GRAPH - Usage (Sample)
GRAPH_Usage.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | GRAPH_Usage.c |
This sample demonstrates the usage of a GRAPH 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 : GRAPH_Usage.c
Purpose : Sample that demonstrates the usage of GRAPH widgets
in emWin.
Requirements: WindowManager - (x)
MemoryDevices - ( )
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
GRAPH_DATA_Handle hData;
GRAPH_SCALE_Handle hScale;
WM_HWIN hGraph;
int Angle;
int Value;
//
// Init GUI
//
GUI_Init();
//
// Enable multi-buffering to avoid flickering during the continuous update of the graph.
//
WM_MULTIBUF_Enable(1);
//
// Create graph widget
//
hGraph = GRAPH_CreateEx(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, GRAPH_CF_GRID_FIXED_X, GUI_ID_GRAPH0);
//
// Configure grid
//
GRAPH_SetGridVis(hGraph, 1); // Enable grid
GRAPH_SetGridDistX(hGraph, 10); // Set X size of grid to 10 pixels
GRAPH_SetGridDistY(hGraph, 10); // Set Y size of grid to 10 pixels
GRAPH_SetGridOffY(hGraph, -5); // Set offset of grid to match with the graph
//
// Set a border to the left of the graph
//
GRAPH_SetBorder(hGraph, 30, 0, 0, 0);
//
// Create data object
// A graph widget has one or more data objects attached.
// These objects are the line displaying the graph data.
// emWin supports two types of curves:
// - GRAPH_DATA_XY for showing a function graph with X/Y coordinates
// - GRAPH_DATA_YT for showing curves with 1 Y-value for each X-position
// e.g. for displaying continuously updated measurement values
//
hData = GRAPH_DATA_YT_Create(GUI_RED, LCD_GetXSize(), NULL, 0);
//
// Position the curve
//
GRAPH_DATA_YT_SetAlign(hData, GRAPH_ALIGN_LEFT);
GRAPH_DATA_YT_SetOffY(hData, 75);
//
// Attach the data object to the graph
//
GRAPH_AttachData(hGraph, hData);
//
// Create scale object
//
hScale = GRAPH_SCALE_Create(15, GUI_TA_HCENTER | GUI_TA_VCENTER, GRAPH_SCALE_CF_VERTICAL, 1);
//
// Configure the scale
//
GRAPH_SCALE_SetNumDecs(hScale, 0); // No decimals are shown on the scale
GRAPH_SCALE_SetFactor(hScale, 1); // Factor of the numbers on the scale
GRAPH_SCALE_SetTickDist(hScale, 20); // Distance in pixels between each number on the scale
GRAPH_SCALE_SetOff(hScale, 130); // Set y-offset of the scale to show negative numbers
//
// Attach the scale object to the graph
//
GRAPH_AttachScale(hGraph, hScale);
//
// Continuously feed the graph with data to create a sine curve
//
Angle = 0;
while (1) {
GUI_Delay(10);
Value = GUI__SinHQ(((Angle++) % 360) * 1000);
Value = (50 * Value) >> 16;
GRAPH_DATA_YT_AddValue(hData, (I16)Value + 60);
}
}
/*************************** End of file ****************************/