acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

Touch_Controller_Demo.ino (1503B)

      1 #include "FS.h"
      2 #include <SPI.h>
      3 #include <TFT_eSPI.h>
      4 TFT_eSPI tft = TFT_eSPI();
      5 
      6 #define CALIBRATION_FILE "/calibrationData"
      7 
      8 void setup(void) {
      9   uint16_t calibrationData[5];
     10   uint8_t calDataOK = 0;
     11 
     12   Serial.begin(115200);
     13   Serial.println("starting");
     14 
     15   tft.init();
     16 
     17   tft.setRotation(3);
     18   tft.fillScreen((0xFFFF));
     19 
     20   tft.setCursor(20, 0, 2);
     21   tft.setTextColor(TFT_BLACK, TFT_WHITE);  tft.setTextSize(1);
     22   tft.println("calibration run");
     23 
     24   // check file system
     25   if (!SPIFFS.begin()) {
     26     Serial.println("formating file system");
     27 
     28     SPIFFS.format();
     29     SPIFFS.begin();
     30   }
     31 
     32   // check if calibration file exists
     33   if (SPIFFS.exists(CALIBRATION_FILE)) {
     34     File f = SPIFFS.open(CALIBRATION_FILE, "r");
     35     if (f) {
     36       if (f.readBytes((char *)calibrationData, 14) == 14)
     37         calDataOK = 1;
     38       f.close();
     39     }
     40   }
     41   if (calDataOK) {
     42     // calibration data valid
     43     tft.setTouch(calibrationData);
     44   } else {
     45     // data not valid. recalibrate
     46     tft.calibrateTouch(calibrationData, TFT_WHITE, TFT_RED, 15);
     47     // store data
     48     File f = SPIFFS.open(CALIBRATION_FILE, "w");
     49     if (f) {
     50       f.write((const unsigned char *)calibrationData, 14);
     51       f.close();
     52     }
     53   }
     54 
     55   tft.fillScreen((0xFFFF));
     56 
     57 }
     58 
     59 void loop() {
     60   uint16_t x, y;
     61   static uint16_t color;
     62 
     63   if (tft.getTouch(&x, &y)) {
     64 
     65     tft.setCursor(5, 5, 2);
     66     tft.printf("x: %i     ", x);
     67     tft.setCursor(5, 20, 2);
     68     tft.printf("y: %i    ", y);
     69 
     70     tft.drawPixel(x, y, color);
     71     color += 155;
     72   }
     73 }
     74 
     75 
     76