inputs: bpm: add commands for setting BPM
This commit is contained in:
parent
9c53d05ab1
commit
5ea43bc908
@ -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);
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user