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

« Back to documentation index

Show/hide line numbers TOUCH_Calibrate.c Source File

TOUCH_Calibrate.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        : TOUCH_Calibrate.c
00041 Purpose     : Demonstrates how a touch screen can be calibrated at run time
00042 Requirements: WindowManager - (X)
00043               MemoryDevices - ( )
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 #define NUM_CALIB_POINTS  5  // Number of points for calibration
00060 
00061 /*********************************************************************
00062 *
00063 *       Static Data
00064 *
00065 **********************************************************************
00066 */
00067 static int _aRefX[NUM_CALIB_POINTS];
00068 static int _aRefY[NUM_CALIB_POINTS];
00069 static int _aSamX[NUM_CALIB_POINTS];
00070 static int _aSamY[NUM_CALIB_POINTS];
00071 
00072 /*********************************************************************
00073 *
00074 *       Static code
00075 *
00076 **********************************************************************
00077 */
00078 /*********************************************************************
00079 *
00080 *       _Calibrate
00081 *
00082 * Purpose:
00083 *   Calibrates the touch screen. Please note that this sample assumes
00084 *   that the 'Driver API for analog touch screens' is used.
00085 */
00086 static void _Calibrate(void) {
00087   GUI_PID_STATE State;
00088   int i;
00089   int xSize, ySize;
00090 
00091   xSize = LCD_GetXSize();
00092   ySize = LCD_GetYSize();
00093   //
00094   // Calculate reference points depending on LCD size
00095   //
00096   _aRefX[0] = (xSize * 5) / 100;
00097   _aRefY[0] = (ySize * 5) / 100;
00098   _aRefX[1] = xSize - (xSize * 5) / 100;
00099   _aRefY[1] = _aRefY[0];
00100   _aRefX[2] = _aRefX[1];
00101   _aRefY[2] = ySize - (ySize * 5) / 100;
00102   _aRefX[3] = _aRefX[0];
00103   _aRefY[3] = _aRefY[2];
00104   _aRefX[4] = xSize / 2;
00105   _aRefY[4] = ySize / 2;
00106   //
00107   // Draw reference points on LCD
00108   //
00109   GUI_TOUCH_GetState(&State);
00110   State.Pressed = 0;
00111   GUI_SetPenSize(3);
00112   for (i = 0; i < NUM_CALIB_POINTS; i++) {
00113     GUI_Clear();
00114     GUI_DispStringHCenterAt("Please touch the point", LCD_GetXSize() / 2, LCD_GetYSize() / 2 - 60);
00115     GUI_DrawCircle(_aRefX[i], _aRefY[i], 5);
00116     while (State.Pressed != 1) {
00117       GUI_Delay(250);
00118       GUI_TOUCH_GetState(&State);
00119     }
00120     if (State.Pressed == 1) {
00121       //
00122       // Store sample points
00123       //
00124       _aSamX[i] = GUI_TOUCH_GetxPhys();
00125       _aSamY[i] = GUI_TOUCH_GetyPhys();
00126     }
00127     State.Pressed = 0;
00128     GUI_Delay(250);
00129   }
00130   //
00131   // Pass measured points to emWin
00132   //
00133   GUI_TOUCH_CalcCoefficients(NUM_CALIB_POINTS, _aRefX, _aRefY, _aSamX, _aSamY, xSize, ySize);
00134 }
00135 
00136 /*********************************************************************
00137 *
00138 *       Public code
00139 *
00140 **********************************************************************
00141 */
00142 /*********************************************************************
00143 *
00144 *       MainTask
00145 */
00146 void MainTask(void) {
00147   GUI_Init();
00148   //
00149   // Calibrate touch ...
00150   //
00151   _Calibrate();
00152   //
00153   // ... and play with it
00154   //
00155   GUI_CURSOR_Show();
00156   BUTTON_Create(100, 100, 200, 50, 1234, WM_CF_SHOW);  // A button to be touched
00157   while (1) {
00158     GUI_Delay(100);
00159   }
00160 }
00161 
00162 /*************************** End of file ****************************/