Skip to content

Commit

Permalink
Add force calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
peteGSX committed Jan 2, 2025
1 parent bf38ca0 commit 6279cf8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions InputInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions InputInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
3 changes: 3 additions & 0 deletions TFT_eSPITouch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions myConfig.example.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6279cf8

Please sign in to comment.