From 6279cf8ff53fe3c3be574902617ae973838e04ba Mon Sep 17 00:00:00 2001 From: peteGSX Date: Thu, 2 Jan 2025 10:54:17 +1000 Subject: [PATCH] Add force calibration --- InputInterface.cpp | 2 ++ InputInterface.h | 5 +++++ InputManager.cpp | 3 +++ TFT_eSPITouch.cpp | 3 +++ Version.h | 4 +++- myConfig.example.h | 5 +++++ 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/InputInterface.cpp b/InputInterface.cpp index 12371a7..bb07fc3 100644 --- a/InputInterface.cpp +++ b/InputInterface.cpp @@ -37,6 +37,8 @@ void InputInterface::setDebounceDelay(unsigned long delay) { _debounceDelay = de void InputInterface::setHoldThreshold(unsigned long threshold) { _holdThreshold = threshold; } +void InputInterface::forceCalibration() { _forceCalibration = true; } + InputAction InputInterface::_debounceOrHeld(InputAction currentAction) { // Record the current time for comparisons unsigned long currentTime = millis(); diff --git a/InputInterface.h b/InputInterface.h index 71eedde..45e6772 100644 --- a/InputInterface.h +++ b/InputInterface.h @@ -63,6 +63,9 @@ class InputInterface { /// @param threshold Threshold in milliseconds (default 500ms) void setHoldThreshold(unsigned long threshold); + /// @brief Force a touch screen into calibration mode, even if existing calibration is valid + void forceCalibration(); + /// @brief Destructor for an InputInterface virtual ~InputInterface() = default; @@ -89,6 +92,8 @@ class InputInterface { InputAction _lastAction = InputAction::PRESS_NONE; /// @brief Flag to help determining if input is held bool _isHolding = false; + /// @brief Flag to force calibration for touch screens if it's required + bool _forceCalibration = false; /// @brief Call this from the derived class' check() method to debounce and detect if the input is a hold vs. press /// @param currentAction The InputAction needing to be interpreted diff --git a/InputManager.cpp b/InputManager.cpp index e1ba2f6..5d09dc3 100644 --- a/InputManager.cpp +++ b/InputManager.cpp @@ -45,6 +45,9 @@ void InputManager::addInput(InputInterface *input) { #ifdef HOLD_THRESHOLD _input->setHoldThreshold(HOLD_THRESHOLD); #endif // HOLD_THRESHOLD +#ifdef FORCE_CALIBRATION + _input->forceCalibration(); +#endif // FORCE_CALIBRATION } InputInterface *InputManager::getInput() { return _input; } diff --git a/TFT_eSPITouch.cpp b/TFT_eSPITouch.cpp index ad9163c..3742146 100644 --- a/TFT_eSPITouch.cpp +++ b/TFT_eSPITouch.cpp @@ -101,6 +101,9 @@ TFT_eSPITouch *TFT_eSPITouch::create(int displayId) { } bool TFT_eSPITouch::_calibrated() { + if (_forceCalibration) { + return false; + } uint16_t calibrationData[5]; File file = SPIFFS.open(_calibrationFile, "r"); if (!file) { diff --git a/Version.h b/Version.h index 11c681a..2d330c9 100644 --- a/Version.h +++ b/Version.h @@ -2,8 +2,10 @@ #define VERSION_H // Numeric version here: major.minor.patch -#define VERSION "0.0.17" +#define VERSION "0.0.18" +// 0.0.18 includes: +// - Added ability to force touchscreen calibration if required // 0.0.17 includes: // - Improved experimental support for multiple TFT_eSPI instances // 0.0.16 includes: diff --git a/myConfig.example.h b/myConfig.example.h index c46bdbd..35ae249 100644 --- a/myConfig.example.h +++ b/myConfig.example.h @@ -46,3 +46,8 @@ * @brief Option to change how long the EX-Display version is displayed, in milliseconds. */ // #define STARTUP_INFO_DELAY 3000 // default is 3 seconds/3000ms - Increase/decrease if desired + +/** + * @brief Option to force a touch screen to enter calibration mode even if the current calibration is valid + */ +// #define FORCE_CALIBRATION