figments: command: rewrite command api to use Task instances instead of static functions
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
@ -77,4 +77,6 @@ private:
|
||||
uint16_t trash;
|
||||
m_timings.take(trash);
|
||||
}
|
||||
|
||||
void doSetBPM(Args& args, Print& print);
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -59,4 +59,6 @@ private:
|
||||
InputEvent parseNormal(char nextChar);
|
||||
InputEvent parseEscape(char nextChar);
|
||||
InputEvent parseCSI(char nextChar);
|
||||
|
||||
void doHelp(Args& args, Print& out);
|
||||
};
|
||||
|
Reference in New Issue
Block a user