figments: command: rewrite command api to use Task instances instead of static functions
This commit is contained in:
@@ -256,17 +256,15 @@ Platform::restart() {
|
||||
}
|
||||
|
||||
|
||||
__attribute__((noreturn))
|
||||
void
|
||||
doReboot(Args& args, Print& out)
|
||||
Platform::doReboot(Args& args, Print& out)
|
||||
{
|
||||
out.println("Rebooting");
|
||||
Platform::restart();
|
||||
}
|
||||
|
||||
__attribute__((noreturn))
|
||||
void
|
||||
doSafeMode(Args& args, Print& out)
|
||||
Platform::doSafeMode(Args& args, Print& out)
|
||||
{
|
||||
out.println("Rebooting into safe mode");
|
||||
Platform::bootopts.forceSafeMode();
|
||||
@@ -276,21 +274,21 @@ doSafeMode(Args& args, Print& out)
|
||||
String s;
|
||||
|
||||
void
|
||||
doTaskStart(Args& args, Print& out)
|
||||
Platform::doTaskStart(Args& args, Print& out)
|
||||
{
|
||||
s = args[1];
|
||||
MainLoop::instance()->dispatch(InputEvent{InputEvent::StartThing, s.c_str()});
|
||||
}
|
||||
|
||||
void
|
||||
doTaskStop(Args& args, Print& out)
|
||||
Platform::doTaskStop(Args& args, Print& out)
|
||||
{
|
||||
s = args[1];
|
||||
MainLoop::instance()->dispatch(InputEvent{InputEvent::StopThing, s.c_str()});
|
||||
}
|
||||
|
||||
void
|
||||
doTaskList(Args& args, Print& out)
|
||||
Platform::doTaskList(Args& args, Print& out)
|
||||
{
|
||||
auto sched = MainLoop::instance()->scheduler;
|
||||
auto printer = Static<SerialInput>::instance()->printer();
|
||||
@@ -312,18 +310,16 @@ doTaskList(Args& args, Print& out)
|
||||
}
|
||||
|
||||
|
||||
|
||||
const std::vector<Command> _commands = {
|
||||
{"tasks", doTaskList},
|
||||
{"safe-mode", doSafeMode},
|
||||
{"reboot", doReboot},
|
||||
{"stop", doTaskStop},
|
||||
{"start", doTaskStart}
|
||||
};
|
||||
|
||||
const std::vector<Command>&
|
||||
Platform::commands() const
|
||||
{
|
||||
static const std::vector<Command> _commands = {
|
||||
{"tasks", &Platform::doTaskList},
|
||||
{"safe-mode", &Platform::doSafeMode},
|
||||
{"reboot", &Platform::doReboot},
|
||||
{"stop", &Platform::doTaskStop},
|
||||
{"start", &Platform::doTaskStart}
|
||||
};
|
||||
return _commands;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user