Replies: 1 comment
-
AceButton itself does not support simultaneous button events. Keeping each button independent of each other allows the code to be more understandable and maintainable. However, I think you can build a custom subclass of The
The custom class ButtonHandler: public IEventHandler {
...
public:
explicit ButtonHandler(bool requireConcurrentTrigger = false)
: mRequireConcurrentTrigger(requireConcurrentTrigger)
{}
void handleEvent(AceButton* button, uint8_t eventType,
uint8_t /*buttonState*/) override {
...
}
void handleB1Pressed() {
Serial.println("B1 pressed");
}
void handleB2Pressed() {
Serial.println("B2 pressed");
}
void handleBothPressed() {
Serial.println("B1 and B2 BOTH pressed");
}
...
}; If you pass Finally, I want to draw attention to the edge case that I commented in the docstring for the /**
* Determine if both buttons are pressed at the same time.
*
* If mRequireConcurrentTrigger is true, then also check if the Pressed
* event of one button occurred within kConcurrentTriggerMillis of the other
* button. The mB{x}PressedMillis is a 16-bit integer which can rollover
* after 65536 milliseconds. So if the first button is held down for more
* than (65536 - 100 = 65435) milliseconds, it is possible for the 2nd
* button to trigger a concurrent press when pressed 65 seconds after the
* first. I can think of 2 possible fixes:
*
* 1) Enable kEventRepeatPress, and use one of those events to reset
* the mB{x}PressedMillis of the other button appropriately.
* 2) Use an external periodic task to reset the mB{x}PressedMillis
* every few seconds.
*/
bool areBothPressed() {
...
} The internal time stamps are Hope this helps... |
Beta Was this translation helpful? Give feedback.
-
Is it possible to detect simultaneous events? For example, assuming there is 3 buttons (A, B and C), is that possible or how would you detect that A and B are pressed together ?
Beta Was this translation helpful? Give feedback.
All reactions