[SOLVED] Possibilities to refresh a graph in background

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

    • [SOLVED] Possibilities to refresh a graph in background

      Hello everybody,

      I have following problem:

      I want to visualize ADC-Values as a Graph.
      Every x ms a new value from the ADC is sampled and visualized.
      The shown data is correct ---> So everything works fine.

      But if I switch to another dialog and come back to the "graph screen" the values are gone. I think the whole dialog is newly created. But how can I manage that?
      Logging data in the background and draw graph if the screen is created? Is there any possibility not to kill that dialog while another dialog is shown? (I tried to create all dialogs/windows once and call them by GUI_ExecCreatedDialog() but that does not work)
      What do you think?

      Image0 ---> after switching back
      Image1 ---> while being on the screen


      Code snippet of the "graph screen":

      C Source Code

      1. static void _cbScreen3(WM_MESSAGE * pMsg)
      2. {
      3. WM_HWIN hItem;
      4. int NCode,Id;
      5. static GRAPH_DATA_Handle hGraph1, hGraph2;
      6. int Value;
      7. static int Angle;
      8. static int Stop;
      9. static WM_HTIMER hTimer1;
      10. GRAPH_SCALE_Handle hScaley;
      11. GRAPH_SCALE_Handle hScalex;
      12. int NumItems;
      13. switch (pMsg->MsgId)
      14. {
      15. case WM_INIT_DIALOG:
      16. hItem = pMsg->hWin;
      17. WINDOW_SetBkColor(hItem, GUI_WHITE);
      18. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_30);
      19. TEXT_SetTextAlign(hItem, TEXT_CF_LEFT);
      20. TEXT_SetTextColor(hItem, GUI_BLUE);
      21. TEXT_SetFont(hItem, GUI_FONT_24B_1);
      22. TEXT_SetText(hItem, "Graph");
      23. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_BACK_MENU_3);
      24. BUTTON_SetText(hItem, "Menu");
      25. BUTTON_SetDefaultSkin(BUTTON_SKIN_FLEX);
      26. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_SCREEN_3);
      27. BUTTON_SetText(hItem, "Screen 2 ");
      28. hItem = WM_GetDialogItem(pMsg->hWin, ID_GRAPH_0);
      29. WM_SetCallback(hItem, _cbGraph);
      30. GRAPH_SetGridVis(hItem, 1); //Gatter sichtbar?
      31. GRAPH_SetColor(hItem, GUI_WHITE,GRAPH_CI_BK);
      32. GRAPH_SetColor(hItem, GUI_GREEN,GRAPH_CI_GRID);
      33. hScaley =GRAPH_SCALE_Create(5,GUI_TA_VCENTER,GRAPH_SCALE_CF_VERTICAL,10);
      34. GRAPH_SCALE_SetPos(hScaley,1);
      35. GRAPH_SCALE_SetTextColor(hScaley,GUI_BLACK);
      36. GRAPH_SCALE_SetFactor(hScaley,0.1);
      37. GRAPH_SCALE_SetTickDist(hScaley,50);
      38. GRAPH_AttachScale(hItem,hScaley);
      39. hScalex = GRAPH_SCALE_Create(5,GUI_TA_HCENTER,GRAPH_SCALE_CF_HORIZONTAL,50); //Scala für die X-Achse
      40. GRAPH_SCALE_SetPos(hScalex,140);
      41. GRAPH_SCALE_SetTextColor(hScalex,GUI_BLACK);
      42. GRAPH_SCALE_SetFactor(hScalex,0.5);
      43. GRAPH_AttachScale(hItem,hScalex);
      44. NumItems = WM_GetWindowSizeX(hItem); //--> Anzahl der Items abhängig von der Größe des Widgets (x-Achse)
      45. // 2 Datenobjekte für Graphen
      46. hGraph1 = GRAPH_DATA_YT_Create(GUI_BLUE, NumItems, NULL, 0);
      47. GRAPH_AttachData(hItem, hGraph1);
      48. // GRAPH_AttachData(hItem, hGraph2);
      49. // alle x ms ein neues Wertepaar je Graph
      50. hTimer1 = WM_CreateTimer( pMsg->hWin, 1, TIMER_VALUE, 0);
      51. break;
      52. case WM_TIMER:
      53. if (Stop == 0)
      54. {
      55. WM_RestartTimer(hTimer1, 0);
      56. }
      57. if(Mode_Timer !=1)
      58. {
      59. }
      60. GRAPH_DATA_YT_AddValue(hGraph1, g_Voltage*10);
      61. break;
      62. case MESSAGE_STARTSTOP:
      63. Stop ^= 1;
      64. if (Stop == 0)
      65. {
      66. WM_RestartTimer(hTimer1, 0);
      67. }
      68. break;
      69. case WM_NOTIFY_PARENT:
      70. Id = WM_GetId(pMsg->hWinSrc);
      71. NCode = pMsg->Data.v;
      72. switch(Id)
      73. {
      74. case ID_BUTTON_SCREEN_3:
      75. switch(NCode)
      76. {
      77. case WM_NOTIFICATION_CLICKED:
      78. break;
      79. case WM_NOTIFICATION_RELEASED:
      80. WM_DeleteWindow(pMsg->hWin);
      81. GUI_CreateDialogBox(_aScreen2Create, GUI_COUNTOF(_aScreen2Create), _cbScreen2, WM_HBKWIN, 0, 0);
      82. break;
      83. }
      84. break;
      85. case ID_BUTTON_BACK_MENU_3:
      86. switch(NCode)
      87. {
      88. case WM_NOTIFICATION_RELEASED:
      89. WM_DeleteWindow(pMsg->hWin);
      90. GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
      91. break;
      92. }
      93. break;
      94. case ID_BUTTON_3: // Notifications sent by 'Iconview'
      95. switch(NCode)
      96. {
      97. case WM_NOTIFICATION_RELEASED:
      98. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_30);
      99. }
      100. }
      101. default:
      102. WM_DefaultProc(pMsg);
      103. break;
      104. }
      105. }
      Display All

      Example how the dialog is called:

      C Source Code

      1. case ID_BUTTON_SCREEN_1:
      2. switch(NCode)
      3. {
      4. case WM_NOTIFICATION_CLICKED:
      5. break;
      6. case WM_NOTIFICATION_RELEASED:
      7. WM_DeleteWindow(pMsg->hWin);
      8. GUI_CreateDialogBox(_aScreen3Create, GUI_COUNTOF(_aScreen3Create), _cbScreen3, WM_HBKWIN, 0, 0);
      9. break;
      10. }
      11. break;
      Display All


      Thank you very much!
      Images
      • image0.jpeg

        384.41 kB, 1,632×1,224, viewed 663 times
      • image1.jpeg

        409.37 kB, 1,632×1,224, viewed 677 times
    • Hi,

      to keep the graph data, the dialog that contains the graph handles should not be deleted.

      You could hide the graph dialog when switching to another window and show the graph dialog again when opening it.

      So instead of deleting the windows and creating them again, you could use the routines WM_HideWindow() and WM_ShowWindow().

      Best regards,

      Florian
      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.