/** * @brief Callback for the debug button * @param Event: The event that caused the callback * @param ButtonId: The button ID that the event happened on * @retval None */ void guiUart2DebugButtonCallback(GUITouchEvent Event, uint32_t ButtonId) { static bool enabled = false; if (Event == GUITouchEvent_Up) { UARTSettings* settings = uart2GetSettings(); SemaphoreHandle_t* settingsSemaphore = uart2GetSettingsSemaphore(); /* Try to take the settings semaphore */ if (*settingsSemaphore != 0 && xSemaphoreTake(*settingsSemaphore, 100) == pdTRUE) { if (enabled) { settings->mode = UARTMode_TX_RX; enabled = false; GUIButton_SetTextForRow(GUIButtonId_Uart2Debug, "Disabled", 1); } else { settings->mode = UARTMode_DebugTX; enabled = true; GUIButton_SetTextForRow(GUIButtonId_Uart2Debug, "Enabled", 1); } /* Give back the semaphore now that we are done */ xSemaphoreGive(*settingsSemaphore); } } }
/** * @brief Callback for the format button * @param Event: The event that caused the callback * @param ButtonId: The button ID that the event happened on * @retval None */ void guiUart2FormatButtonCallback(GUITouchEvent Event, uint32_t ButtonId) { if (Event == GUITouchEvent_Up) { UARTSettings* settings = uart2GetSettings(); SemaphoreHandle_t* settingsSemaphore = uart2GetSettingsSemaphore(); /* Try to take the settings semaphore */ if (*settingsSemaphore != 0 && xSemaphoreTake(*settingsSemaphore, 100) == pdTRUE) { if (settings->textFormat == GUITextFormat_ASCII) { settings->textFormat = GUITextFormat_HexWithSpaces; GUIButton_SetTextForRow(GUIButtonId_Uart2Format, "Hex", 1); } else if (settings->textFormat == GUITextFormat_HexWithSpaces) { settings->textFormat = GUITextFormat_ASCII; GUIButton_SetTextForRow(GUIButtonId_Uart2Format, "ASCII", 1); } /* Give back the semaphore now that we are done */ xSemaphoreGive(*settingsSemaphore); /* Update the text format for the text box */ GUITextBox_ChangeTextFormat(GUITextBoxId_Uart2Main, settings->textFormat, GUITextFormatChangeStyle_LockEnd); /* Refresh the main text box */ guiUart2ManageMainTextBox(true); } } }
/** * @brief * @param Event: The event that caused the callback * @param ButtonId: The button ID that the event happened on * @retval None */ void guiUart2ParitySelectionCallback(GUITouchEvent Event, uint32_t ButtonId) { if (Event == GUITouchEvent_Up) { UARTParity newParity; switch (ButtonId) { case GUIButtonId_Uart2ParityNone: GUIButton_SetTextForRow(GUIButtonId_Uart2Parity, "None", 1); newParity = UARTParity_None; break; case GUIButtonId_Uart2ParityOdd: GUIButton_SetTextForRow(GUIButtonId_Uart2Parity, "Odd", 1); newParity = UARTParity_Odd; break; case GUIButtonId_Uart2ParityEven: GUIButton_SetTextForRow(GUIButtonId_Uart2Parity, "Even", 1); newParity = UARTParity_Even; break; default: newParity = 0xFFFF; break; } UARTSettings* settings = uart2GetSettings(); SemaphoreHandle_t* settingsSemaphore = uart2GetSettingsSemaphore(); /* Try to take the settings semaphore */ if (newParity != 0xFFFF && *settingsSemaphore != 0 && xSemaphoreTake(*settingsSemaphore, 100) == pdTRUE) { settings->parity = newParity; uart2UpdateWithNewSettings(); /* Restart the channel if it was on */ if (settings->connection == UARTConnection_Connected) uart2Restart(); /* Give back the semaphore now that we are done */ xSemaphoreGive(*settingsSemaphore); } /* Hide the pop out */ GUIContainer_Hide(GUIContainerId_PopoutUart2Parity); GUI_SetActiveLayer(GUILayer_0); GUIButton_SetLayer(GUIButtonId_Uart2Parity, GUILayer_0); GUIButton_SetState(GUIButtonId_Uart2Parity, GUIButtonState_Disabled); /* Refresh the main text box */ guiUart2ManageMainTextBox(true); } }
/** * @brief Update the GUI elements for this channel that are dependent on the value of the settings * @param None * @retval None */ void guiUart2UpdateGuiElementsReadFromSettings() { /* Get the current settings */ UARTSettings* settings = uart2GetSettings(); /* Update the baud rate text to match what is actually set */ switch (settings->baudRate) { case UARTBaudRate_4800: GUIButton_SetTextForRow(GUIButtonId_Uart2BaudRate, "4800 bps", 1); break; case UARTBaudRate_7200: GUIButton_SetTextForRow(GUIButtonId_Uart2BaudRate, "7200 bps", 1); break; case UARTBaudRate_9600: GUIButton_SetTextForRow(GUIButtonId_Uart2BaudRate, "9600 bps", 1); break; case UARTBaudRate_19200: GUIButton_SetTextForRow(GUIButtonId_Uart2BaudRate, "19200 bps", 1); break; case UARTBaudRate_28800: GUIButton_SetTextForRow(GUIButtonId_Uart2BaudRate, "28800 bps", 1); break; case UARTBaudRate_38400: GUIButton_SetTextForRow(GUIButtonId_Uart2BaudRate, "38400 bps", 1); break; case UARTBaudRate_57600: GUIButton_SetTextForRow(GUIButtonId_Uart2BaudRate, "57600 bps", 1); break; case UARTBaudRate_115200: GUIButton_SetTextForRow(GUIButtonId_Uart2BaudRate, "115200 bps", 1); break; default: break; } /* Update the write format text to match what is actually set */ switch (settings->textFormat) { case GUITextFormat_ASCII: GUIButton_SetTextForRow(GUIButtonId_Uart2Format, "ASCII", 1); break; case GUITextFormat_HexWithSpaces: GUIButton_SetTextForRow(GUIButtonId_Uart2Format, "Hex", 1); break; default: break; } }
/** * @brief Manages how data is displayed in the main text box when the source is UART2 * @param None * @retval None */ void guiUart2ManageMainTextBox(bool ShouldRefresh) { const uint32_t constStartFlashAddress = FLASH_ADR_UART2_DATA; /* Get the current write address, this is the address where the last data is */ uint32_t currentWriteAddress = uart2GetCurrentWriteAddress(); /* Get the current settings of the channel */ UARTSettings* settings = uart2GetSettings(); SemaphoreHandle_t* settingsSemaphore = uart2GetSettingsSemaphore(); lcdManageGenericUartMainTextBox(constStartFlashAddress, currentWriteAddress, settings, settingsSemaphore, GUITextBoxId_Uart2Main, ShouldRefresh); /* Info textbox */ static uint32_t lastAmountOfDataSaved = 1; static uint32_t lastFirstDataItem = 0; static uint32_t lastLastDataItem = 0; uint32_t firstDataItem = GUITextBox_GetNumberForFirstDisplayedData(GUITextBoxId_Uart2Main); uint32_t lastDataItem = GUITextBox_GetNumberForLastDisplayedData(GUITextBoxId_Uart2Main); if (ShouldRefresh || lastAmountOfDataSaved != settings->amountOfDataSaved || lastFirstDataItem != firstDataItem || lastLastDataItem != lastDataItem) { lastAmountOfDataSaved = settings->amountOfDataSaved; GUITextBox_ClearAndResetWritePosition(GUITextBoxId_Uart2Info); GUITextBox_SetYWritePositionToCenter(GUITextBoxId_Uart2Info); GUITextBox_SetXWritePosition(GUITextBoxId_Uart2Info, 5); GUITextBox_WriteString(GUITextBoxId_Uart2Info, "Data Count: "); GUITextBox_WriteNumber(GUITextBoxId_Uart2Info, (int32_t)lastAmountOfDataSaved); GUITextBox_WriteString(GUITextBoxId_Uart2Info, " bytes, "); GUITextBox_WriteString(GUITextBoxId_Uart2Info, "Displayed data: "); if (lastAmountOfDataSaved != 0) { uint32_t firstDataItem = GUITextBox_GetNumberForFirstDisplayedData(GUITextBoxId_Uart2Main); uint32_t lastDataItem = GUITextBox_GetNumberForLastDisplayedData(GUITextBoxId_Uart2Main); GUITextBox_WriteNumber(GUITextBoxId_Uart2Info, (int32_t)firstDataItem); GUITextBox_WriteString(GUITextBoxId_Uart2Info, " to "); GUITextBox_WriteNumber(GUITextBoxId_Uart2Info, (int32_t)lastDataItem); } else GUITextBox_WriteString(GUITextBoxId_Uart2Info, "None"); /* Update the variables */ lastFirstDataItem = firstDataItem; lastLastDataItem = lastDataItem; } }
/** * @brief Callback for the save settings button, will save the settings of the channels to SPI FLASH * @param Event: The event that caused the callback * @param ButtonId: The button ID that the event happened on * @retval None */ void guiSaveSettingsButtonCallback(GUITouchEvent Event, uint32_t ButtonId) { if (Event == GUITouchEvent_Up) { volatile uint32_t currentFlashAddress = FLASH_ADR_CHANNEL_SETTINGS; /* Start by erasing all the old settings */ SPI_FLASH_EraseSector(currentFlashAddress); /* CAN */ SPI_FLASH_WriteBuffer((uint8_t*)can1GetSettings(), currentFlashAddress, sizeof(CANSettings)); currentFlashAddress += sizeof(CANSettings); SPI_FLASH_WriteBuffer((uint8_t*)can2GetSettings(), currentFlashAddress, sizeof(CANSettings)); currentFlashAddress += sizeof(CANSettings); /* UART */ SPI_FLASH_WriteBuffer((uint8_t*)uart1GetSettings(), currentFlashAddress, sizeof(UARTSettings)); currentFlashAddress += sizeof(UARTSettings); SPI_FLASH_WriteBuffer((uint8_t*)uart2GetSettings(), currentFlashAddress, sizeof(UARTSettings)); currentFlashAddress += sizeof(UARTSettings); SPI_FLASH_WriteBuffer((uint8_t*)rs232GetSettings(), currentFlashAddress, sizeof(UARTSettings)); currentFlashAddress += sizeof(UARTSettings); } }
/** * @brief * @param Event: The event that caused the callback * @param ButtonId: The button ID that the event happened on * @retval None */ void guiUart2BaudRateSelectionCallback(GUITouchEvent Event, uint32_t ButtonId) { if (Event == GUITouchEvent_Up) { UARTBaudRate newBaudRate; switch (ButtonId) { case GUIButtonId_Uart2BaudRate4800: GUIButton_SetTextForRow(GUIButtonId_Uart2BaudRate, "4800 bps", 1); newBaudRate = UARTBaudRate_4800; break; case GUIButtonId_Uart2BaudRate7200: GUIButton_SetTextForRow(GUIButtonId_Uart2BaudRate, "7200 bps", 1); newBaudRate = UARTBaudRate_7200; break; case GUIButtonId_Uart2BaudRate9600: GUIButton_SetTextForRow(GUIButtonId_Uart2BaudRate, "9600 bps", 1); newBaudRate = UARTBaudRate_9600; break; case GUIButtonId_Uart2BaudRate19k2: GUIButton_SetTextForRow(GUIButtonId_Uart2BaudRate, "19200 bps", 1); newBaudRate = UARTBaudRate_19200; break; case GUIButtonId_Uart2BaudRate28k8: GUIButton_SetTextForRow(GUIButtonId_Uart2BaudRate, "28800 bps", 1); newBaudRate = UARTBaudRate_28800; break; case GUIButtonId_Uart2BaudRate38k4: GUIButton_SetTextForRow(GUIButtonId_Uart2BaudRate, "38400 bps", 1); newBaudRate = UARTBaudRate_38400; break; case GUIButtonId_Uart2BaudRate57k6: GUIButton_SetTextForRow(GUIButtonId_Uart2BaudRate, "57600 bps", 1); newBaudRate = UARTBaudRate_57600; break; case GUIButtonId_Uart2BaudRate115k: GUIButton_SetTextForRow(GUIButtonId_Uart2BaudRate, "115200 bps", 1); newBaudRate = UARTBaudRate_115200; break; default: newBaudRate = 0; break; } UARTSettings* settings = uart2GetSettings(); SemaphoreHandle_t* settingsSemaphore = uart2GetSettingsSemaphore(); /* Try to take the settings semaphore */ if (newBaudRate != 0 && *settingsSemaphore != 0 && xSemaphoreTake(*settingsSemaphore, 100) == pdTRUE) { settings->baudRate = newBaudRate; uart2UpdateWithNewSettings(); /* Restart the channel if it was on */ if (settings->connection == UARTConnection_Connected) uart2Restart(); /* Give back the semaphore now that we are done */ xSemaphoreGive(*settingsSemaphore); } /* Hide the pop out */ GUIContainer_Hide(GUIContainerId_PopoutUart2BaudRate); GUI_SetActiveLayer(GUILayer_0); GUIButton_SetLayer(GUIButtonId_Uart2BaudRate, GUILayer_0); GUIButton_SetState(GUIButtonId_Uart2BaudRate, GUIButtonState_Disabled); /* Refresh the main text box */ guiUart2ManageMainTextBox(true); } }