Andrew Reed / Mbed OS CITY1082-i2c_master_wifi_mqtt
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DIALOG_Radio.c Source File

DIALOG_Radio.c

00001 /*********************************************************************
00002 *                SEGGER Microcontroller GmbH                         *
00003 *        Solutions for real time microcontroller applications        *
00004 **********************************************************************
00005 *                                                                    *
00006 *        (c) 1996 - 2018  SEGGER Microcontroller GmbH                *
00007 *                                                                    *
00008 *        Internet: www.segger.com    Support:  support@segger.com    *
00009 *                                                                    *
00010 **********************************************************************
00011 
00012 ** emWin V5.48 - Graphical user interface for embedded applications **
00013 All  Intellectual Property rights  in the Software belongs to  SEGGER.
00014 emWin is protected by  international copyright laws.  Knowledge of the
00015 source code may not be used to write a similar product.  This file may
00016 only be used in accordance with the following terms:
00017 
00018 The software  has been licensed to  Cypress Semiconductor Corporation,
00019 whose registered  office is situated  at 198 Champion Ct. San Jose, CA 
00020 95134 USA  solely for the  purposes of creating  libraries for Cypress
00021 PSoC3 and  PSoC5 processor-based devices,  sublicensed and distributed
00022 under  the  terms  and  conditions  of  the  Cypress  End User License
00023 Agreement.
00024 Full source code is available at: www.segger.com
00025 
00026 We appreciate your understanding and fairness.
00027 ----------------------------------------------------------------------
00028 Licensing information
00029 Licensor:                 SEGGER Microcontroller Systems LLC
00030 Licensed to:              Cypress Semiconductor Corp, 198 Champion Ct., San Jose, CA 95134, USA
00031 Licensed SEGGER software: emWin
00032 License number:           GUI-00319
00033 License model:            Services and License Agreement, signed June 10th, 2009
00034 Licensed platform:        Any Cypress platform (Initial targets are: PSoC3, PSoC5)
00035 ----------------------------------------------------------------------
00036 Support and Update Agreement (SUA)
00037 SUA period:               2009-06-12 - 2022-07-27
00038 Contact to extend SUA:    sales@segger.com
00039 ----------------------------------------------------------------------
00040 File        : DIALOG_Radio.c
00041 Purpose     : Example demonstrating the use of a RADIO widget
00042 Requirements: WindowManager - (x)
00043               MemoryDevices - (x)
00044               AntiAliasing  - ( )
00045               VNC-Server    - ( )
00046               PNG-Library   - ( )
00047               TrueTypeFonts - ( )
00048 ----------------------------------------------------------------------
00049 */
00050 
00051 #include <stddef.h>
00052 #include "GUI.h"
00053 #include "DIALOG.h"
00054 
00055 /*********************************************************************
00056 *
00057 *       Defines
00058 *
00059 **********************************************************************
00060 */
00061 //
00062 // Recommended memory to run the sample with adequate performance
00063 //
00064 #define RECOMMENDED_MEMORY (1024L * 10)
00065 
00066 /*********************************************************************
00067 *
00068 *       Static data
00069 *
00070 **********************************************************************
00071 */
00072 /*********************************************************************
00073 *
00074 *       Dialog resource
00075 *
00076 * Function description
00077 *   This table conatins the info required to create the dialog.
00078 *   It has been created manually, but could also be created by a GUI-builder.
00079 */
00080 static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
00081   { FRAMEWIN_CreateIndirect, "Radio button sample", 0,        30,  70, 260, 100, FRAMEWIN_CF_MOVEABLE },
00082   { RADIO_CreateIndirect,     NULL,           GUI_ID_RADIO0,   5,  10,   0,   0,   0,  3 },
00083   { TEXT_CreateIndirect,     "Suspend",       GUI_ID_TEXT0,   25,  10,  70,  20, TEXT_CF_LEFT },
00084   { TEXT_CreateIndirect,     "Shut down",     GUI_ID_TEXT1,   25,  30,  70,  20, TEXT_CF_LEFT },
00085   { TEXT_CreateIndirect,     "Restart after", GUI_ID_TEXT2,   25,  50,  70,  20, TEXT_CF_LEFT },
00086   { TEXT_CreateIndirect,     "seconds",       GUI_ID_TEXT3,  130,  50,  70,  20, TEXT_CF_LEFT },
00087   { EDIT_CreateIndirect,     "200",           GUI_ID_EDIT0,   95,  47,  30,  19, 0, 3},
00088   { BUTTON_CreateIndirect,   "OK",            GUI_ID_OK,     180,  10,  60,  20 },
00089   { BUTTON_CreateIndirect,   "Cancel",        GUI_ID_CANCEL, 180,  40,  60,  20 }
00090 };
00091 
00092 /*********************************************************************
00093 *
00094 *       Static code
00095 *
00096 **********************************************************************
00097 */
00098 /*********************************************************************
00099 *
00100 *       _cbBkWindow
00101 */
00102 static void _cbBkWindow(WM_MESSAGE* pMsg) {
00103   switch (pMsg->MsgId) {
00104   case WM_PAINT:
00105     GUI_SetBkColor(GUI_RED);
00106     GUI_Clear();
00107     GUI_SetColor(GUI_WHITE);
00108     GUI_SetFont(&GUI_Font24_ASCII);
00109     GUI_DispStringHCenterAt("DIALOG_Radio - Sample", 160, 5);
00110     break;
00111   default:
00112     WM_DefaultProc(pMsg);
00113   }
00114 }
00115 
00116 /*********************************************************************
00117 *
00118 *       _cbCallback
00119 */
00120 static void _cbCallback(WM_MESSAGE * pMsg) {
00121   WM_HWIN hDlg;
00122   WM_HWIN hItem;
00123   int     Sel;
00124   int     NCode;
00125   int     Id;
00126 
00127   GUI_PID_STATE * pState;
00128   hDlg = pMsg->hWin;
00129   switch (pMsg->MsgId) {
00130     case WM_INIT_DIALOG:
00131       hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT0);
00132       EDIT_SetDecMode(hItem, 30,   0, 999, 0, 0);    // Select decimal mode
00133       WM_DisableWindow(hItem);
00134       break;
00135     case WM_KEY:
00136       switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) {
00137         case GUI_KEY_ESCAPE:
00138           GUI_EndDialog(hDlg, 1);
00139           break;
00140         case GUI_KEY_ENTER:
00141           GUI_EndDialog(hDlg, 0);
00142           break;
00143       }
00144       break;
00145     case WM_TOUCH_CHILD:
00146       Id = WM_GetId(pMsg->hWinSrc);      // Id of widget
00147       switch (Id) {
00148         case GUI_ID_TEXT0:
00149         case GUI_ID_TEXT1:
00150         case GUI_ID_TEXT2:
00151           pState = (GUI_PID_STATE *)((WM_MESSAGE *)pMsg->Data.p)->Data.p;
00152           if (pState) {
00153             if (pState->Pressed) {
00154               WM_HWIN hRadio = WM_GetDialogItem(hDlg, GUI_ID_RADIO0);
00155               RADIO_SetValue(hRadio, Id - GUI_ID_TEXT0);    // Use the text beside the radio button to 
00156                                                             // set the value of the radio button
00157             }
00158           }
00159           break;
00160       }
00161       break;
00162     case WM_NOTIFY_PARENT:
00163       Id    = WM_GetId(pMsg->hWinSrc);      // Id of widget
00164       NCode = pMsg->Data.v;                 // Notification code
00165       switch (NCode) {
00166         case WM_NOTIFICATION_RELEASED:      // React only if released
00167           switch (Id) {
00168             case GUI_ID_OK:
00169               GUI_EndDialog(hDlg, 0);
00170               break;
00171             case GUI_ID_CANCEL:
00172               GUI_EndDialog(hDlg, 1);
00173               break;
00174           }
00175           break;
00176         case WM_NOTIFICATION_VALUE_CHANGED:
00177           hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO0);
00178           Sel   = RADIO_GetValue(hItem);
00179           hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT0);
00180           WM_SetEnableState(hItem, Sel == 2);      
00181           break;
00182       }
00183       break;
00184     default:
00185       WM_DefaultProc(pMsg);
00186   }
00187 }
00188 
00189 /*********************************************************************
00190 *
00191 *       Public code
00192 *
00193 **********************************************************************
00194 */
00195 /*********************************************************************
00196 *
00197 *       MainTask
00198 */
00199 void MainTask(void) {
00200   WM_SetCreateFlags(WM_CF_MEMDEV);  // Use memory devices on all windows to avoid flicker
00201   GUI_Init();
00202   //
00203   // Check if recommended memory for the sample is available
00204   //
00205   if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
00206     GUI_ErrorOut("Not enough memory available."); 
00207     return;
00208   }
00209   WM_SetCallback(WM_HBKWIN, &_cbBkWindow);
00210   while (1) {
00211     GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
00212     GUI_Delay(1000);
00213   }
00214 }
00215 
00216 /*************************** End of file ****************************/
00217