mirror of
https://github.com/xoseperez/espurna.git
synced 2026-03-22 16:17:06 +01:00
Terminal: change command-line parser (#2247)
Change the underlying command line handling: - switch to a custom parser, inspired by redis / sds - update terminalRegisterCommand signature, pass only bare minimum - clean-up `help` & `commands`. update settings `set`, `get` and `del` - allow our custom test suite to run command-line tests - clean-up Stream IO to allow us to print large things into debug stream (for example, `eeprom.dump`) - send parsing errors to the debug log As a proof of concept, introduce `TERMINAL_MQTT_SUPPORT` and `TERMINAL_WEB_API_SUPPORT` - MQTT subscribes to the `<root>/cmd/set` and sends response to the `<root>/cmd`. We can't output too much, as we don't have any large-send API. - Web API listens to the `/api/cmd?apikey=...&line=...` (or PUT, params inside the body). This one is intended as a possible replacement of the `API_SUPPORT`. Internals introduce a 'task' around the AsyncWebServerRequest object that will simulate what WiFiClient does and push data into it continuously, switching between CONT and SYS. Both are experimental. We only accept a single command and not every command is updated to use Print `ctx.output` object. We are also somewhat limited by the Print / Stream overall, perhaps I am overestimating the usefulness of Arduino compatibility to such an extent :) Web API handler can also sometimes show only part of the result, whenever the command tries to yield() by itself waiting for something. Perhaps we would need to create a custom request handler for that specific use-case.
This commit is contained in:
@@ -1035,21 +1035,21 @@ void _lightChannelDebug(unsigned char id) {
|
||||
|
||||
void _lightInitCommands() {
|
||||
|
||||
terminalRegisterCommand(F("BRIGHTNESS"), [](Embedis* e) {
|
||||
if (e->argc > 1) {
|
||||
_lightAdjustBrightness(e->argv[1]);
|
||||
terminalRegisterCommand(F("BRIGHTNESS"), [](const terminal::CommandContext& ctx) {
|
||||
if (ctx.argc > 1) {
|
||||
_lightAdjustBrightness(ctx.argv[1].c_str());
|
||||
lightUpdate(true, true);
|
||||
}
|
||||
DEBUG_MSG_P(PSTR("Brightness: %u\n"), lightBrightness());
|
||||
terminalOK();
|
||||
});
|
||||
|
||||
terminalRegisterCommand(F("CHANNEL"), [](Embedis* e) {
|
||||
terminalRegisterCommand(F("CHANNEL"), [](const terminal::CommandContext& ctx) {
|
||||
if (!lightChannels()) return;
|
||||
|
||||
auto id = -1;
|
||||
if (e->argc > 1) {
|
||||
id = String(e->argv[1]).toInt();
|
||||
if (ctx.argc > 1) {
|
||||
id = ctx.argv[1].toInt();
|
||||
}
|
||||
|
||||
if (id < 0 || id >= static_cast<decltype(id)>(lightChannels())) {
|
||||
@@ -1059,8 +1059,8 @@ void _lightInitCommands() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e->argc > 2) {
|
||||
_lightAdjustChannel(id, e->argv[2]);
|
||||
if (ctx.argc > 2) {
|
||||
_lightAdjustChannel(id, ctx.argv[2].c_str());
|
||||
lightUpdate(true, true);
|
||||
}
|
||||
|
||||
@@ -1069,27 +1069,27 @@ void _lightInitCommands() {
|
||||
terminalOK();
|
||||
});
|
||||
|
||||
terminalRegisterCommand(F("COLOR"), [](Embedis* e) {
|
||||
if (e->argc > 1) {
|
||||
lightColor(e->argv[1]);
|
||||
terminalRegisterCommand(F("COLOR"), [](const terminal::CommandContext& ctx) {
|
||||
if (ctx.argc > 1) {
|
||||
lightColor(ctx.argv[1].c_str());
|
||||
lightUpdate(true, true);
|
||||
}
|
||||
DEBUG_MSG_P(PSTR("Color: %s\n"), lightColor().c_str());
|
||||
terminalOK();
|
||||
});
|
||||
|
||||
terminalRegisterCommand(F("KELVIN"), [](Embedis* e) {
|
||||
if (e->argc > 1) {
|
||||
_lightAdjustKelvin(e->argv[1]);
|
||||
terminalRegisterCommand(F("KELVIN"), [](const terminal::CommandContext& ctx) {
|
||||
if (ctx.argc > 1) {
|
||||
_lightAdjustKelvin(ctx.argv[1].c_str());
|
||||
lightUpdate(true, true);
|
||||
}
|
||||
DEBUG_MSG_P(PSTR("Color: %s\n"), lightColor().c_str());
|
||||
terminalOK();
|
||||
});
|
||||
|
||||
terminalRegisterCommand(F("MIRED"), [](Embedis* e) {
|
||||
if (e->argc > 1) {
|
||||
_lightAdjustMireds(e->argv[1]);
|
||||
terminalRegisterCommand(F("MIRED"), [](const terminal::CommandContext& ctx) {
|
||||
if (ctx.argc > 1) {
|
||||
_lightAdjustMireds(ctx.argv[1].c_str());
|
||||
lightUpdate(true, true);
|
||||
}
|
||||
DEBUG_MSG_P(PSTR("Color: %s\n"), lightColor().c_str());
|
||||
|
||||
Reference in New Issue
Block a user