renderbug-cpp/firmware/inputs/Buttons.cpp
2021-03-27 18:19:55 -07:00

39 lines
1.0 KiB
C++

#include "Particle.h"
#include "./Buttons.h"
void
Buttons::onStart()
{
for(int i = 0; i < 3; i++) {
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();
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];
Log.info("Chord with %d", j);
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{};
}