inputs: bpm: add commands for setting BPM

This commit is contained in:
Torrie Fischer 2023-12-11 07:58:33 +01:00
parent 9c53d05ab1
commit 5ea43bc908
2 changed files with 24 additions and 0 deletions

View File

@ -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<BPM>::instance()->setBPM(newBPM);
}
const std::vector<Command> _commands = {
{"bpm", doBPM}
};
const std::vector<Command>&
BPM::commands() const
{
return _commands;
}
STATIC_ALLOC(BPM);
STATIC_TASK(BPM);

View File

@ -18,6 +18,8 @@ public:
ConfigTaskMixin::handleEvent(evt);
}
const std::vector<Command>& 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();