/** * @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 guiUart1FormatButtonCallback(GUITouchEvent Event, uint32_t ButtonId) { if (Event == GUITouchEvent_Up) { UARTSettings* settings = uart1GetSettings(); SemaphoreHandle_t* settingsSemaphore = uart1GetSettingsSemaphore(); /* 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_Uart1Format, "Hex", 1); } else if (settings->textFormat == GUITextFormat_HexWithSpaces) { settings->textFormat = GUITextFormat_ASCII; GUIButton_SetTextForRow(GUIButtonId_Uart1Format, "ASCII", 1); } /* Give back the semaphore now that we are done */ xSemaphoreGive(*settingsSemaphore); /* Update the text format for the text box */ GUITextBox_ChangeTextFormat(GUITextBoxId_Uart1Main, settings->textFormat, GUITextFormatChangeStyle_LockEnd); /* Refresh the main text box */ guiUart1ManageMainTextBox(true); } } }
/** * @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 guiUart1DebugButtonCallback(GUITouchEvent Event, uint32_t ButtonId) { static bool enabled = false; if (Event == GUITouchEvent_Up) { UARTSettings* settings = uart1GetSettings(); SemaphoreHandle_t* settingsSemaphore = uart1GetSettingsSemaphore(); /* 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_Uart1Debug, "Disabled", 1); } else { settings->mode = UARTMode_DebugTX; enabled = true; GUIButton_SetTextForRow(GUIButtonId_Uart1Debug, "Enabled", 1); } /* Give back the semaphore now that we are done */ xSemaphoreGive(*settingsSemaphore); } } }
/** * @brief Callback for the voltage level button * @param Event: The event that caused the callback * @param ButtonId: The button ID that the event happened on * @retval None */ void guiUart1VoltageLevelButtonCallback(GUITouchEvent Event, uint32_t ButtonId) { static bool level5VisActive = false; if (Event == GUITouchEvent_Up) { if (level5VisActive) { ErrorStatus status = uart1SetPower(UARTPower_3V3); if (status == SUCCESS) { level5VisActive = false; GUIButton_SetTextForRow(GUIButtonId_Uart1VoltageLevel, "3.3 V", 1); } } else { ErrorStatus status = uart1SetPower(UARTPower_5V); if (status == SUCCESS) { level5VisActive = true; GUIButton_SetTextForRow(GUIButtonId_Uart1VoltageLevel, "5 V ", 1); } } } }
/** * @brief Callback for the termination button * @param Event: The event that caused the callback * @param ButtonId: The button ID that the event happened on * @retval None */ void guiCan1TerminationButtonCallback(GUITouchEvent Event, uint32_t ButtonId) { static bool terminated = false; if (Event == GUITouchEvent_Up) { if (terminated) { ErrorStatus status = can1SetTermination(CANTermination_Disconnected); if (status == SUCCESS) { terminated = false; GUIButton_SetTextForRow(GUIButtonId_Can1Termination, "None", 1); } } else { ErrorStatus status = can1SetTermination(CANTermination_Connected); if (status == SUCCESS) { terminated = true; GUIButton_SetTextForRow(GUIButtonId_Can1Termination, "120 R", 1); } } } }
/** * @brief Callback for the enable button * @param Event: The event that caused the callback * @param ButtonId: The button ID that the event happened on * @retval None */ void guiCan1EnableButtonCallback(GUITouchEvent Event, uint32_t ButtonId) { static bool enabled = false; if (Event == GUITouchEvent_Up) { if (enabled) { ErrorStatus status = can1SetConnection(CANConnection_Disconnected); if (status == SUCCESS) { enabled = false; GUIButton_SetTextForRow(GUIButtonId_Can1Enable, "Disabled", 1); GUIButton_SetState(GUIButtonId_Can1Top, GUIButtonState_Disabled); GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "< Bit Rate:", 0); GUIButton_SetState(GUIButtonId_Can1BitRate, GUIButtonState_Disabled); } } else { ErrorStatus status = can1SetConnection(CANConnection_Connected); if (status == SUCCESS) { enabled = true; GUIButton_SetTextForRow(GUIButtonId_Can1Enable, "Enabled", 1); GUIButton_SetState(GUIButtonId_Can1Top, GUIButtonState_Enabled); GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "Bit Rate:", 0); GUIButton_SetState(GUIButtonId_Can1BitRate, GUIButtonState_DisabledTouch); } } } }
/** * @brief * @param Event: The event that caused the callback * @param ButtonId: The button ID that the event happened on * @retval None */ void guiUart1ParitySelectionCallback(GUITouchEvent Event, uint32_t ButtonId) { if (Event == GUITouchEvent_Up) { UARTParity newParity; switch (ButtonId) { case GUIButtonId_Uart1ParityNone: GUIButton_SetTextForRow(GUIButtonId_Uart1Parity, "None", 1); newParity = UARTParity_None; break; case GUIButtonId_Uart1ParityOdd: GUIButton_SetTextForRow(GUIButtonId_Uart1Parity, "Odd", 1); newParity = UARTParity_Odd; break; case GUIButtonId_Uart1ParityEven: GUIButton_SetTextForRow(GUIButtonId_Uart1Parity, "Even", 1); newParity = UARTParity_Even; break; default: newParity = 0xFFFF; break; } UARTSettings* settings = uart1GetSettings(); SemaphoreHandle_t* settingsSemaphore = uart1GetSettingsSemaphore(); /* Try to take the settings semaphore */ if (newParity != 0xFFFF && *settingsSemaphore != 0 && xSemaphoreTake(*settingsSemaphore, 100) == pdTRUE) { settings->parity = newParity; uart1UpdateWithNewSettings(); /* Restart the channel if it was on */ if (settings->connection == UARTConnection_Connected) uart1Restart(); /* Give back the semaphore now that we are done */ xSemaphoreGive(*settingsSemaphore); } /* Hide the pop out */ GUIContainer_Hide(GUIContainerId_PopoutUart1Parity); GUI_SetActiveLayer(GUILayer_0); GUIButton_SetLayer(GUIButtonId_Uart1Parity, GUILayer_0); GUIButton_SetState(GUIButtonId_Uart1Parity, GUIButtonState_Disabled); /* Refresh the main text box */ guiUart1ManageMainTextBox(true); } }
/** * @brief Update the GUI elements for this channel that are dependent on the value of the settings * @param None * @retval None */ void guiCan1UpdateGuiElementsReadFromSettings() { /* Get the current settings */ CANSettings* settings = can1GetSettings(); /* Update the bit rate text to match what is actually set */ switch (settings->bitRate) { case CANBitRate_10k: GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "10kbit/s", 1); break; case CANBitRate_20k: GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "20kbit/s", 1); break; case CANBitRate_50k: GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "50kbit/s", 1); break; case CANBitRate_100k: GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "100kbit/s", 1); break; case CANBitRate_125k: GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "125kbit/s", 1); break; case CANBitRate_250k: GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "250kbit/s", 1); break; case CANBitRate_500k: GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "500kbit/s", 1); break; case CANBitRate_1M: GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "1Mbit/s", 1); break; default: break; } }
/** * @brief Update the GUI elements for this channel that are dependent on the value of the settings * @param None * @retval None */ void guiUart1UpdateGuiElementsReadFromSettings() { /* Get the current settings */ UARTSettings* settings = uart1GetSettings(); /* Update the baud rate text to match what is actually set */ switch (settings->baudRate) { case UARTBaudRate_4800: GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "4800 bps", 1); break; case UARTBaudRate_7200: GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "7200 bps", 1); break; case UARTBaudRate_9600: GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "9600 bps", 1); break; case UARTBaudRate_19200: GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "19200 bps", 1); break; case UARTBaudRate_28800: GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "28800 bps", 1); break; case UARTBaudRate_38400: GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "38400 bps", 1); break; case UARTBaudRate_57600: GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "57600 bps", 1); break; case UARTBaudRate_115200: GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "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_Uart1Format, "ASCII", 1); break; case GUITextFormat_HexWithSpaces: GUIButton_SetTextForRow(GUIButtonId_Uart1Format, "Hex", 1); break; default: break; } }
/** * @brief Callback for the enable button * @param Event: The event that caused the callback * @param ButtonId: The button ID that the event happened on * @retval None */ void guiUart1EnableButtonCallback(GUITouchEvent Event, uint32_t ButtonId) { static bool enabled = false; if (Event == GUITouchEvent_Up) { if (enabled) { ErrorStatus status = uart1SetConnection(UARTConnection_Disconnected); if (status == SUCCESS) { enabled = false; GUIButton_SetTextForRow(GUIButtonId_Uart1Enable, "Disabled", 1); GUIButton_SetState(GUIButtonId_Uart1Top, GUIButtonState_Disabled); GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "< Baud Rate:", 0); GUIButton_SetState(GUIButtonId_Uart1BaudRate, GUIButtonState_Disabled); GUIButton_SetTextForRow(GUIButtonId_Uart1Parity, "< Parity:", 0); GUIButton_SetState(GUIButtonId_Uart1Parity, GUIButtonState_Disabled); } } else { ErrorStatus status = uart1SetConnection(UARTConnection_Connected); if (status == SUCCESS) { enabled = true; GUIButton_SetTextForRow(GUIButtonId_Uart1Enable, "Enabled", 1); GUIButton_SetState(GUIButtonId_Uart1Top, GUIButtonState_Enabled); GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "Baud Rate:", 0); GUIButton_SetState(GUIButtonId_Uart1BaudRate, GUIButtonState_DisabledTouch); GUIButton_SetTextForRow(GUIButtonId_Uart1Parity, "Parity:", 0); GUIButton_SetState(GUIButtonId_Uart1Parity, GUIButtonState_DisabledTouch); } } } }
/** * @brief * @param Event: The event that caused the callback * @param ButtonId: The button ID that the event happened on * @retval None */ void guiUart1BaudRateSelectionCallback(GUITouchEvent Event, uint32_t ButtonId) { if (Event == GUITouchEvent_Up) { UARTBaudRate newBaudRate; switch (ButtonId) { case GUIButtonId_Uart1BaudRate4800: GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "4800 bps", 1); newBaudRate = UARTBaudRate_4800; break; case GUIButtonId_Uart1BaudRate7200: GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "7200 bps", 1); newBaudRate = UARTBaudRate_7200; break; case GUIButtonId_Uart1BaudRate9600: GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "9600 bps", 1); newBaudRate = UARTBaudRate_9600; break; case GUIButtonId_Uart1BaudRate19k2: GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "19200 bps", 1); newBaudRate = UARTBaudRate_19200; break; case GUIButtonId_Uart1BaudRate28k8: GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "28800 bps", 1); newBaudRate = UARTBaudRate_28800; break; case GUIButtonId_Uart1BaudRate38k4: GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "38400 bps", 1); newBaudRate = UARTBaudRate_38400; break; case GUIButtonId_Uart1BaudRate57k6: GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "57600 bps", 1); newBaudRate = UARTBaudRate_57600; break; case GUIButtonId_Uart1BaudRate115k: GUIButton_SetTextForRow(GUIButtonId_Uart1BaudRate, "115200 bps", 1); newBaudRate = UARTBaudRate_115200; break; default: newBaudRate = 0; break; } UARTSettings* settings = uart1GetSettings(); SemaphoreHandle_t* settingsSemaphore = uart1GetSettingsSemaphore(); /* Try to take the settings semaphore */ if (newBaudRate != 0 && *settingsSemaphore != 0 && xSemaphoreTake(*settingsSemaphore, 100) == pdTRUE) { settings->baudRate = newBaudRate; uart1UpdateWithNewSettings(); /* Restart the channel if it was on */ if (settings->connection == UARTConnection_Connected) uart1Restart(); /* Give back the semaphore now that we are done */ xSemaphoreGive(*settingsSemaphore); } /* Hide the pop out */ GUIContainer_Hide(GUIContainerId_PopoutUart1BaudRate); GUI_SetActiveLayer(GUILayer_0); GUIButton_SetLayer(GUIButtonId_Uart1BaudRate, GUILayer_0); GUIButton_SetState(GUIButtonId_Uart1BaudRate, GUIButtonState_Disabled); /* Refresh the main text box */ guiUart1ManageMainTextBox(true); } }
/** * @brief * @param Event: The event that caused the callback * @param ButtonId: The button ID that the event happened on * @retval None */ void guiCan1BitRateSelectionCallback(GUITouchEvent Event, uint32_t ButtonId) { if (Event == GUITouchEvent_Up) { CANBitRate newBitRate; switch (ButtonId) { case GUIButtonId_Can1BitRate10k: GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "10kbit/s", 1); newBitRate = CANBitRate_10k; break; case GUIButtonId_Can1BitRate20k: GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "20kbit/s", 1); newBitRate = CANBitRate_20k; break; case GUIButtonId_Can1BitRate50k: GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "50kbit/s", 1); newBitRate = CANBitRate_50k; break; case GUIButtonId_Can1BitRate100k: GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "100kbit/s", 1); newBitRate = CANBitRate_100k; break; case GUIButtonId_Can1BitRate125k: GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "125kbit/s", 1); newBitRate = CANBitRate_125k; break; case GUIButtonId_Can1BitRate250k: GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "250kbit/s", 1); newBitRate = CANBitRate_250k; break; case GUIButtonId_Can1BitRate500k: GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "500kbit/s", 1); newBitRate = CANBitRate_500k; break; case GUIButtonId_Can1BitRate1M: GUIButton_SetTextForRow(GUIButtonId_Can1BitRate, "1Mbit/s", 1); newBitRate = CANBitRate_1M; break; default: newBitRate = 0; break; } CANSettings* settings = can1GetSettings(); SemaphoreHandle_t* settingsSemaphore = can1GetSettingsSemaphore(); /* Try to take the settings semaphore */ if (newBitRate != 0 && *settingsSemaphore != 0 && xSemaphoreTake(*settingsSemaphore, 100) == pdTRUE) { settings->bitRate = newBitRate; can1UpdateWithNewSettings(); /* Restart the channel if it was on */ if (settings->connection == CANConnection_Connected) can1Restart(); /* Give back the semaphore now that we are done */ xSemaphoreGive(*settingsSemaphore); } /* Hide the pop out */ GUIContainer_Hide(GUIContainerId_PopoutCan1BitRate); GUI_SetActiveLayer(GUILayer_0); GUIButton_SetLayer(GUIButtonId_Can1BitRate, GUILayer_0); GUIButton_SetState(GUIButtonId_Can1BitRate, GUIButtonState_Disabled); /* Refresh the main text box */ guiCan1ManageMainTextBox(true); } }