Need to plot Knob with Graph [Newbie]

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

    • Need to plot Knob with Graph [Newbie]

      Hi,
      I am new to EmWin and am using it on an STM32 Discovery platform. I want to find a way of plotting two graphs and a knob. So far I have managed to plot the graphs and update their values based on code available on this forums. However, I can not see the knob when I try to plot it. I am attaching the relevant code below.


      /*********************************************************************
      * SEGGER MICROCONTROLLER SYSTEME GmbH *
      * Solutions for real time microcontroller applications *
      **********************************************************************
      * *
      * (c) 1996 - 2015 SEGGER Microcontroller Systeme GmbH *
      * *
      * Internet: segger.com Support: support@segger.com *
      * *
      **********************************************************************

      ***** emWin - Graphical user interface for embedded applications *****
      emWin is protected by international copyright laws. Knowledge of the
      source code may not be used to write a similar product. This file may
      only be used in accordance with a license and should not be re-
      distributed in any way. We appreciate your understanding and fairness.
      ----------------------------------------------------------------------
      File : BASIC_HelloWorld.c
      Purpose : Simple demo drawing "Hello world"
      ----------------------------------------------------------------------
      */

      #include "GUI.h"
      #include "download.c"
      #include "DIALOG.h"
      #include "KNOB.h"
      /*********************************************************************
      *
      * Defines
      *
      **********************************************************************
      */
      #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      #define ID_GRAPH_0 (GUI_ID_USER + 0x01)
      #define ID_EDIT_0 (GUI_ID_USER + 0x02)
      #define ID_GRAPH_1 (GUI_ID_USER + 0x03)
      #define ID_KNOB (GUI_ID_USER + 0x04)
      /*********************************************************************
      *
      * Static data
      *
      **********************************************************************
      */
      /*********************************************************************
      *
      * _aDialogCreate
      */
      static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 800, 500, 0, 0x0, 0 },
      { GRAPH_CreateIndirect, "Graph", ID_GRAPH_0, 20, 20, 440, 200, 0, 0x0, 0 },
      { GRAPH_CreateIndirect, "Graph", ID_GRAPH_1, 20, 240, 440, 200, 0, 0x0, 0 },
      { EDIT_CreateIndirect, "Edit", ID_EDIT_0, 600, 200, 150, 50, 0, 0x0, 0},
      { KNOB_CreateIndirect, "Knob", ID_KNOB, 300, 300, 150, 150, 0, 0x0, 0}
      };



      /*********************************************************************
      *
      * Static code
      *
      **********************************************************************
      */
      /*********************************************************************
      *
      * _GetADValue
      */
      static I16 _GetADValue(void) {
      return (rand() % 100 + 1) + 50;
      }
      /*********************************************************************
      *
      * _cbDialog
      */
      static void _cbDialog(WM_MESSAGE * pMsg) {
      static GRAPH_DATA_Handle hData;
      static GRAPH_DATA_Handle hData_1;
      WM_HWIN hItem;
      WM_HWIN hItem_1;
      I16 Value;
      switch (pMsg->MsgId) {
      case WM_INIT_DIALOG:
      hData = GRAPH_DATA_YT_Create(GUI_ORANGE, 440, NULL, 0);
      hData_1 = GRAPH_DATA_YT_Create(GUI_GREEN, 440, NULL, 0);
      hItem = WM_GetDialogItem(pMsg->hWin, ID_GRAPH_0);
      GRAPH_AttachData(hItem, hData);
      WM_CreateTimer(pMsg->hWin, 0, 25, 0);
      hItem_1 = WM_GetDialogItem(pMsg->hWin, ID_GRAPH_1);
      GRAPH_AttachData(hItem_1, hData_1);
      WM_CreateTimer(pMsg->hWin, 0, 25, 0);


      break;
      case WM_TIMER:
      Value = _GetADValue();
      GRAPH_DATA_YT_AddValue(hData, Value);
      WM_RestartTimer((WM_HTIMER)pMsg->Data.v, 0);
      Value = _GetADValue()*2;
      GRAPH_DATA_YT_AddValue(hData_1, Value);
      WM_RestartTimer((WM_HTIMER)pMsg->Data.v, 0);

      break;
      default:
      WM_DefaultProc(pMsg);
      break;
      }
      }
      /*********************************************************************
      *
      * Public code
      *
      **********************************************************************
      */
      /*********************************************************************
      *
      * MainTask
      */
      void MainTask(void) {
      GUI_Init();
      GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);

      while (1) {
      GUI_Delay(100);
      }
      }

      /*************************** End of file ****************************/
    • Hello,

      emWin reference guide, chapter 19.4.6 "KNOB API", function KNOB_SetDevice(): "Sets a memory device which contains a drawn knob. This drawing defines the appearance of the knob."

      So you need first to create memory device at least for the knob image and then attach it to the widget.

      Add memory device handler variable:
      GUI_MEMDEV_Handle hMem;

      Add this code to the WM_INIT_DIALOG handler. This draws a simple knob in memory device and attach it:

      // Create Memory Device 32bpp
      hMem = GUI_MEMDEV_CreateFixed32(0, 0, 150, 150);


      // Select it for drawing
      GUI_MEMDEV_Select(hMem);


      // Draw the knob
      GUI_SetBkColor(GUI_WHITE);
      GUI_Clear();
      GUI_SetColor(GUI_LIGHTBLUE);
      GUI_AA_FillCircle(75, 75, 75);
      GUI_SetColor(GUI_LIGHTRED);
      GUI_AA_FillCircle(75, 20, 10);


      // Return drawing from Memory Device to the screen
      GUI_MEMDEV_Select(0);


      // Get the knob handler and attach Memory Device to the knob
      hItem = WM_GetDialogItem(pMsg->hWin, ID_KNOB);
      KNOB_SetDevice(hItem, hMem);

      It seems your knob covers the graph data area, so you may move it:
      { KNOB_CreateIndirect, "Knob", ID_KNOB, 600, 300, 150, 150, 0, 0x0, 0}

      Alex.

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