test export
Dependencies: DmTftLibrary mbed
Fork of dm_calibrate by
main.cpp
00001 /********************************************************************************************** 00002 Copyright (c) 2014 DisplayModule. All rights reserved. 00003 00004 Redistribution and use of this source code, part of this source code or any compiled binary 00005 based on this source code is permitted as long as the above copyright notice and following 00006 disclaimer is retained. 00007 00008 DISCLAIMER: 00009 THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. DISPLAYMODULE ASSUMES 00010 NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE. 00011 ********************************************************************************************/ 00012 00013 /****************************************************************************** 00014 * Includes 00015 *****************************************************************************/ 00016 00017 #include "mbed.h" 00018 00019 #include "DmTftHX8353C.h" 00020 #include "DmTftS6D0164.h" 00021 #include "DmTftIli9325.h" 00022 #include "DmTftIli9341.h" 00023 #include "DmTftSsd2119.h" 00024 #include "DmTftRa8875.h" 00025 #include "DmTouch.h" 00026 #include "DmTouchCalibration.h" 00027 00028 /****************************************************************************** 00029 * Typedefs and defines 00030 *****************************************************************************/ 00031 00032 /* Note that there are restrictions on which platforms that can use printf 00033 in combinations with the DmTftLibrary. Some platforms (e.g. LPC1549 LPCXpresso) 00034 use the same pins for USBRX/USBTX and display control. Printing will 00035 cause the display to not work. Read more about this on the display's notebook 00036 page. */ 00037 //#define log(...) printf(__VA_ARGS__) 00038 #define log(...) 00039 00040 #if 1 00041 /* Displays without adapter */ 00042 #define DM_PIN_SPI_MOSI D11 00043 #define DM_PIN_SPI_MISO D12 00044 #define DM_PIN_SPI_SCLK D13 00045 #define DM_PIN_CS_TOUCH D4 00046 #define DM_PIN_CS_TFT D10 00047 #define DM_PIN_CS_SDCARD D8 00048 #define DM_PIN_CS_FLASH D6 00049 #else 00050 /* Displays with adapter */ 00051 #define DM_PIN_SPI_MOSI A0 00052 #define DM_PIN_SPI_MISO D9 00053 #define DM_PIN_SPI_SCLK A1 00054 #define DM_PIN_CS_TOUCH D8 00055 #define DM_PIN_CS_TFT A3 00056 #define DM_PIN_CS_SDCARD D10 00057 #endif 00058 00059 /****************************************************************************** 00060 * Local variables 00061 *****************************************************************************/ 00062 00063 //DmTftIli9325 tft; /* DM_TFT28_103 and DM_TFT24_104 */ 00064 //DmTftIli9341 tft; /* DM_TFT28_105 */ 00065 //DmTftSsd2119 tft; /* DM_TFT35_107 */ 00066 DmTftRa8875 tft; /* DM_TFT43_108 and DM_TFT50_111 */ 00067 00068 //DmTouch touch(DmTouch::DM_TFT28_103, DmTouch::Software); /* For LPC4088 QuickStart Board */ 00069 //DmTouch touch(DmTouch::DM_TFT28_103); 00070 //DmTouch touch(DmTouch::DM_TFT24_104, DmTouch::Software); /* For LPC4088 QuickStart Board */ 00071 //DmTouch touch(DmTouch::DM_TFT24_104); 00072 //DmTouch touch(DmTouch::DM_TFT28_105); 00073 //DmTouch touch(DmTouch::DM_TFT35_107); 00074 //DmTouch touch(DmTouch::DM_TFT43_108); // For DmTftRa8875 driver, The panel resolution should be config in DmTftRa8875::init() function on the DmTftRa8875.cpp file. 00075 DmTouch touch(DmTouch::DM_TFT50_111); 00076 00077 DmTouchCalibration calibration = DmTouchCalibration(&tft, &touch); 00078 00079 DigitalInOut csTouch(DM_PIN_CS_TOUCH, PIN_OUTPUT, PullUp, 1); 00080 DigitalInOut csDisplay(DM_PIN_CS_TFT, PIN_OUTPUT, PullUp, 1); 00081 DigitalInOut csSDCard(DM_PIN_CS_SDCARD, PIN_OUTPUT, PullUp, 1); 00082 #ifdef DM_PIN_CS_FLASH 00083 DigitalInOut csFlash(DM_PIN_CS_FLASH, PIN_OUTPUT, PullUp, 1); 00084 #endif 00085 00086 bool calibrated = false; 00087 00088 /****************************************************************************** 00089 * Global variables 00090 *****************************************************************************/ 00091 00092 /****************************************************************************** 00093 * Local functions 00094 *****************************************************************************/ 00095 00096 static void loop() { 00097 uint16_t x, y = 0; 00098 bool touched = false; 00099 00100 if (!calibrated) { 00101 tft.drawString(5, 5, "Press and hold on cross"); 00102 tft.drawString(5, 25, "until it turns green. "); 00103 00104 Point displayRefPoint[5]; 00105 Point touchRefPoint[5]; 00106 if (calibration.getTouchReferencePoints(displayRefPoint, touchRefPoint, tft.width(), tft.height())) { 00107 CalibrationMatrix calibrationMatrix = calibration.calculateCalibrationMatrix(displayRefPoint, touchRefPoint); 00108 touch.setCalibrationMatrix(calibrationMatrix); 00109 tft.clearScreen(); 00110 calibration.drawCalibPoint(displayRefPoint[0].x, displayRefPoint[0].y); 00111 calibration.drawCalibPoint(displayRefPoint[1].x, displayRefPoint[1].y); 00112 calibration.drawCalibPoint(displayRefPoint[2].x, displayRefPoint[2].y); 00113 calibration.drawCalibPoint(displayRefPoint[3].x, displayRefPoint[3].y); 00114 calibration.drawCalibPoint(displayRefPoint[4].x, displayRefPoint[4].y); 00115 calibration.drawCalibration(calibrationMatrix); 00116 calibrated = true; 00117 } else { 00118 tft.clearScreen(); 00119 tft.drawString(5, 5, "Calibration failed"); 00120 tft.drawString(5, 25, "Please try again."); 00121 delay(2000); 00122 tft.clearScreen(); 00123 return; 00124 } 00125 } 00126 00127 if (touch.isTouched()) { 00128 touch.readTouchData(x,y,touched); 00129 calibration.drawCalibPoint(x, y); 00130 } 00131 } 00132 00133 /****************************************************************************** 00134 * Main 00135 *****************************************************************************/ 00136 00137 int main() { 00138 tft.init(); 00139 touch.init(); 00140 while (1) { 00141 loop(); 00142 } 00143 } 00144
Generated on Wed Jul 13 2022 18:27:26 by 1.7.2