From 91183b5eed62766926890a966a6bd64ec06540d0 Mon Sep 17 00:00:00 2001 From: Torrie Fischer Date: Tue, 28 Jan 2020 13:48:06 -0800 Subject: [PATCH] figments: input: support creating input handlers via lambdas --- firmware/Figments/Input.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/firmware/Figments/Input.h b/firmware/Figments/Input.h index fa94304..02c6bf8 100644 --- a/firmware/Figments/Input.h +++ b/firmware/Figments/Input.h @@ -81,6 +81,20 @@ public: virtual InputEvent read() = 0; }; +class InputFunc : public InputSource { +public: + InputFunc(std::function f) : InputSource(), m_func(f) {} + InputFunc(std::function f, const char* name) : InputSource(name), m_func(f) {} + InputFunc(std::function f, const char* name, Task::State initialState) : InputSource(name, initialState), m_func(f) {} + + InputEvent read() override { + return m_func(); + } + +private: + std::function m_func; +}; + class BufferedInputSource: public InputSource { public: BufferedInputSource() : InputSource() {}