From d33163397d76c47f7ab97f2b6d376fc8ac6be65d Mon Sep 17 00:00:00 2001 From: prenticedavid Date: Mon, 18 Sep 2017 00:00:37 +0100 Subject: [PATCH] example uses local TouchScreen_kbv library --- .../TouchScreen_Calibr_native.ino | 50 +++++++++++++------ ...chScreen_kbv.cpp.h => TouchScreen_kbv.cpp} | 14 +++--- .../TouchScreen_kbv.h | 12 ++--- 3 files changed, 47 insertions(+), 29 deletions(-) rename examples/TouchScreen_Calibr_native/{TouchScreen_kbv.cpp.h => TouchScreen_kbv.cpp} (90%) diff --git a/examples/TouchScreen_Calibr_native/TouchScreen_Calibr_native.ino b/examples/TouchScreen_Calibr_native/TouchScreen_Calibr_native.ino index 3ced6ff..c906b97 100644 --- a/examples/TouchScreen_Calibr_native/TouchScreen_Calibr_native.ino +++ b/examples/TouchScreen_Calibr_native/TouchScreen_Calibr_native.ino @@ -15,13 +15,18 @@ MCUFRIEND_kbv tft; // MCUFRIEND UNO shield shares pins with the TFT. +#if defined(ESP32) +int XP = 27, YP = 4, XM = 15, YM = 14; //most common configuration +#else int XP = 6, YP = A1, XM = A2, YM = 7; //most common configuration //int XP = 7, YP = A2, XM = A1, YM = 6; //most common configuration -#include //Adafruit Library -TouchScreen ts(XP, YP, XM, YM, 300); //re-initialised after diagnose -//#include "TouchScreen_kbv.h" //my hacked version -//TouchScreen_kbv ts(XP, YP, XM, YM, 300); //re-initialised after diagnose -TSPoint tp; //global point +#endif +//#include //Adafruit Library +//TouchScreen ts(XP, YP, XM, YM, 300); //re-initialised after diagnose +//TSPoint tp; //global point +#include "TouchScreen_kbv.h" //my hacked version +TouchScreen_kbv ts(XP, YP, XM, YM, 300); //re-initialised after diagnose +TSPoint_kbv tp; //global point #define WHITE 0xFFFF #define RED 0xF800 @@ -33,8 +38,9 @@ void readResistiveTouch(void) tp = ts.getPoint(); pinMode(YP, OUTPUT); //restore shared pins pinMode(XM, OUTPUT); - digitalWrite(YP, HIGH); //because TFT control pins + digitalWrite(YP, HIGH); //because TFT control pins digitalWrite(XM, HIGH); + // Serial.println("tp.x=" + String(tp.x) + ", tp.y=" + String(tp.y) + ", tp.z =" + String(tp.z)); } bool ISPRESSED(void) @@ -45,7 +51,7 @@ bool ISPRESSED(void) bool state, oldstate; while (count < 10) { readResistiveTouch(); - state = tp.z > 180 && tp.z < 1000; + state = tp.z > 20; if (state == oldstate) count++; else count = 0; oldstate = state; @@ -61,10 +67,22 @@ float px, py; int dispx, dispy, text_y_center, swapxy; uint32_t calx, caly, cals; +char *Aval(int pin) +{ + static char buf[2][10], cnt; + cnt = !cnt; +#if defined(ESP32) + sprintf(buf[cnt], "%d", pin); +#else + sprintf(buf[cnt], "A%d", pin - A0); +#endif + return buf[cnt]; +} + void showpins(int A, int D, int value, const char *msg) { char buf[40]; - sprintf(buf, "%s (A%d, D%d) = %d", msg, A - A0, D, value); + sprintf(buf, "%s (%s, D%d) = %d", msg, Aval(A), D, value); Serial.println(buf); } @@ -107,8 +125,8 @@ boolean diagnose_pins() (Values[i] < Values[!i]) ? "XM,XP: " : "YP,YM: "); } XM = Apins[!idx]; XP = Dpins[!idx]; YP = Apins[idx]; YM = Dpins[idx]; - ts = TouchScreen(XP, YP, XM, YM, 300); //re-initialise with pins -// ts = TouchScreen_kbv(XP, YP, XM, YM, 300); //re-initialise with pins +// ts = TouchScreen(XP, YP, XM, YM, 300); //re-initialise with pins + ts = TouchScreen_kbv(XP, YP, XM, YM, 300); //re-initialise with pins return true; //success } Serial.println(F("BROKEN TOUCHSCREEN")); @@ -120,8 +138,8 @@ void setup() Serial.begin(9600); Serial.println(TITLE); bool ret = true; -#if defined(__arm__) - Serial.println(F("Not possible to diagnose Touch pins on ARM")); +#if defined(__arm__) || defined(ESP32) + Serial.println(F("Not possible to diagnose Touch pins on ARM or ESP32")); #else ret = diagnose_pins(); #endif @@ -215,7 +233,7 @@ void readCoordinates() do { readResistiveTouch(); - if (tp.z > 20 && tp.z < 1000) + if (tp.z > 20) { tx += tp.x; ty += tp.y; @@ -299,8 +317,8 @@ void report() sprintf(buf, "y = map(p.y, TOP=%d, BOT=%d, 0, %d)", TS_TOP, TS_BOT, TS_HT); tft.println(buf); Serial.println(buf); - sprintf(buf, "Touch Pin Wiring XP=%d XM=A%d YP=A%d YM=%d", - XP, XM - A0, YP - A0, YM); + sprintf(buf, "Touch Pin Wiring XP=%d XM=%s YP=%s YM=%d", + XP, Aval(XM), Aval(YP), YM); tft.println(""); tft.println(buf); Serial.println(buf); @@ -364,7 +382,7 @@ void startup() while (ISPRESSED() == false) {} while (ISPRESSED() == true) {} -// waitForTouch(); + // waitForTouch(); } void fail() diff --git a/examples/TouchScreen_Calibr_native/TouchScreen_kbv.cpp.h b/examples/TouchScreen_Calibr_native/TouchScreen_kbv.cpp similarity index 90% rename from examples/TouchScreen_Calibr_native/TouchScreen_kbv.cpp.h rename to examples/TouchScreen_Calibr_native/TouchScreen_kbv.cpp index 1686bca..938a027 100644 --- a/examples/TouchScreen_Calibr_native/TouchScreen_kbv.cpp.h +++ b/examples/TouchScreen_Calibr_native/TouchScreen_kbv.cpp @@ -7,27 +7,27 @@ #include "TouchScreen_kbv.h" #define NUMSAMPLES 3 //.kbv -#if defined(__STM32F1__) //Maple core +#if defined(__STM32F1__) || defined(ESP32) //Maple core #define ADC_ADJUST >>2 #else #define ADC_ADJUST #endif -TSPoint::TSPoint(void) { +TSPoint_kbv::TSPoint_kbv(void) { x = y = 0; } -TSPoint::TSPoint(int16_t x0, int16_t y0, int16_t z0) { +TSPoint_kbv::TSPoint_kbv(int16_t x0, int16_t y0, int16_t z0) { x = x0; y = y0; z = z0; } -bool TSPoint::operator==(TSPoint p1) { +bool TSPoint_kbv::operator==(TSPoint_kbv p1) { return ((p1.x == x) && (p1.y == y) && (p1.z == z)); } -bool TSPoint::operator!=(TSPoint p1) { +bool TSPoint_kbv::operator!=(TSPoint_kbv p1) { return ((p1.x != x) || (p1.y != y) || (p1.z != z)); } @@ -43,7 +43,7 @@ static void insert_sort(int array[], uint8_t size) { } } -TSPoint TouchScreen_kbv::getPoint(void) { +TSPoint_kbv TouchScreen_kbv::getPoint(void) { int x, y, z; int samples[NUMSAMPLES]; uint8_t i, valid; @@ -104,7 +104,7 @@ TSPoint TouchScreen_kbv::getPoint(void) { z = (1023 - (z2 - z1)); - return TSPoint(x, y, z); //XM, YP still in ANALOG mode + return TSPoint_kbv(x, y, z); //XM, YP still in ANALOG mode } TouchScreen_kbv::TouchScreen_kbv(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym) { diff --git a/examples/TouchScreen_Calibr_native/TouchScreen_kbv.h b/examples/TouchScreen_Calibr_native/TouchScreen_kbv.h index 4b21831..b94fc07 100644 --- a/examples/TouchScreen_Calibr_native/TouchScreen_kbv.h +++ b/examples/TouchScreen_Calibr_native/TouchScreen_kbv.h @@ -7,13 +7,13 @@ #define _TOUCHSCREEN_KBV_H_ #include -class TSPoint { +class TSPoint_kbv { public: - TSPoint(void); - TSPoint(int16_t x, int16_t y, int16_t z); + TSPoint_kbv(void); + TSPoint_kbv(int16_t x, int16_t y, int16_t z); - bool operator==(TSPoint); - bool operator!=(TSPoint); + bool operator==(TSPoint_kbv); + bool operator!=(TSPoint_kbv); int16_t x, y, z; }; @@ -27,7 +27,7 @@ class TouchScreen_kbv { uint16_t pressure(void); int readTouchY(); int readTouchX(); - TSPoint getPoint(); + TSPoint_kbv getPoint(); int16_t pressureThreshhold; private: