Browse Source

crash,lights: ensure that settings contain positive value

master
Maxim Prokhorov 5 years ago
parent
commit
01b76adff0
2 changed files with 16 additions and 8 deletions
  1. +1
    -1
      code/espurna/crash.ino
  2. +15
    -7
      code/espurna/light.ino

+ 1
- 1
code/espurna/crash.ino View File

@ -190,7 +190,7 @@ void crashSetup() {
// Minumum of 16 and align for column formatter in crashDump() // Minumum of 16 and align for column formatter in crashDump()
// Maximum of flash sector size minus reserved space at the beginning // Maximum of flash sector size minus reserved space at the beginning
const uint16_t trace_max = constrain( 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()) 0, (SPI_FLASH_SEC_SIZE - crashUsedSpace())
); );


+ 15
- 7
code/espurna/light.ino View File

@ -1172,6 +1172,10 @@ void _lightAPISetup() {
#if TERMINAL_SUPPORT #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() { void _lightInitCommands() {
terminalRegisterCommand(F("BRIGHTNESS"), [](Embedis* e) { terminalRegisterCommand(F("BRIGHTNESS"), [](Embedis* e) {
@ -1184,14 +1188,17 @@ void _lightInitCommands() {
}); });
terminalRegisterCommand(F("CHANNEL"), [](Embedis* e) { terminalRegisterCommand(F("CHANNEL"), [](Embedis* e) {
if (e->argc < 2) {
terminalError(F("CHANNEL <ID> [<VALUE>]"));
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<decltype(id)>(lightChannels())) {
for (unsigned char index = 0; index < lightChannels(); ++index) {
_lightChannelDebug(index);
}
return; return;
} }
@ -1200,7 +1207,8 @@ void _lightInitCommands() {
lightUpdate(true, true); lightUpdate(true, true);
} }
DEBUG_MSG_P(PSTR("Channel #%u (%s): %d\n"), id, lightDesc(id).c_str(), lightChannel(id));
_lightChannelDebug(id);
terminalOK(); terminalOK();
}); });


Loading…
Cancel
Save