mirror of
https://github.com/YuzuZensai/MCUFRIEND_kbv.git
synced 2026-01-31 14:57:48 +00:00
example uses local TouchScreen_kbv library
This commit is contained in:
@@ -15,13 +15,18 @@
|
|||||||
MCUFRIEND_kbv tft;
|
MCUFRIEND_kbv tft;
|
||||||
|
|
||||||
// MCUFRIEND UNO shield shares pins with the 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 = 6, YP = A1, XM = A2, YM = 7; //most common configuration
|
||||||
//int XP = 7, YP = A2, XM = A1, YM = 6; //most common configuration
|
//int XP = 7, YP = A2, XM = A1, YM = 6; //most common configuration
|
||||||
#include <TouchScreen.h> //Adafruit Library
|
#endif
|
||||||
TouchScreen ts(XP, YP, XM, YM, 300); //re-initialised after diagnose
|
//#include <TouchScreen.h> //Adafruit Library
|
||||||
//#include "TouchScreen_kbv.h" //my hacked version
|
//TouchScreen ts(XP, YP, XM, YM, 300); //re-initialised after diagnose
|
||||||
//TouchScreen_kbv ts(XP, YP, XM, YM, 300); //re-initialised after diagnose
|
//TSPoint tp; //global point
|
||||||
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 WHITE 0xFFFF
|
||||||
#define RED 0xF800
|
#define RED 0xF800
|
||||||
@@ -35,6 +40,7 @@ void readResistiveTouch(void)
|
|||||||
pinMode(XM, OUTPUT);
|
pinMode(XM, OUTPUT);
|
||||||
digitalWrite(YP, HIGH); //because TFT control pins
|
digitalWrite(YP, HIGH); //because TFT control pins
|
||||||
digitalWrite(XM, HIGH);
|
digitalWrite(XM, HIGH);
|
||||||
|
// Serial.println("tp.x=" + String(tp.x) + ", tp.y=" + String(tp.y) + ", tp.z =" + String(tp.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ISPRESSED(void)
|
bool ISPRESSED(void)
|
||||||
@@ -45,7 +51,7 @@ bool ISPRESSED(void)
|
|||||||
bool state, oldstate;
|
bool state, oldstate;
|
||||||
while (count < 10) {
|
while (count < 10) {
|
||||||
readResistiveTouch();
|
readResistiveTouch();
|
||||||
state = tp.z > 180 && tp.z < 1000;
|
state = tp.z > 20;
|
||||||
if (state == oldstate) count++;
|
if (state == oldstate) count++;
|
||||||
else count = 0;
|
else count = 0;
|
||||||
oldstate = state;
|
oldstate = state;
|
||||||
@@ -61,10 +67,22 @@ float px, py;
|
|||||||
int dispx, dispy, text_y_center, swapxy;
|
int dispx, dispy, text_y_center, swapxy;
|
||||||
uint32_t calx, caly, cals;
|
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)
|
void showpins(int A, int D, int value, const char *msg)
|
||||||
{
|
{
|
||||||
char buf[40];
|
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);
|
Serial.println(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,8 +125,8 @@ boolean diagnose_pins()
|
|||||||
(Values[i] < Values[!i]) ? "XM,XP: " : "YP,YM: ");
|
(Values[i] < Values[!i]) ? "XM,XP: " : "YP,YM: ");
|
||||||
}
|
}
|
||||||
XM = Apins[!idx]; XP = Dpins[!idx]; YP = Apins[idx]; YM = Dpins[idx];
|
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(XP, YP, XM, YM, 300); //re-initialise with pins
|
||||||
// ts = TouchScreen_kbv(XP, YP, XM, YM, 300); //re-initialise with pins
|
ts = TouchScreen_kbv(XP, YP, XM, YM, 300); //re-initialise with pins
|
||||||
return true; //success
|
return true; //success
|
||||||
}
|
}
|
||||||
Serial.println(F("BROKEN TOUCHSCREEN"));
|
Serial.println(F("BROKEN TOUCHSCREEN"));
|
||||||
@@ -120,8 +138,8 @@ void setup()
|
|||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
Serial.println(TITLE);
|
Serial.println(TITLE);
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
#if defined(__arm__)
|
#if defined(__arm__) || defined(ESP32)
|
||||||
Serial.println(F("Not possible to diagnose Touch pins on ARM"));
|
Serial.println(F("Not possible to diagnose Touch pins on ARM or ESP32"));
|
||||||
#else
|
#else
|
||||||
ret = diagnose_pins();
|
ret = diagnose_pins();
|
||||||
#endif
|
#endif
|
||||||
@@ -215,7 +233,7 @@ void readCoordinates()
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
readResistiveTouch();
|
readResistiveTouch();
|
||||||
if (tp.z > 20 && tp.z < 1000)
|
if (tp.z > 20)
|
||||||
{
|
{
|
||||||
tx += tp.x;
|
tx += tp.x;
|
||||||
ty += tp.y;
|
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);
|
sprintf(buf, "y = map(p.y, TOP=%d, BOT=%d, 0, %d)", TS_TOP, TS_BOT, TS_HT);
|
||||||
tft.println(buf);
|
tft.println(buf);
|
||||||
Serial.println(buf);
|
Serial.println(buf);
|
||||||
sprintf(buf, "Touch Pin Wiring XP=%d XM=A%d YP=A%d YM=%d",
|
sprintf(buf, "Touch Pin Wiring XP=%d XM=%s YP=%s YM=%d",
|
||||||
XP, XM - A0, YP - A0, YM);
|
XP, Aval(XM), Aval(YP), YM);
|
||||||
tft.println("");
|
tft.println("");
|
||||||
tft.println(buf);
|
tft.println(buf);
|
||||||
Serial.println(buf);
|
Serial.println(buf);
|
||||||
|
|||||||
@@ -7,27 +7,27 @@
|
|||||||
#include "TouchScreen_kbv.h"
|
#include "TouchScreen_kbv.h"
|
||||||
|
|
||||||
#define NUMSAMPLES 3 //.kbv
|
#define NUMSAMPLES 3 //.kbv
|
||||||
#if defined(__STM32F1__) //Maple core
|
#if defined(__STM32F1__) || defined(ESP32) //Maple core
|
||||||
#define ADC_ADJUST >>2
|
#define ADC_ADJUST >>2
|
||||||
#else
|
#else
|
||||||
#define ADC_ADJUST
|
#define ADC_ADJUST
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TSPoint::TSPoint(void) {
|
TSPoint_kbv::TSPoint_kbv(void) {
|
||||||
x = y = 0;
|
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;
|
x = x0;
|
||||||
y = y0;
|
y = y0;
|
||||||
z = z0;
|
z = z0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TSPoint::operator==(TSPoint p1) {
|
bool TSPoint_kbv::operator==(TSPoint_kbv p1) {
|
||||||
return ((p1.x == x) && (p1.y == y) && (p1.z == z));
|
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));
|
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 x, y, z;
|
||||||
int samples[NUMSAMPLES];
|
int samples[NUMSAMPLES];
|
||||||
uint8_t i, valid;
|
uint8_t i, valid;
|
||||||
@@ -104,7 +104,7 @@ TSPoint TouchScreen_kbv::getPoint(void) {
|
|||||||
|
|
||||||
z = (1023 - (z2 - z1));
|
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) {
|
TouchScreen_kbv::TouchScreen_kbv(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym) {
|
||||||
@@ -7,13 +7,13 @@
|
|||||||
#define _TOUCHSCREEN_KBV_H_
|
#define _TOUCHSCREEN_KBV_H_
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
class TSPoint {
|
class TSPoint_kbv {
|
||||||
public:
|
public:
|
||||||
TSPoint(void);
|
TSPoint_kbv(void);
|
||||||
TSPoint(int16_t x, int16_t y, int16_t z);
|
TSPoint_kbv(int16_t x, int16_t y, int16_t z);
|
||||||
|
|
||||||
bool operator==(TSPoint);
|
bool operator==(TSPoint_kbv);
|
||||||
bool operator!=(TSPoint);
|
bool operator!=(TSPoint_kbv);
|
||||||
|
|
||||||
int16_t x, y, z;
|
int16_t x, y, z;
|
||||||
};
|
};
|
||||||
@@ -27,7 +27,7 @@ class TouchScreen_kbv {
|
|||||||
uint16_t pressure(void);
|
uint16_t pressure(void);
|
||||||
int readTouchY();
|
int readTouchY();
|
||||||
int readTouchX();
|
int readTouchX();
|
||||||
TSPoint getPoint();
|
TSPoint_kbv getPoint();
|
||||||
int16_t pressureThreshhold;
|
int16_t pressureThreshhold;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user