From 3b32d72d5e84a7f1c6a42b5893cd412ad42c5dba Mon Sep 17 00:00:00 2001 From: Torrie Fischer Date: Tue, 28 Jan 2020 13:48:46 -0800 Subject: [PATCH] inputs: buttons: split implementation into cpp --- firmware/inputs/Buttons.cpp | 23 +++++++++++++++++++++++ firmware/inputs/Buttons.h | 23 +++++++---------------- 2 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 firmware/inputs/Buttons.cpp diff --git a/firmware/inputs/Buttons.cpp b/firmware/inputs/Buttons.cpp new file mode 100644 index 0000000..3632c55 --- /dev/null +++ b/firmware/inputs/Buttons.cpp @@ -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{}; +} diff --git a/firmware/inputs/Buttons.h b/firmware/inputs/Buttons.h index 7487469..399db2d 100644 --- a/firmware/inputs/Buttons.h +++ b/firmware/inputs/Buttons.h @@ -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];