Graph Data Control with Checkbox Widget

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Graph Data Control with Checkbox Widget

      Hello
      I have a graph field and a graph data.
      I want attach it to graph with a checkbox if it is true [GRAPH_AttachData(hItem,_hDataYT0);]
      and if it is no true detach it [GRAPH_DetachData(hItem,_hDataYT0);]
      and do it with a button.

      But I could not control it with check box and button.. It is complicated a bit.
      Here is my code block. I made it with emWin GUIBuilder.

      In this project ADC is activated and my board is stm32f746g_disco

      C Source Code: WindowDLG.c

      1. /*********************************************************************
      2. * *
      3. * SEGGER Microcontroller GmbH & Co. KG *
      4. * Solutions for real time microcontroller applications *
      5. * *
      6. **********************************************************************
      7. * *
      8. * C-file generated by: *
      9. * *
      10. * GUI_Builder for emWin version 5.40 *
      11. * Compiled Jun 22 2017, 10:13:26 *
      12. * (c) 2017 Segger Microcontroller GmbH & Co. KG *
      13. * *
      14. **********************************************************************
      15. * *
      16. * Internet: www.segger.com Support: support@segger.com *
      17. * *
      18. **********************************************************************
      19. */
      20. // USER START (Optionally insert additional includes)
      21. #include "GUI_App.h"
      22. #include "GUI.h"
      23. #include "DIALOG.h"
      24. #include "stm32746g_discovery.h"
      25. #include "stm32746g_discovery_ts.h"
      26. #include "stm32f7xx_hal.h"
      27. #include "DIALOG.h"
      28. #include "stdlib.h"
      29. /*********************************************************************
      30. *
      31. * Defines
      32. *
      33. **********************************************************************
      34. */
      35. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      36. #define ID_GRAPH_0 (GUI_ID_USER + 0x01)
      37. #define ID_SLIDER_0 (GUI_ID_USER + 0x02)
      38. ADC_HandleTypeDef hadc1;
      39. static void MX_ADC1_Init(void);
      40. static void MX_GPIO_Init(void);
      41. int frameXSize=480;
      42. int frameYSize=205;
      43. uint16_t c;
      44. uint16_t sliderV=10;
      45. GUI_RECT Rect = {0, 0, 30, 205};
      46. char acText[] = "Temperature";
      47. /*********************************************************************
      48. *
      49. * Static data
      50. *
      51. **********************************************************************
      52. */
      53. /*********************************************************************
      54. *
      55. * _aDialogCreate
      56. */
      57. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      58. { WINDOW_CreateIndirect, "Window",ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0, 0 },
      59. { GRAPH_CreateIndirect, "Graph",ID_GRAPH_0, 25, 86, 200, 100, 0, 0x0, 0 },
      60. };
      61. static GRAPH_DATA_Handle _hDataYT0;
      62. static SLIDER_Handle hSli;
      63. /*********************************************************************
      64. *
      65. * Static code
      66. *
      67. **********************************************************************
      68. */
      69. /*********************************************************************
      70. *
      71. * _cbDialog
      72. */
      73. static void _cbDialog(WM_MESSAGE * pMsg) {
      74. WM_HWIN hItem;
      75. switch (pMsg->MsgId) {
      76. case WM_INIT_DIALOG:
      77. //
      78. // Initialization of 'Window'
      79. //
      80. hItem = pMsg->hWin;
      81. hSli=SLIDER_CreateEx(25,200,200,25,hItem,WM_CF_SHOW,0,0);
      82. WINDOW_SetBkColor(hItem, GUI_DARKGREEN);
      83. hItem = WM_GetDialogItem(pMsg->hWin, ID_GRAPH_0);
      84. _hDataYT0 = GRAPH_DATA_YT_Create(GUI_RED, 200, NULL, 0);
      85. GRAPH_SetGridVis(hItem, 1);
      86. SLIDER_SetNumTicks(hSli,50);
      87. SLIDER_SetRange(hSli,0,90);
      88. SLIDER_SetFocusColor(hSli,GUI_DARKGREEN);
      89. GRAPH_AttachData(hItem,_hDataYT0);
      90. while(1)
      91. {
      92. sliderV=SLIDER_GetValue(hSli);
      93. HAL_ADC_Start(&hadc1);
      94. c=HAL_ADC_GetValue(&hadc1);
      95. GRAPH_DATA_YT_AddValue(_hDataYT0,c*0.025);
      96. GUI_Delay(sliderV+10);
      97. }
      98. break;
      99. default:
      100. WM_DefaultProc(pMsg);
      101. break;
      102. }
      103. }
      104. /*********************************************************************
      105. *
      106. * Public code
      107. *
      108. **********************************************************************
      109. */
      110. /*********************************************************************
      111. *
      112. * CreateWindow
      113. */
      114. WM_HWIN CreateWindow(void);
      115. WM_HWIN CreateWindow(void) {
      116. WM_HWIN hWin;
      117. hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
      118. return hWin;
      119. }
      120. // USER START (Optionally insert additional public code)
      121. // USER END
      122. /*************************** End of file ****************************/
      123. static void MX_ADC1_Init(void)
      124. {
      125. ADC_ChannelConfTypeDef sConfig;
      126. hadc1.Instance = ADC1;
      127. hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
      128. hadc1.Init.Resolution = ADC_RESOLUTION_12B;
      129. hadc1.Init.ScanConvMode = DISABLE;
      130. hadc1.Init.ContinuousConvMode = ENABLE;
      131. hadc1.Init.DiscontinuousConvMode = DISABLE;
      132. hadc1.Init.NbrOfDiscConversion = 1;
      133. hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
      134. hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
      135. hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
      136. hadc1.Init.NbrOfConversion = 1;
      137. hadc1.Init.DMAContinuousRequests = DISABLE;
      138. hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
      139. if (HAL_ADC_Init(&hadc1) != HAL_OK)
      140. {
      141. _Error_Handler(__FILE__, __LINE__);
      142. }
      143. sConfig.Channel = ADC_CHANNEL_0;
      144. sConfig.Rank = ADC_REGULAR_RANK_1;
      145. sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
      146. if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
      147. {
      148. _Error_Handler(__FILE__, __LINE__);
      149. }
      150. }
      151. static void MX_GPIO_Init(void)
      152. {
      153. GPIO_InitTypeDef GPIO_InitStruct;
      154. // GPIO Ports Clock Enable
      155. __HAL_RCC_GPIOE_CLK_ENABLE();
      156. __HAL_RCC_GPIOB_CLK_ENABLE();
      157. __HAL_RCC_GPIOA_CLK_ENABLE();
      158. __HAL_RCC_GPIOG_CLK_ENABLE();
      159. __HAL_RCC_GPIOJ_CLK_ENABLE();
      160. __HAL_RCC_GPIOD_CLK_ENABLE();
      161. __HAL_RCC_GPIOK_CLK_ENABLE();
      162. __HAL_RCC_GPIOF_CLK_ENABLE();
      163. __HAL_RCC_GPIOI_CLK_ENABLE();
      164. __HAL_RCC_GPIOH_CLK_ENABLE();
      165. __HAL_RCC_GPIOC_CLK_ENABLE();
      166. //Configure GPIO pin Output Level
      167. HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_Port, LCD_BL_CTRL_Pin, GPIO_PIN_SET);
      168. //Configure GPIO pin Output Level
      169. HAL_GPIO_WritePin(LCD_DISP_GPIO_Port, LCD_DISP_Pin, GPIO_PIN_SET);
      170. //Configure GPIO pin : LCD_BL_CTRL_Pin
      171. GPIO_InitStruct.Pin = LCD_BL_CTRL_Pin;
      172. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
      173. GPIO_InitStruct.Pull = GPIO_NOPULL;
      174. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
      175. HAL_GPIO_Init(LCD_BL_CTRL_GPIO_Port, &GPIO_InitStruct);
      176. //Configure GPIO pin : LCD_DISP_Pin
      177. GPIO_InitStruct.Pin = LCD_DISP_Pin;
      178. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
      179. GPIO_InitStruct.Pull = GPIO_NOPULL;
      180. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
      181. HAL_GPIO_Init(LCD_DISP_GPIO_Port, &GPIO_InitStruct);
      182. //Configure GPIO pin : LCD_INT_Pin
      183. GPIO_InitStruct.Pin = LCD_INT_Pin;
      184. GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
      185. GPIO_InitStruct.Pull = GPIO_NOPULL;
      186. HAL_GPIO_Init(LCD_INT_GPIO_Port, &GPIO_InitStruct);
      187. }
      Display All
    • Hi,

      You can't simply create an endless loop right within the creation process of the dialog. It might be possible that you will get some output on the LCD, because you call GUI_Delay(), but this might result in unexpected behavior.

      You better have one endless loop (not within a callback of a window/dialog/widget) and call there GUI_Delay()/GUI_Exec().

      Please try the example below. Instead of adding random values to the graph data use the ADC values.

      C Source Code

      1. #include "DIALOG.h"
      2. #include <stdlib.h>
      3. /*********************************************************************
      4. *
      5. * Externals
      6. *
      7. **********************************************************************
      8. */
      9. /*********************************************************************
      10. *
      11. * Defines
      12. *
      13. **********************************************************************
      14. */
      15. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      16. #define ID_GRAPH_0 (GUI_ID_USER + 0x01)
      17. #define ID_BUTTON_0 (GUI_ID_USER + 0x02)
      18. #define ID_CHECKBOX_0 (GUI_ID_USER + 0x03)
      19. /*********************************************************************
      20. *
      21. * Static data
      22. *
      23. **********************************************************************
      24. */
      25. /*********************************************************************
      26. *
      27. * _aDialogCreate
      28. */
      29. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      30. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0, 0 },
      31. { GRAPH_CreateIndirect, "Graph", ID_GRAPH_0, 10, 10, 460, 200, 0, 0x0, 0 },
      32. { BUTTON_CreateIndirect, "Detach", ID_BUTTON_0, 250, 230, 80, 20, 0, 0x0, 0 },
      33. { CHECKBOX_CreateIndirect, "Checkbox", ID_CHECKBOX_0, 150, 230, 80, 20, 0, 0x0, 0 },
      34. };
      35. static GRAPH_DATA_Handle _hDataYT0;
      36. /*********************************************************************
      37. *
      38. * Static code
      39. *
      40. **********************************************************************
      41. */
      42. /*********************************************************************
      43. *
      44. * _cbDialog
      45. */
      46. static void _cbDialog(WM_MESSAGE * pMsg) {
      47. WM_HWIN hItem;
      48. int NCode;
      49. int Id;
      50. switch (pMsg->MsgId) {
      51. case WM_INIT_DIALOG:
      52. WINDOW_SetBkColor(pMsg->hWin, GUI_DARKGREEN);
      53. //
      54. // Initialization of 'Checkbox'
      55. //
      56. hItem = WM_GetDialogItem(pMsg->hWin, ID_CHECKBOX_0);
      57. CHECKBOX_SetText(hItem, "Attach");
      58. _hDataYT0 = GRAPH_DATA_YT_Create(GUI_RED, 200, NULL, 0);
      59. hItem = WM_GetDialogItem(pMsg->hWin, ID_GRAPH_0);
      60. GRAPH_SetGridVis(hItem, 1);
      61. break;
      62. case WM_NOTIFY_PARENT:
      63. Id = WM_GetId(pMsg->hWinSrc);
      64. NCode = pMsg->Data.v;
      65. switch(Id) {
      66. case ID_BUTTON_0: // Notifications sent by 'Detach'
      67. switch(NCode) {
      68. case WM_NOTIFICATION_CLICKED:
      69. break;
      70. case WM_NOTIFICATION_RELEASED:
      71. hItem = WM_GetDialogItem(pMsg->hWin, ID_GRAPH_0);
      72. GRAPH_DetachData(hItem, _hDataYT0);
      73. hItem = WM_GetDialogItem(pMsg->hWin, ID_CHECKBOX_0);
      74. CHECKBOX_SetState(hItem, 0);
      75. break;
      76. }
      77. break;
      78. case ID_CHECKBOX_0: // Notifications sent by 'Checkbox'
      79. switch(NCode) {
      80. case WM_NOTIFICATION_CLICKED:
      81. break;
      82. case WM_NOTIFICATION_RELEASED:
      83. break;
      84. case WM_NOTIFICATION_VALUE_CHANGED:
      85. hItem = WM_GetDialogItem(pMsg->hWin, ID_CHECKBOX_0);
      86. if (CHECKBOX_GetState(hItem)) {
      87. hItem = WM_GetDialogItem(pMsg->hWin, ID_GRAPH_0);
      88. GRAPH_AttachData(hItem, _hDataYT0);
      89. } else {
      90. hItem = WM_GetDialogItem(pMsg->hWin, ID_GRAPH_0);
      91. GRAPH_DetachData(hItem, _hDataYT0);
      92. }
      93. break;
      94. }
      95. break;
      96. }
      97. break;
      98. default:
      99. WM_DefaultProc(pMsg);
      100. break;
      101. }
      102. }
      103. /*********************************************************************
      104. *
      105. * Public code
      106. *
      107. **********************************************************************
      108. */
      109. /*********************************************************************
      110. *
      111. * MainTask
      112. */
      113. void MainTask(void) {
      114. GUI_Init();
      115. WM_MULTIBUF_Enable(1);
      116. GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
      117. while (1) {
      118. GUI_Delay(100);
      119. GRAPH_DATA_YT_AddValue(_hDataYT0, (rand() % 50) + 50);
      120. }
      121. }
      122. /*************************** End of file ****************************/
      Display All

      Regards,
      Sven
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.