RADIO - Usage (Sample)
RADIO_Usage.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | RADIO_Usage.c |
This sample demonstrates the usage of a RADIO widget.
Demo
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 : RADIO_Usage.c
Purpose : Sample that demonstrates the usage of RADIO widgets in
emWin. The sample also shows, how multiple RADIOs can be
combined by grouping them.
Requirements: WindowManager - (x)
MemoryDevices - ( )
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
#include <stdio.h>
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define RADIO_GROUP 1
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
static const char * _acValues[] = {
"Red",
"Green",
"Blue",
"Magenta",
"Cyan",
"Yellow"
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
static void _cbWin(WM_MESSAGE * pMsg) {
static WM_HWIN hRadio0, hRadio1;
int i, j;
char acBuffer[32];
int NCode, Id;
int Value;
static WM_HWIN hNotify;
switch(pMsg->MsgId) {
case WM_CREATE:
//
// Create a RADIO widget.
//
hRadio0 = RADIO_CreateEx(10, 10, 60, 60, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_RADIO0, 3, 20);
//
// Add items to RADIO.
//
for (i = 0; i < (GUI_COUNTOF(_acValues) / 2); i++) {
RADIO_SetText(hRadio0, *(_acValues + i), i);
}
//
// Edit the widget's properties.
//
RADIO_SetFont(hRadio0, &GUI_Font13B_1);
RADIO_SetTextColor(hRadio0, GUI_RED);
//
// Increment selection.
//
RADIO_Inc(hRadio0);
//
// Create another RADIO.
//
hRadio1 = RADIO_CreateEx(80, 10, 80, 60, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_RADIO0, 3, 20);
for (j = 0; j < (GUI_COUNTOF(_acValues) / 2); j++) {
RADIO_SetText(hRadio1, *(_acValues + i), j);
i++;
}
//
// Group both RADIOs together.
// This way, we can only select one item from both RADIOs.
//
RADIO_SetGroupId(hRadio0, RADIO_GROUP);
RADIO_SetGroupId(hRadio1, RADIO_GROUP);
break;
case WM_PAINT:
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
GUI_SetFont(&GUI_Font13B_1);
GUI_SetColor(GUI_BLACK);
//
// Process current selection.
//
Value = RADIO_GetValue(hNotify);
if (Value != -1) {
if(hNotify == hRadio1) {
//
// If our second radio widget was clicked, we need to add an offset to the value,
// so we access the correct string.
//
Value += 3;
}
sprintf(acBuffer, "Current selection: %s", *(_acValues + Value));
GUI_DispStringAt(acBuffer, 10, 80);
}
break;
case WM_NOTIFY_PARENT:
//
// Get Id of sender window and notification code.
//
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch (Id) {
case GUI_ID_RADIO0:
case GUI_ID_RADIO1:
switch(NCode) {
case WM_NOTIFICATION_VALUE_CHANGED:
//
// Save the RADIO widget that was clicked, so we can process it later.
//
hNotify = pMsg->hWinSrc;
//
// Redraw the parent window when the RADIO's selection has changed.
//
WM_InvalidateWindow(pMsg->hWin);
break;
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
//
// Init emWin.
//
GUI_Init();
//
// Create parent window for RADIO.
//
WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWin, 0);
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/