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

« Back to documentation index

Show/hide line numbers Calibration.c Source File

Calibration.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        : Calibration.c
00041 Purpose     : TBD
00042 ---------------------------END-OF-HEADER------------------------------
00043 */
00044 
00045 #include <stddef.h>
00046 #include "GUI.h"
00047 #include "DIALOG.h"
00048 #include "Main.h"
00049 
00050 /*********************************************************************
00051 *
00052 *       Defines
00053 *
00054 **********************************************************************
00055 */
00056 /*********************************************************************
00057 *
00058 *       Dialog IDs
00059 */
00060 #define ID_FRAMEWIN              1
00061 
00062 /*********************************************************************
00063 *
00064 *       Static data
00065 *
00066 **********************************************************************
00067 */
00068 static WM_HWIN _hPrevWin;
00069 static int     _aSlider[4];
00070 
00071 static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
00072   { FRAMEWIN_CreateIndirect, "Calibration",  ID_FRAMEWIN,        0, 480, 320, 240, 0},
00073   { TEXT_CreateIndirect,     "Horizontal min:",0,               20,  40,  70,  20, TEXT_CF_LEFT | TEXT_CF_VCENTER },
00074   { TEXT_CreateIndirect,     "Horizontal max:",0,               20,  70,  70,  20, TEXT_CF_LEFT | TEXT_CF_VCENTER },
00075   { TEXT_CreateIndirect,     "Vertical   min:",0,               20, 100,  70,  20, TEXT_CF_LEFT | TEXT_CF_VCENTER },
00076   { TEXT_CreateIndirect,     "Vertical   max:",0,               20, 130,  70,  20, TEXT_CF_LEFT | TEXT_CF_VCENTER },
00077   { SLIDER_CreateIndirect,   NULL,             GUI_ID_SLIDER0, 100,  40, 100,  20 },
00078   { SLIDER_CreateIndirect,   NULL,             GUI_ID_SLIDER1, 100,  70, 100,  20 },
00079   { SLIDER_CreateIndirect,   NULL,             GUI_ID_SLIDER2, 100, 100, 100,  20 },
00080   { SLIDER_CreateIndirect,   NULL,             GUI_ID_SLIDER3, 100, 130, 100,  20 },
00081   { EDIT_CreateIndirect,     NULL ,            GUI_ID_EDIT0,   210,  40,  60,  20, 0, 0},
00082   { EDIT_CreateIndirect,     NULL ,            GUI_ID_EDIT1,   210,  70,  60,  20, 0, 0},
00083   { EDIT_CreateIndirect,     NULL ,            GUI_ID_EDIT2,   210, 100,  60,  20, 0, 0},
00084   { EDIT_CreateIndirect,     NULL ,            GUI_ID_EDIT3,   210, 130,  60,  20, 0, 0},
00085   { BUTTON_CreateIndirect,   "OK",             GUI_ID_OK,      230, 180,  60,  20 },
00086 };
00087 
00088 /*********************************************************************
00089 *
00090 *       Static code
00091 *
00092 **********************************************************************
00093 */
00094 /*********************************************************************
00095 *
00096 *       _OnValueChanged
00097 */
00098 static void _OnValueChanged(WM_HWIN hDlg, int Id) {
00099   unsigned Index, v;
00100   WM_HWIN hItem;
00101   if ((Id >= GUI_ID_SLIDER0) && (Id <= GUI_ID_SLIDER3)) {
00102     Index = Id - GUI_ID_SLIDER0;
00103     /* SLIDER-widget has changed, update EDIT-widget */
00104     hItem = WM_GetDialogItem(hDlg, GUI_ID_SLIDER0 + Index);
00105     v = SLIDER_GetValue(hItem);
00106     hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT0 + Index);
00107     EDIT_SetValue(hItem, v);
00108     _aSlider[Index] = v;
00109   }
00110 }
00111 
00112 /*********************************************************************
00113 *
00114 *       _cbCallback
00115 */
00116 static void _cbCallback(WM_MESSAGE * pMsg) {
00117   WM_HWIN hDlg, hWinSrc, hItem;
00118   int Id, NCode, i;
00119   hWinSrc = pMsg->hWinSrc;
00120   hDlg = pMsg->hWin;
00121   switch (pMsg->MsgId) {
00122   case WM_INIT_DIALOG:
00123     WM_MakeModal(hDlg);
00124     FRAMEWIN_SetFont(hDlg, &GUI_Font24B_ASCII);
00125     FRAMEWIN_SetTextAlign(hDlg, GUI_TA_HCENTER);
00126     FRAMEWIN_SetClientColor(hDlg, GUI_YELLOW);
00127     for (i = 0; i < 4; i++) {
00128       hItem = WM_GetDialogItem(hDlg, GUI_ID_SLIDER0 + i);
00129       SLIDER_SetRange(hItem, 0, 999); 
00130       SLIDER_SetValue(hItem, _aSlider[i]);
00131       hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT0 + i);
00132       EDIT_SetDecMode(hItem, _aSlider[i], 0, 999, 0, 0);
00133       WM_DisableWindow(hItem);
00134     }
00135     break;
00136   case WM_NOTIFY_PARENT:
00137     Id    = WM_GetId(hWinSrc);                    /* Id of widget */
00138     NCode = pMsg->Data.v;                         /* Notification code */
00139     if (NCode == WM_NOTIFICATION_RELEASED) {      /* React only if released */
00140       if (Id == GUI_ID_OK) {                      /* OK Button */
00141         GUI_EndDialog(hDlg, 0);
00142         WM_SetFocus(_hPrevWin);
00143       }
00144     }
00145     if (NCode == WM_NOTIFICATION_VALUE_CHANGED) {
00146       _OnValueChanged(hDlg, Id);
00147     }
00148     break;
00149 
00150   default:
00151     WM_DefaultProc(pMsg);
00152   }
00153 }
00154 
00155 /*********************************************************************
00156 *
00157 *       Public code
00158 *
00159 **********************************************************************
00160 */
00161 /*********************************************************************
00162 *
00163 *       ExecCalibration
00164 */
00165 void ExecCalibration(void) {
00166   _hPrevWin = WM_GetFocussedWindow();
00167   GUI_SetOrg(0, 480);
00168   TEXT_SetDefaultTextColor(GUI_BLACK);
00169   GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
00170   GUI_SetOrg(0, 0);
00171 }
00172 
00173