From 01b76adff022e1b7449d46ae7a7153e495c8ece0 Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Thu, 17 Oct 2019 17:45:28 +0300 Subject: [PATCH] crash,lights: ensure that settings contain positive value --- code/espurna/crash.ino | 2 +- code/espurna/light.ino | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/code/espurna/crash.ino b/code/espurna/crash.ino index 9d43f15f..e047ef87 100644 --- a/code/espurna/crash.ino +++ b/code/espurna/crash.ino @@ -190,7 +190,7 @@ void crashSetup() { // Minumum of 16 and align for column formatter in crashDump() // Maximum of flash sector size minus reserved space at the beginning const uint16_t trace_max = constrain( - ((getSetting("sysTraceMax", SAVE_CRASH_STACK_TRACE_MAX).toInt() + 15) & -16), + abs((getSetting("sysTraceMax", SAVE_CRASH_STACK_TRACE_MAX).toInt() + 15) & -16), 0, (SPI_FLASH_SEC_SIZE - crashUsedSpace()) ); diff --git a/code/espurna/light.ino b/code/espurna/light.ino index e40bbc99..d1505eb1 100644 --- a/code/espurna/light.ino +++ b/code/espurna/light.ino @@ -1172,6 +1172,10 @@ void _lightAPISetup() { #if TERMINAL_SUPPORT +void _lightChannelDebug(unsigned char id) { + DEBUG_MSG_P(PSTR("Channel #%u (%s): %d\n"), id, lightDesc(id).c_str(), lightChannel(id)); +} + void _lightInitCommands() { terminalRegisterCommand(F("BRIGHTNESS"), [](Embedis* e) { @@ -1184,14 +1188,17 @@ void _lightInitCommands() { }); terminalRegisterCommand(F("CHANNEL"), [](Embedis* e) { - if (e->argc < 2) { - terminalError(F("CHANNEL []")); - return; + if (!lightChannels()) return; + + auto id = -1; + if (e->argc > 1) { + id = String(e->argv[1]).toInt(); } - const int id = String(e->argv[1]).toInt(); - if (id < 0 || id >= lightChannels()) { - terminalError(F("Channel value out of range")); + if (id < 0 || id >= static_cast(lightChannels())) { + for (unsigned char index = 0; index < lightChannels(); ++index) { + _lightChannelDebug(index); + } return; } @@ -1200,7 +1207,8 @@ void _lightInitCommands() { lightUpdate(true, true); } - DEBUG_MSG_P(PSTR("Channel #%u (%s): %d\n"), id, lightDesc(id).c_str(), lightChannel(id)); + _lightChannelDebug(id); + terminalOK(); });