mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2024-12-14 04:04:34 +00:00
Improve Select button response when Long Press is enabled during CPU-intensive apps (WFM) (#1304)
* Long press * Long-press improvement during CPU-intensive apps * Long-press improvement during CPU-intensive apps
This commit is contained in:
parent
3514a9a608
commit
ea238f4988
@ -23,6 +23,31 @@
|
|||||||
|
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
|
uint8_t Debounce::state() {
|
||||||
|
bool v = !pulse_upon_release_ && (state_ || simulated_pulse_);
|
||||||
|
if (simulated_pulse_)
|
||||||
|
simulated_pulse_ = false;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Debounce::enable_repeat() {
|
||||||
|
repeat_enabled_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Debounce::get_long_press_enabled() const {
|
||||||
|
return long_press_enabled_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Debounce::set_long_press_enabled(bool v) {
|
||||||
|
long_press_enabled_ = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Debounce::long_press_occurred() {
|
||||||
|
bool v = long_press_occurred_;
|
||||||
|
long_press_occurred_ = false;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
// Returns TRUE if button state changed (after debouncing)
|
// Returns TRUE if button state changed (after debouncing)
|
||||||
bool Debounce::feed(const uint8_t bit) {
|
bool Debounce::feed(const uint8_t bit) {
|
||||||
history_ = (history_ << 1) | (bit & 1);
|
history_ = (history_ << 1) | (bit & 1);
|
||||||
@ -63,11 +88,12 @@ bool Debounce::feed(const uint8_t bit) {
|
|||||||
// Has button been released for DEBOUNCE_COUNT ticks?
|
// Has button been released for DEBOUNCE_COUNT ticks?
|
||||||
if ((history_ & DEBOUNCE_MASK) == 0) {
|
if ((history_ & DEBOUNCE_MASK) == 0) {
|
||||||
// Button has been released when long_press_enabled_ and before LONG_PRESS_DELAY was reached;
|
// Button has been released when long_press_enabled_ and before LONG_PRESS_DELAY was reached;
|
||||||
// allow state() function to finally return a single press indication
|
// allow state() function to finally return a single press indication (simulated pulse).
|
||||||
// (in long press mode, apps won't see button press until the button is released)
|
// Note: In long press mode, apps won't see button press until the button is released.
|
||||||
if (pulse_upon_release_) {
|
if (pulse_upon_release_) {
|
||||||
// leaving state_==1 for one cycle
|
// force state() function (called by EventDispatcher) to return simulated press for one cycle
|
||||||
pulse_upon_release_ = 0;
|
simulated_pulse_ = true;
|
||||||
|
pulse_upon_release_ = false;
|
||||||
} else {
|
} else {
|
||||||
state_ = 0;
|
state_ = 0;
|
||||||
}
|
}
|
||||||
@ -87,7 +113,8 @@ bool Debounce::feed(const uint8_t bit) {
|
|||||||
// (note that repeat_support and long_press support are mutually exclusive)
|
// (note that repeat_support and long_press support are mutually exclusive)
|
||||||
if (held_time_ >= LONG_PRESS_DELAY) {
|
if (held_time_ >= LONG_PRESS_DELAY) {
|
||||||
long_press_occurred_ = true;
|
long_press_occurred_ = true;
|
||||||
pulse_upon_release_ = 0;
|
simulated_pulse_ = true;
|
||||||
|
pulse_upon_release_ = false;
|
||||||
held_time_ = 0;
|
held_time_ = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -36,38 +36,22 @@
|
|||||||
class Debounce {
|
class Debounce {
|
||||||
public:
|
public:
|
||||||
bool feed(const uint8_t bit);
|
bool feed(const uint8_t bit);
|
||||||
|
uint8_t state();
|
||||||
uint8_t state() const {
|
void enable_repeat();
|
||||||
return (pulse_upon_release_) ? 0 : state_;
|
bool get_long_press_enabled() const;
|
||||||
}
|
void set_long_press_enabled(bool v);
|
||||||
|
bool long_press_occurred();
|
||||||
void enable_repeat() {
|
|
||||||
repeat_enabled_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool get_long_press_enabled() const {
|
|
||||||
return long_press_enabled_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_long_press_enabled(bool v) {
|
|
||||||
long_press_enabled_ = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool long_press_occurred() {
|
|
||||||
bool v = long_press_occurred_;
|
|
||||||
long_press_occurred_ = false;
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t history_{0};
|
uint8_t history_{0};
|
||||||
uint8_t state_{0};
|
uint8_t state_{0};
|
||||||
bool repeat_enabled_{0};
|
bool repeat_enabled_{false};
|
||||||
uint16_t repeat_ctr_{0};
|
uint16_t repeat_ctr_{0};
|
||||||
uint16_t held_time_{0};
|
uint16_t held_time_{0};
|
||||||
bool pulse_upon_release_{0};
|
bool pulse_upon_release_{false};
|
||||||
bool long_press_enabled_{0};
|
bool simulated_pulse_{false};
|
||||||
bool long_press_occurred_{0};
|
bool long_press_enabled_{false};
|
||||||
|
bool long_press_occurred_{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*__DEBOUNCE_H__*/
|
#endif /*__DEBOUNCE_H__*/
|
||||||
|
@ -228,6 +228,7 @@ void controls_init() {
|
|||||||
switch_debounce[toUType(i)].enable_repeat();
|
switch_debounce[toUType(i)].enable_repeat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note: Called by event handler or apps, not in ISR, so some presses might be missed during high CPU utilization
|
||||||
SwitchesState get_switches_state() {
|
SwitchesState get_switches_state() {
|
||||||
SwitchesState result;
|
SwitchesState result;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user