Add long press repeat interval.

This commit is contained in:
whywilson 2025-07-25 17:00:05 +08:00
parent 2fcb08a20a
commit af91b78721
2 changed files with 10 additions and 3 deletions

View File

@ -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
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
}
}

View File

@ -50,7 +50,9 @@ class TrackballInterruptBase : public Observable<const InputEvent *>, public con
// Long press detection for press button
uint32_t pressStartTime = 0;
bool pressDetected = false;
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;