renderbug-cpp/src/inputs/Buttons.cpp

38 lines
1015 B
C++
Raw Normal View History

#include "./Buttons.h"
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);
m_buttons[i].attach(2 + i, INPUT_PULLDOWN);
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};
}
}
}
return InputEvent{};
}