2020-01-28 21:48:46 +00:00
|
|
|
#include "./Buttons.h"
|
2021-03-31 18:50:00 +00:00
|
|
|
#include "../Static.h"
|
2020-01-28 21:48:46 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Buttons::onStart()
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 3; i++) {
|
2021-03-29 08:10:55 +00:00
|
|
|
//Log.info("Bound pin %d to button %d", 2 + i, i);
|
2021-03-31 18:50:00 +00:00
|
|
|
//m_buttons[i].attach(2 + i, INPUT_PULLDOWN);
|
|
|
|
m_buttons[i].attach(2 + i, INPUT_PULLUP);
|
2020-01-28 21:48:46 +00:00
|
|
|
m_buttons[i].interval(15);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InputEvent
|
|
|
|
Buttons::read()
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 3; i++) {
|
|
|
|
m_buttons[i].update();
|
2021-03-28 01:19:55 +00:00
|
|
|
if (m_buttons[i].rose()) {
|
|
|
|
//Log.info("Read press on %d", i);
|
|
|
|
int buttonID = m_buttonMap[i];
|
|
|
|
for(int j = 0; j < 3; j++ ) {
|
|
|
|
if (j != i && m_buttons[j].held()) {
|
|
|
|
buttonID |= m_buttonMap[j];
|
2021-03-29 08:10:55 +00:00
|
|
|
//Log.info("Chord with %d", j);
|
2021-03-28 01:19:55 +00:00
|
|
|
m_wasChord[j] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_wasChord[i]) {
|
|
|
|
//Log.info("Not emitting release from previous chord");
|
|
|
|
m_wasChord[i] = false;
|
|
|
|
} else {
|
|
|
|
return InputEvent{InputEvent::UserInput, buttonID};
|
|
|
|
}
|
2020-01-28 21:48:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return InputEvent{};
|
|
|
|
}
|
2021-03-31 18:50:00 +00:00
|
|
|
|
|
|
|
STATIC_ALLOC(Buttons);
|