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

« Back to documentation index

Show/hide line numbers DIALOG_Count.c Source File

DIALOG_Count.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_Count.c
00041 Purpose     : Shows a dialog which is continously counting
00042 Requirements: WindowManager - (x)
00043               MemoryDevices - (x)
00044               AntiAliasing  - ( )
00045               VNC-Server    - ( )
00046               PNG-Library   - ( )
00047               TrueTypeFonts - ( )
00048 ---------------------------END-OF-HEADER------------------------------
00049 */
00050 
00051 #include "DIALOG.h"
00052 
00053 /*********************************************************************
00054 *
00055 *       Defines
00056 *
00057 **********************************************************************
00058 */
00059 //
00060 // Recommended memory to run the sample with adequate performance
00061 //
00062 #define RECOMMENDED_MEMORY (1024L * 25)
00063 
00064 /*********************************************************************
00065 *
00066 *       Static data
00067 *
00068 **********************************************************************
00069 */
00070 static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
00071   { FRAMEWIN_CreateIndirect, "Counting...",     0,      30,  90, 260, 145, FRAMEWIN_CF_MOVEABLE },
00072   { TEXT_CreateIndirect,     "00",     GUI_ID_TEXT0,    10,  10, 120,  80 },
00073   { RADIO_CreateIndirect,    "",       GUI_ID_RADIO0,  150,  10, 100,  80, 0, 4 },
00074   { BUTTON_CreateIndirect,   "OK",     GUI_ID_OK,       10, 100,  60,  18 },
00075   { BUTTON_CreateIndirect,   "Cancel", GUI_ID_CANCEL,  180, 100,  60,  18 },
00076 };
00077 
00078 static const char * _apLabel[] = {
00079   "GUI_FontFD32",
00080   "GUI_FontFD48",
00081   "GUI_FontFD64",
00082   "GUI_FontFD80",
00083 };
00084 
00085 static const GUI_FONT * _apFont[] = {
00086   &GUI_FontD32,
00087   &GUI_FontD48,
00088   &GUI_FontD64,
00089   &GUI_FontD80
00090 };
00091 
00092 static const char * _asExplain[] = {
00093   "Please use the RADIO buttons to select",
00094   "the big digit font used for counting."
00095 };
00096 
00097 /*********************************************************************
00098 *
00099 *       Static code
00100 *
00101 **********************************************************************
00102 */
00103 /*********************************************************************
00104 *
00105 *       _SetFont
00106 */
00107 static void _SetFont(WM_HWIN hDlg) {
00108   WM_HWIN hItem;
00109   int Index;
00110   hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO0);
00111   Index = RADIO_GetValue(hItem);
00112   hItem = WM_GetDialogItem(hDlg, GUI_ID_TEXT0);
00113   TEXT_SetFont(hItem, _apFont[Index]);
00114 }
00115 
00116 /*********************************************************************
00117 *
00118 *       _cbBkWindow
00119 */
00120 static void _cbBkWindow(WM_MESSAGE * pMsg) {
00121   unsigned i;
00122   switch (pMsg->MsgId) {
00123   case WM_PAINT:
00124     GUI_SetBkColor(GUI_BLUE);
00125     GUI_Clear();
00126     GUI_SetColor(GUI_WHITE);
00127     GUI_SetFont(&GUI_Font24_ASCII);
00128     GUI_DispStringHCenterAt("Counting Sample", 160, 5);
00129     GUI_SetFont(&GUI_Font8x16);
00130     for (i = 0; i < GUI_COUNTOF(_asExplain); i++) {
00131       GUI_DispStringAt(_asExplain[i], 5, 40 + i * 16);
00132     }
00133   default:
00134     WM_DefaultProc(pMsg);
00135   }
00136 }
00137 
00138 /*********************************************************************
00139 *
00140 *       _cbCallback
00141 */
00142 static void _cbCallback(WM_MESSAGE * pMsg) {
00143   unsigned i;
00144   int NCode, Id;
00145   WM_HWIN hDlg, hItem;
00146   hDlg = pMsg->hWin;
00147   switch (pMsg->MsgId) {
00148     case WM_INIT_DIALOG:
00149       hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO0);
00150       for (i = 0; i < GUI_COUNTOF(_apLabel); i++) {
00151         RADIO_SetText(hItem, _apLabel[i], i);
00152       }
00153       _SetFont(hDlg);
00154       break;
00155     case WM_NOTIFY_PARENT:
00156       Id    = WM_GetId(pMsg->hWinSrc);    /* Id of widget */
00157       NCode = pMsg->Data.v;               /* Notification code */
00158       switch (NCode) {
00159       case WM_NOTIFICATION_VALUE_CHANGED: /* Value has changed */
00160         _SetFont(hDlg);
00161         break;
00162       case WM_NOTIFICATION_RELEASED:      /* React only if released */
00163         if (Id == GUI_ID_OK) {            /* OK Button */
00164           GUI_EndDialog(hDlg, 0);
00165         }
00166         if (Id == GUI_ID_CANCEL) {        /* Cancel Button */
00167           GUI_EndDialog(hDlg, 1);
00168         }
00169         break;
00170       }
00171       break;
00172     default:
00173       WM_DefaultProc(pMsg);
00174   }
00175 }
00176 
00177 /*********************************************************************
00178 *
00179 *       Public code
00180 *
00181 **********************************************************************
00182 */
00183 /*********************************************************************
00184 *
00185 *       MainTask
00186 */
00187 void MainTask(void) {
00188   int Value = 0;
00189   WM_HWIN hDlgFrame;
00190   
00191   WM_SetCreateFlags(WM_CF_MEMDEV);  /* Use memory devices on all windows to avoid flicker */
00192   GUI_Init();
00193   //
00194   // Check if recommended memory for the sample is available
00195   //
00196   if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
00197     GUI_ErrorOut("Not enough memory available."); 
00198     return;
00199   }
00200   WM_SetCallback(WM_HBKWIN, _cbBkWindow);  
00201   hDlgFrame = 0;
00202   while(1) {
00203     WM_HWIN hDlg, hText;
00204     char acText[3] = {0};
00205     GUI_Delay(150);
00206     if (!WM_IsWindow(hDlgFrame)) {
00207       hDlgFrame = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
00208     }
00209     Value = (Value + 1) % 100;
00210     acText[0] = '0' + Value / 10;
00211     acText[1] = '0' + Value % 10;
00212     hDlg = WM_GetClientWindow(hDlgFrame);
00213     hText = WM_GetDialogItem(hDlg, GUI_ID_TEXT0);
00214     TEXT_SetText(hText, acText);
00215   }
00216 }
00217 
00218 /*************************** End of file ****************************/
00219