mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-07-21 14:09:12 -04:00
Support "repeat" when a direction button is held down (#1053)
* Support "repeat" when holding a direction button * Support "repeat" when a direction button is held * Support "repeat" when a direction button is held * Support "repeat" when a direction button is held * Formatting violation - removed a trailing space * Removed unneeded return() statement
This commit is contained in:
parent
c2314f4838
commit
67b5b57533
3 changed files with 47 additions and 0 deletions
|
@ -27,11 +27,28 @@
|
|||
bool Debounce::feed(const uint8_t bit) {
|
||||
history_ = (history_ << 1) | (bit & 1);
|
||||
|
||||
// "Repeat" handling - simulated button release
|
||||
if (repeat_ctr_) {
|
||||
// Make sure the button is still being held continuously
|
||||
if (history_ == 0xFF) {
|
||||
// Simulate button press every REPEAT_SUBSEQUENT_DELAY ticks
|
||||
if (--repeat_ctr_ == 0) {
|
||||
state_ = !state_;
|
||||
repeat_ctr_ = REPEAT_SUBSEQUENT_DELAY / 2;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// It's a real button release; stop simulating
|
||||
repeat_ctr_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (state_ == 0) {
|
||||
// Previous button state was 0 (released);
|
||||
// Has button been held for DEBOUNCE_COUNT ticks?
|
||||
if ((history_ & DEBOUNCE_MASK) == DEBOUNCE_MASK) {
|
||||
state_ = 1;
|
||||
held_time_ = 0;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
|
@ -41,6 +58,21 @@ bool Debounce::feed(const uint8_t bit) {
|
|||
state_ = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Repeat support is limited to the 4 directional buttons
|
||||
if (repeat_enabled_) {
|
||||
// Has button been held continuously for DEBOUNCE_REPEAT_DELAY?
|
||||
if (history_ == 0xFF) {
|
||||
if (++held_time_ == REPEAT_INITIAL_DELAY) {
|
||||
// Delay reached; trigger repeat code on NEXT tick
|
||||
repeat_ctr_ = 1;
|
||||
held_time_ = 0;
|
||||
}
|
||||
} else {
|
||||
// Button not continuously pressed; reset counter
|
||||
held_time_ = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue