From b449186ababea2c9fe16c4caed7ca72695209eeb Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Tue, 15 Nov 2022 03:48:00 +0100 Subject: [PATCH] Add haspTouch.set_calibration() --- src/drv/touch/touch_driver.h | 2 ++ src/drv/touch/touch_driver_lovyangfx.h | 12 ++++++++++-- src/drv/touch/touch_driver_tftespi.h | 11 ++++++++--- src/hasp_gui.cpp | 24 +++++++++++++++++------- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/drv/touch/touch_driver.h b/src/drv/touch/touch_driver.h index 4f6b0e09..6a51047a 100644 --- a/src/drv/touch/touch_driver.h +++ b/src/drv/touch/touch_driver.h @@ -32,6 +32,8 @@ class BaseTouch { } void calibrate(uint16_t* calData) {} + void set_calibration(uint16_t* calData) + {} bool is_driver_pin(uint8_t) { return false; diff --git a/src/drv/touch/touch_driver_lovyangfx.h b/src/drv/touch/touch_driver_lovyangfx.h index 5c4d2bac..d5456ed3 100644 --- a/src/drv/touch/touch_driver_lovyangfx.h +++ b/src/drv/touch/touch_driver_lovyangfx.h @@ -53,8 +53,16 @@ class TouchLovyanGfx : public BaseTouch { #endif } + void set_calibration(uint16_t* calData) + { + if(haspTft.tft.panel() && haspTft.tft.width() && haspTft.tft.height()) { + haspTft.tft.setTouchCalibrate(calData); + } + } + void calibrate(uint16_t* calData) { + if(haspTft.tft.panel() && haspTft.tft.width() && haspTft.tft.height()) { haspTft.tft.fillScreen(TFT_BLACK); // haspTft.tft.setCursor(20, 0); @@ -67,8 +75,8 @@ class TouchLovyanGfx : public BaseTouch { // haspTft.tft.setTextFont(1); delay(500); haspTft.tft.calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15); - // haspTft.tft.setTouch(calData); - + set_calibration(calData); + } } }; diff --git a/src/drv/touch/touch_driver_tftespi.h b/src/drv/touch/touch_driver_tftespi.h index f9abcf37..cad72563 100644 --- a/src/drv/touch/touch_driver_tftespi.h +++ b/src/drv/touch/touch_driver_tftespi.h @@ -38,8 +38,8 @@ class TouchTftEspi : public BaseTouch { if(haspTft.tft.getTouch((uint16_t*)&data->point.x, (uint16_t*)&data->point.y, 300)) { if(hasp_sleep_state != HASP_SLEEP_OFF) hasp_update_sleep_state(); // update Idle data->state = LV_INDEV_STATE_PR; - hasp_set_sleep_offset(0); // Reset the offset - } else { + hasp_set_sleep_offset(0); // Reset the offset + } else { data->state = LV_INDEV_STATE_REL; } @@ -47,6 +47,11 @@ class TouchTftEspi : public BaseTouch { return false; } + void set_calibration(uint16_t* calData) + { + haspTft.tft.setTouch(calData); + } + void calibrate(uint16_t* calData) { haspTft.tft.fillScreen(TFT_BLACK); @@ -60,7 +65,7 @@ class TouchTftEspi : public BaseTouch { haspTft.tft.setTextFont(1); delay(500); haspTft.tft.calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15); - haspTft.tft.setTouch(calData); + set_calibration(calData); } }; diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index d072a8c0..204aef57 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -374,6 +374,7 @@ void guiSetup() #if !(defined(WINDOWS) || defined(POSIX)) // drv_touch_init(gui_settings.rotation); // Touch driver haspTouch.init(tft_width, tft_height); + haspTouch.set_calibration(gui_settings.cal_data); haspTouch.set_rotation(gui_settings.rotation); #endif @@ -461,9 +462,13 @@ bool guiGetConfig(const JsonObject& settings) changed = true; #if TOUCH_DRIVER == 0x2046 && defined(USER_SETUP_LOADED) && defined(TOUCH_CS) - // tft_espi_set_touch(gui_settings.cal_data); - haspTft.tft.setTouch(gui_settings.cal_data); + // haspTft.tft.setTouch(gui_settings.cal_data); + haspTouch.set_calibration(gui_settings.cal_data); +#elif TOUCH_DRIVER == 0x2046 && defined(HASP_USE_LGFX_TOUCH) + // haspTft.tft.setTouchCalibrate(gui_settings.cal_data); + haspTouch.set_calibration(gui_settings.cal_data); #endif + } i++; } @@ -477,10 +482,11 @@ bool guiGetConfig(const JsonObject& settings) changed = true; #if TOUCH_DRIVER == 0x2046 && defined(USER_SETUP_LOADED) && defined(TOUCH_CS) - // tft_espi_set_touch(gui_settings.cal_data); - haspTft.tft.setTouch(gui_settings.cal_data); + // haspTft.tft.setTouch(gui_settings.cal_data); + haspTouch.set_calibration(gui_settings.cal_data); #elif TOUCH_DRIVER == 0x2046 && defined(HASP_USE_LGFX_TOUCH) - haspTft.tft.setTouchCalibrate(gui_settings.cal_data); + // haspTft.tft.setTouchCalibrate(gui_settings.cal_data); + haspTouch.set_calibration(gui_settings.cal_data); #endif } @@ -553,9 +559,13 @@ bool guiSetConfig(const JsonObject& settings) } #if TOUCH_DRIVER == 0x2046 && defined(USER_SETUP_LOADED) && defined(TOUCH_CS) - if(status) // tft_espi_set_touch(gui_settings.cal_data); - haspTft.tft.setTouch(gui_settings.cal_data); + // haspTft.tft.setTouch(gui_settings.cal_data); + if(status) haspTouch.set_calibration(gui_settings.cal_data); +#elif TOUCH_DRIVER == 0x2046 && defined(HASP_USE_LGFX_TOUCH) + // haspTft.tft.setTouchCalibrate(gui_settings.cal_data); + if(status) haspTouch.set_calibration(gui_settings.cal_data); #endif + changed |= status; }