diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index 9ac9adeec..5f2f73c0b 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -238,6 +238,11 @@ const uint32_t LOOP_SLEEP_DELAY = 50; // Lowest number of milliseconds to #define KNX_MAX_device_param 31 #define MAX_KNXTX_CMNDS 5 +// XPT2046 resistive touch driver min/max raw values +#define XPT2046_MINX 192 +#define XPT2046_MAXX 3895 +#define XPT2046_MINY 346 +#define XPT2046_MAXY 3870 /*********************************************************************************************\ * Enumeration \*********************************************************************************************/ diff --git a/tasmota/xdrv_13_display.ino b/tasmota/xdrv_13_display.ino index 2a5b52feb..02c0e1d0f 100755 --- a/tasmota/xdrv_13_display.ino +++ b/tasmota/xdrv_13_display.ino @@ -2621,6 +2621,9 @@ bool XPT2046_found; bool Touch_Init(uint16_t CS) { touchp = new XPT2046_Touchscreen(CS); XPT2046_found = touchp->begin(); + if (XPT2046_found) { + AddLog(LOG_LEVEL_INFO, PSTR("TS: XPT2046")); + } return XPT2046_found; } @@ -2644,7 +2647,11 @@ uint32_t Touch_Status(uint32_t sel) { #ifdef USE_TOUCH_BUTTONS void Touch_MQTT(uint8_t index, const char *cp, uint32_t val) { +#if defined(USE_FT5206) ResponseTime_P(PSTR(",\"FT5206\":{\"%s%d\":\"%d\"}}"), cp, index+1, val); +#elif defined(USE_XPT2046) + ResponseTime_P(PSTR(",\"XPT2046\":{\"%s%d\":\"%d\"}}"), cp, index+1, val); +#endif MqttPublishTeleSensor(); } @@ -2696,7 +2703,7 @@ uint8_t vbutt=0; rotconvert(&pLoc.x, &pLoc.y); - //AddLog(LOG_LEVEL_INFO, PSTR("touch %d - %d"), pLoc.x, pLoc.y); + // AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("touch after convert %d - %d"), pLoc.x, pLoc.y); // now must compare with defined buttons for (uint8_t count = 0; count < MAX_TOUCH_BUTTONS; count++) { if (buttons[count]) { diff --git a/tasmota/xdsp_04_ili9341.ino b/tasmota/xdsp_04_ili9341.ino index e71de0b67..e8dc5e224 100644 --- a/tasmota/xdsp_04_ili9341.ino +++ b/tasmota/xdsp_04_ili9341.ino @@ -171,7 +171,8 @@ void ili9342_dimm(uint8_t dim) { #if defined(USE_FT5206) || defined(USE_XPT2046) #ifdef USE_TOUCH_BUTTONS -void ili9342_RotConvert(int16_t *x, int16_t *y) { +#if defined(USE_FT5206) +void TS_RotConvert(int16_t *x, int16_t *y) { int16_t temp; if (renderer) { @@ -196,6 +197,38 @@ int16_t temp; } } } +#elif defined(USE_XPT2046) +void TS_RotConvert(int16_t *x, int16_t *y) { + +int16_t temp; + if (renderer) { + uint8_t rot = renderer->getRotation(); +// AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(" TS: before convert x:%d / y:%d screen r:%d / w:%d / h:%d"), *x, *y,rot,renderer->width(),renderer->height()); + temp = map(*x,XPT2046_MINX,XPT2046_MAXX, renderer->height(), 0); + *x = map(*y,XPT2046_MINY,XPT2046_MAXY, renderer->width(), 0); + *y = temp; + switch (rot) { + case 0: + break; + case 1: + temp = *y; + *y = renderer->width() - *x; + *x = temp; + break; + case 2: + *x = renderer->width() - *x; + *y = renderer->height() - *y; + break; + case 3: + temp = *y; + *y = *x; + *x = renderer->height() - temp; + break; + } +// AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(" TS: after convert x:%d / y:%d screen r:%d / w:%d / h:%d"), *x, *y,rot,renderer->width(),renderer->height()); + } +} +#endif // check digitizer hit void ili9342_CheckTouch() { @@ -203,7 +236,8 @@ ili9342_ctouch_counter++; if (2 == ili9342_ctouch_counter) { // every 100 ms should be enough ili9342_ctouch_counter = 0; - Touch_Check(ili9342_RotConvert); + + Touch_Check(TS_RotConvert); } } #endif // USE_TOUCH_BUTTONS