Updating variable values dynamically

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

    • Updating variable values dynamically

      I'm using the GUI_DispDecAt() API to display a value at a particular position. However, I want to update this value within a loop. The values are getting overwritten. Is there anyway to updated the digits alone?

      int var = 100;

      for(int k =0; k <10; k++) {

      GUI_DispDecAt(var++,140,72,3);
      }

      Please let me know how to go about this. Thank You!
    • Hi,

      the values are getting written onto the display all at once. You can add a delay to the for-loop to see the value getting updated. To do that, use GUI_Delay(ms).

      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.
    • Hi,

      Your suggestion works. However, I got the same output using the function GUI_DispStringAtCEOL(). Is there a way to change the way the area is refreshed? It looks like a transparent rectangle sliding down and then new value is displayed. Is there a way to change this animation? I want just the digit to change.

      Thank You.

      The post was edited 1 time, last by jysrvnn ().

    • Hi,

      when you are displaying a new value, it is written above the old value. Therefore, the background of the value has to be cleared, so that only the new value is visible in the end. You can clear the background of a window with GUI_Clear().

      Note that GUI_Clear() clears the entire screen with the currently set background color. You can limit the area to be cleared with GUI_ClearRect().

      If emWin widgets are included in your library or source code, using the TEXT widget will be probably a lot easier. The TEXT widget also has a decimal mode for displaying numeric values. After it has been created, to update the text or value, you only have to call TEXT_SetText() or TEXT_SetDec().

      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.
    • Hi, using the Text widget is a good idea. I'm creating a Text widget within my Window. However, I would like to update it within a different function. How to get the handle of the dialog item (that is the Text item)?


      static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 35,50, 320, 480, 0, 0x0, 0 },
      { GRAPH_CreateIndirect, "Graph", ID_GRAPH_0, 0, 38, GRAPH1_LEN, GRAPH1_WID, 0, 0x0, 0 },
      { TEXT_CreateIndirect, "Text", ID_TEXT_0, 192, 5, 120, 30, 0, 0x0, 0 }
      };

      /*********************************************************************
      *
      * _cbDialog
      *
      **********************************************************************
      */

      static void _cbDialog(WM_MESSAGE * pMsg) {

      WM_HWIN hItem;
      switch (pMsg->MsgId) {
      case WM_INIT_DIALOG:

      // Initialization of 'Window'

      hItem = pMsg->hWin;
      WINDOW_SetBkColor(hItem, GUI_MAKE_COLOR(0x00000000));//0x00000000

      // Initialization of 'TEXT'

      hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
      TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
      TEXT_SetFont(hItem, Roboto_30);
      TEXT_SetTextColor(hItem, UI_GREEN);
      TEXT_SetText(hItem, "120");
      break;

      default:
      WM_DefaultProc(pMsg);
      break;
      }
      }

      /*********************************************************************
      *
      * Update_Text
      */*********************************************************************

      static void _UpdateText(int val) {

      WM_HWIN Txt;

      char buff[10];
      for(int k =0; k < 10; k++) {
      sprintf(buff, "%i", val);
      val++;
      Txt = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0); //here it's throwing error because the pMsg->hWin handle is not defined here
      TEXT_SetText(Txt, buff);
      }
      }
    • Hi,

      you can get the handle of the TEXT widget by calling WM_GetDialogItem(hParent, ID_TEXT_0) where hParent is the parent window of the child window. In this case, the dialog is the parent of the TEXT widget.

      In your function _UpdateText(), you can't call pMsg->hWin without having a pointer to a WM_MESSAGE structure. You could save the handle of the parent window as a static variable in order for the function to work.

      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.