figments: command: rewrite command api to use Task instances instead of static functions

This commit is contained in:
Torrie Fischer
2023-12-20 09:13:23 +01:00
parent 214825c1d3
commit 6e138175be
14 changed files with 76 additions and 81 deletions

View File

@ -2,19 +2,19 @@
#include "../Static.h"
void
doBPM(Args& args, Print& out)
BPM::doSetBPM(Args& args, Print& out)
{
uint8_t newBPM(atoi(args[1].c_str()));
Static<BPM>::instance()->setBPM(newBPM);
setBPM(newBPM);
}
const std::vector<Command> _commands = {
{"bpm", doBPM}
};
const std::vector<Command>&
BPM::commands() const
{
static const std::vector<Command> _commands = {
{"bpm", &BPM::doSetBPM}
};
return _commands;
}

View File

@ -77,4 +77,6 @@ private:
uint16_t trash;
m_timings.take(trash);
}
void doSetBPM(Args& args, Print& print);
};

View File

@ -126,7 +126,7 @@ SerialInput::read()
}
void
doHelp(Args& args, Print& out)
SerialInput::doHelp(Args& args, Print& out)
{
out.println("Available commands:");
auto sched = MainLoop::instance()->scheduler;
@ -139,14 +139,13 @@ doHelp(Args& args, Print& out)
out.println();
}
const std::vector<Command> serialCommands = {
{"help", doHelp}
};
const std::vector<Command>&
SerialInput::commands() const
{
return serialCommands;
static const std::vector<Command> _commands = {
{"help", &SerialInput::doHelp}
};
return _commands;
}
void
@ -158,7 +157,7 @@ SerialInput::doCommand() {
for(auto task : sched.tasks) {
for(auto &command : task->commands()) {
if (cmdName == command.name) {
command.func(args, m_logPrinter);
command.invoke(task, args, m_logPrinter);
return;
}
}

View File

@ -59,4 +59,6 @@ private:
InputEvent parseNormal(char nextChar);
InputEvent parseEscape(char nextChar);
InputEvent parseCSI(char nextChar);
void doHelp(Args& args, Print& out);
};