GAUGE (Sample)

From SEGGER Wiki
(Redirected from GAUGE (Usage))
Jump to: navigation, search
GAUGE_Usage.c
GAUGE Usage.gif
File(s) required
  • GAUGE_Usage.c
Runs in simulation Yes
Runs on target Yes
Download GAUGE_Usage.c

This sample demonstrates the usage and custom drawing of a GAUGE widget.

Code

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

** emWin V6.10 - 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        : GAUGE_Usage.c
Purpose     : Sample that demonstrates how the user can use a GAUGE
              widget and define its appearance.
Requirements: WindowManager - (x)
              MemoryDevices - ( )
              AntiAliasing  - ( )
              VNC-Server    - ( )
              PNG-Library   - ( )
              TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/

#include "DIALOG.h"
#include <stdio.h>

/*********************************************************************
*
*       Defines
*
**********************************************************************
*/

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/
static WM_HWIN _hGauge;

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/
/*********************************************************************
*
*       _cbWin
*/
static void _cbWin(WM_MESSAGE * pMsg) {
  int NCode, Id;
  char acBuffer[32];
  int Value;

  switch(pMsg->MsgId) {
  case WM_CREATE:
    //
    // Create GAUGE widget.
    //
    _hGauge = GAUGE_CreateUser(10, 10, 300, 200, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_GAUGE0, 0);
    //
    // Set starting angle of GAUGE to -30° and ending angle to 210°.
    //
    GAUGE_SetRange(_hGauge, -30000, 210000);
    //
    // Set radius of GAUGE.
    //
    GAUGE_SetRadius(_hGauge, 90);
    //
    // Set color of the background arc to gray.
    // Set color of the foreground arc to green.
    //
    GAUGE_SetColor(_hGauge, 0, GUI_GRAY);
    GAUGE_SetColor(_hGauge, 1, GUI_GREEN);
    //
    // Set width of the background arc to 16 px.
    // Set width of the foreground arc to 8 px.
    //
    GAUGE_SetWidth(_hGauge, 0, 16);
    GAUGE_SetWidth(_hGauge, 1, 8);
    //
    // Set range of values from 0 to 1000.
    //
    GAUGE_SetValueRange(_hGauge, 0, 1000);
    //
    // Set background color of the widget to white.
    //
    GAUGE_SetBkColor(_hGauge, GUI_WHITE);
    //
    // Align the GAUGE to be in the center.
    //
    GAUGE_SetAlign(_hGauge, GUI_ALIGN_HCENTER | GUI_ALIGN_VCENTER);
    GAUGE_SetOffset(_hGauge, 0, 15);
    //
    // Set both arcs to have round edged ends.
    //
    GAUGE_SetRoundedEnd(_hGauge, 1);
    GAUGE_SetRoundedValue(_hGauge, 1);
    break;
  case WM_PAINT:
    GUI_SetBkColor(GUI_BLACK);
    GUI_Clear();
    //
    // Display value of GAUGE.
    //
    Value = GAUGE_GetValue(_hGauge);
    sprintf(acBuffer, "Value: %d", Value);
    GUI_SetColor(GUI_WHITE);
    GUI_DispStringAt(acBuffer, 320, 10);
    break;
  case WM_NOTIFY_PARENT:
    Id    = WM_GetId(pMsg->hWinSrc);
    NCode = pMsg->Data.v;
    switch(Id) {
    case GUI_ID_GAUGE0:
      switch(NCode) {
      case WM_NOTIFICATION_VALUE_CHANGED:
        //
        // Invalidate parent window when GAUGE's value has changed to update the displayed value.
        //
        WM_InvalidateWindow(pMsg->hWin);
        break;
      }
      break;
    }
    break;
  default:
    WM_DefaultProc(pMsg);
  }
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       MainTask
*/
void MainTask(void) {
  int i;

  GUI_Init();
  //
  // Enable multi-buffering.
  //
  WM_MULTIBUF_Enable(1);
  //
  // Create parent window that creates the GAUGE as a child window.
  //
  WM_CreateWindow(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_CF_SHOW, _cbWin, 0);
  //
  // Continously update GAUGE.
  //
  while (1) {
    if (_hGauge) {
      for (i = 0; i < 1000; i += 10) {
        GAUGE_SetValue(_hGauge, i);
        GUI_Delay(1);
      }
      for (i = 1000; i >= 0; i -= 10) {
        GAUGE_SetValue(_hGauge, i);
        GUI_Delay(1);
      }
    }
  }
}

/*************************** End of file ****************************/