inputs: buttons: split implementation into cpp
This commit is contained in:
parent
91183b5eed
commit
3b32d72d5e
23
firmware/inputs/Buttons.cpp
Normal file
23
firmware/inputs/Buttons.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "Particle.h"
|
||||
#include "./Buttons.h"
|
||||
|
||||
void
|
||||
Buttons::onStart()
|
||||
{
|
||||
for(int i = 0; i < 3; 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].fell()) {
|
||||
return InputEvent{m_buttonMap[i]};
|
||||
}
|
||||
}
|
||||
return InputEvent{};
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "../Figments/Input.h"
|
||||
|
||||
class Bounce {
|
||||
public:
|
||||
@ -43,6 +44,10 @@ public:
|
||||
return m_state == Confirmed;
|
||||
}
|
||||
|
||||
bool held() const {
|
||||
return m_state == Held;
|
||||
}
|
||||
|
||||
private:
|
||||
enum State {
|
||||
Ready,
|
||||
@ -59,22 +64,8 @@ private:
|
||||
|
||||
class Buttons: public InputSource {
|
||||
public:
|
||||
void onStart() override {
|
||||
for(int i = 0; i < 3; i++) {
|
||||
m_buttons[i].attach(2 + i, INPUT_PULLDOWN);
|
||||
m_buttons[i].interval(15);
|
||||
}
|
||||
}
|
||||
|
||||
InputEvent read() override {
|
||||
for(int i = 0; i < 3; i++) {
|
||||
m_buttons[i].update();
|
||||
if (m_buttons[i].fell()) {
|
||||
return InputEvent{m_buttonMap[i]};
|
||||
}
|
||||
}
|
||||
return InputEvent{};
|
||||
}
|
||||
void onStart() override;
|
||||
InputEvent read() override;
|
||||
|
||||
private:
|
||||
Bounce m_buttons[3];
|
||||
|
Loading…
Reference in New Issue
Block a user