PFW-1404 Only create button event when the button is released

pull/233/head
Guðni Már Gilbert 2022-10-27 22:53:26 +00:00
parent 0e625dc551
commit b750cc21f4
3 changed files with 6 additions and 3 deletions

View File

@ -38,6 +38,8 @@ public:
/// @param index of the button to check
inline bool ButtonPressed(uint8_t index) const { return buttons[index].Pressed(); }
inline bool ButtonReleased(uint8_t index) const { return buttons[index].Released(); }
/// @returns true if any of the button is pressed
inline bool AnyButtonPressed() const {
for (uint8_t i = 0; i < config::buttonCount; ++i) {

View File

@ -19,6 +19,7 @@ public:
/// @returns true if debounced value is currently considered as pressed
inline bool Pressed() const { return f.state == State::WaitForRelease; }
inline bool Released() const { return f.state == State::Update; }
/// State machine stepping routine
void Step(uint16_t time, bool press);

View File

@ -8,11 +8,11 @@ namespace user_input {
UserInput userInput;
void UserInput::Step() {
if (buttons::buttons.ButtonPressed(mb::Left))
if (buttons::buttons.ButtonReleased(mb::Left))
eventQueue.push(Event::Left);
if (buttons::buttons.ButtonPressed(mb::Middle))
if (buttons::buttons.ButtonReleased(mb::Middle))
eventQueue.push(Event::Middle);
if (buttons::buttons.ButtonPressed(mb::Right))
if (buttons::buttons.ButtonReleased(mb::Right))
eventQueue.push(Event::Right);
}