From 5ea43bc908144e5822e146d41e1fef5c6df9f27e Mon Sep 17 00:00:00 2001 From: Torrie Fischer Date: Mon, 11 Dec 2023 07:58:33 +0100 Subject: [PATCH] inputs: bpm: add commands for setting BPM --- src/inputs/BPM.cpp | 17 +++++++++++++++++ src/inputs/BPM.h | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/src/inputs/BPM.cpp b/src/inputs/BPM.cpp index c92ed1c..e11d2c8 100644 --- a/src/inputs/BPM.cpp +++ b/src/inputs/BPM.cpp @@ -1,5 +1,22 @@ #include "./BPM.h" #include "../Static.h" +void +doBPM(Args& args, Print& out) +{ + uint8_t newBPM(atoi(args[1].c_str())); + Static::instance()->setBPM(newBPM); +} + +const std::vector _commands = { + {"bpm", doBPM} +}; + +const std::vector& +BPM::commands() const +{ + return _commands; +} + STATIC_ALLOC(BPM); STATIC_TASK(BPM); diff --git a/src/inputs/BPM.h b/src/inputs/BPM.h index 464d4ec..e15b1c0 100644 --- a/src/inputs/BPM.h +++ b/src/inputs/BPM.h @@ -18,6 +18,8 @@ public: ConfigTaskMixin::handleEvent(evt); } + const std::vector& commands() const override; + void loop() { InputSource::loop(); ConfigTaskMixin::loop(); @@ -29,6 +31,11 @@ public: Log.notice("bpm: idle BPM set to %d (requested %d)", (int)msToBPM(m_msPerBeat), (int)requestedBPM); } + void setBPM(double bpm) { + m_msPerBeat = 60000.0 / (double)bpm; + Log.notice("bpm: Command changed to %d (requested %d)", (int)msToBPM(m_msPerBeat), (int)bpm); + } + InputEvent read() override { if (m_msPerBeat > 0) { uint16_t now = millis();