diff --git a/src/input/TrackballInterruptBase.cpp b/src/input/TrackballInterruptBase.cpp index e84e32705..c1424550f 100644 --- a/src/input/TrackballInterruptBase.cpp +++ b/src/input/TrackballInterruptBase.cpp @@ -73,12 +73,17 @@ int32_t TrackballInterruptBase::runOnce() // Reset state pressDetected = false; pressStartTime = 0; + lastLongPressEventTime = 0; this->action = TB_ACTION_NONE; } else if (pressDuration >= LONG_PRESS_DURATION) { // Long press detected - e.inputEvent = this->_eventPressedLong; + uint32_t currentTime = millis(); + // Only trigger long press event if enough time has passed since the last one + if (lastLongPressEventTime == 0 || (currentTime - lastLongPressEventTime) >= LONG_PRESS_REPEAT_INTERVAL) { + e.inputEvent = this->_eventPressedLong; + lastLongPressEventTime = currentTime; + } this->action = TB_ACTION_PRESSED_LONG; - // Keep pressDetected true to avoid repeated long press events } } diff --git a/src/input/TrackballInterruptBase.h b/src/input/TrackballInterruptBase.h index 30967fe7f..38be22f20 100644 --- a/src/input/TrackballInterruptBase.h +++ b/src/input/TrackballInterruptBase.h @@ -50,7 +50,9 @@ class TrackballInterruptBase : public Observable, public con // Long press detection for press button uint32_t pressStartTime = 0; bool pressDetected = false; - static const uint32_t LONG_PRESS_DURATION = 500; // ms + uint32_t lastLongPressEventTime = 0; + static const uint32_t LONG_PRESS_DURATION = 500; // ms + static const uint32_t LONG_PRESS_REPEAT_INTERVAL = 500; // ms - interval between repeated long press events private: input_broker_event _eventDown = INPUT_BROKER_NONE;