port to platformio
This commit is contained in:
37
src/inputs/Buttons.cpp
Normal file
37
src/inputs/Buttons.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#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{};
|
||||
}
|
Reference in New Issue
Block a user