mirror of
https://github.com/Bodmer/TFT_eSPI.git
synced 2025-08-06 14:14:44 +02:00
Add touch pressure hysterisis and user defined sensitivity
getTouch accepts a third optional pressure threshold, default is 600, increasing means harder presses are needed. getTouch(uint16_t *x, uint16_t *y, uint16_t threshold = 600);
This commit is contained in:
26
TFT_eSPI.cpp
26
TFT_eSPI.cpp
@@ -4114,10 +4114,22 @@ uint8_t TFT_eSPI::validTouch(uint16_t *x, uint16_t *y, uint16_t threshold){
|
||||
** Description: read callibrated position. Return false if not pressed.
|
||||
***************************************************************************************/
|
||||
#define Z_THRESHOLD 350 // Touch pressure threshold for validating touches
|
||||
uint8_t TFT_eSPI::getTouch(uint16_t *x, uint16_t *y){
|
||||
uint8_t TFT_eSPI::getTouch(uint16_t *x, uint16_t *y, uint16_t threshold){
|
||||
uint16_t x_tmp, y_tmp, xx, yy;
|
||||
|
||||
if(!validTouch(&x_tmp, &y_tmp, Z_THRESHOLD)) return false;
|
||||
if (threshold<20) threshold = 20;
|
||||
if (_pressTime > millis()) threshold=20;
|
||||
|
||||
byte n = 5;
|
||||
byte valid = 0;
|
||||
while (n--)
|
||||
{
|
||||
if (validTouch(&x_tmp, &y_tmp, threshold)) valid++;;
|
||||
}
|
||||
|
||||
if (valid<1) { _pressTime = 0; return false; }
|
||||
|
||||
_pressTime = millis() + 50;
|
||||
|
||||
if(!touchCalibration_rotate){
|
||||
xx=(x_tmp-touchCalibration_x0)*_width/touchCalibration_x1;
|
||||
@@ -4135,11 +4147,13 @@ uint8_t TFT_eSPI::getTouch(uint16_t *x, uint16_t *y){
|
||||
yy = _height - yy;
|
||||
}
|
||||
|
||||
if (xx >= _width || yy >= _height) return false;
|
||||
if (xx >= _width || yy >= _height) return valid;
|
||||
|
||||
*x = xx;
|
||||
*y = yy;
|
||||
return true;
|
||||
_pressX = xx;
|
||||
_pressY = yy;
|
||||
*x = _pressX;
|
||||
*y = _pressY;
|
||||
return valid;
|
||||
}
|
||||
|
||||
/***************************************************************************************
|
||||
|
@@ -458,7 +458,7 @@ class TFT_eSPI : public Print {
|
||||
// These are associated with the Touch Screen handlers
|
||||
uint8_t getTouchRaw(uint16_t *x, uint16_t *y);
|
||||
uint16_t getTouchRawZ(void);
|
||||
uint8_t getTouch(uint16_t *x, uint16_t *y);
|
||||
uint8_t getTouch(uint16_t *x, uint16_t *y, uint16_t threshold = 600);
|
||||
|
||||
void calibrateTouch(uint16_t *data, uint32_t color_fg, uint32_t color_bg, uint8_t size);
|
||||
void setTouch(uint16_t *data);
|
||||
@@ -488,6 +488,8 @@ class TFT_eSPI : public Print {
|
||||
// Initialise with example calibration values so processor does not crash if setTouch() not called in setup()
|
||||
uint16_t touchCalibration_x0 = 300, touchCalibration_x1 = 3600, touchCalibration_y0 = 300, touchCalibration_y1 = 3600;
|
||||
uint8_t touchCalibration_rotate = 1, touchCalibration_invert_x = 2, touchCalibration_invert_y = 0;
|
||||
uint32_t _pressTime;
|
||||
uint16_t _pressX, _pressY;
|
||||
|
||||
protected:
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "TFT_eSPI",
|
||||
"version": "0.17.19",
|
||||
"version": "0.17.20",
|
||||
"keywords": "TFT, ESP8266, NodeMCU, ESP32, ILI9341, ST7735, ILI9163, S6D02A1, ILI9486",
|
||||
"description": "A TFT SPI graphics library for ESP8266",
|
||||
"repository":
|
||||
|
@@ -1,5 +1,5 @@
|
||||
name=TFT_eSPI
|
||||
version=0.17.19
|
||||
version=0.17.20
|
||||
author=Bodmer
|
||||
maintainer=Bodmer
|
||||
sentence=A fast TFT library for ESP8266 processors and the Arduino IDE
|
||||
|
Reference in New Issue
Block a user