stefanbode / Sonoff-Tasmota

Provide ESP8266 based itead Sonoff with Web, MQTT and OTA firmware using Arduino IDE, enhanced with I2C options
GNU General Public License v3.0
128 stars 41 forks source link

DeepSleep value checking incorrect in "void CmndDeepSleep(void)" #176

Closed thomas-lentz closed 4 years ago

thomas-lentz commented 4 years ago

BUG DESCRIPTION

Can't set deepsleep to the following values: 0, 10 to 39, >1000 (after correcting issue #175)

REQUESTED INFORMATION

ADDITIONAL CONTEXT

The boundary check in "void CmndDeepSleep(void)" seems to be faulty (39<deepsleep<1001):

  if ((XdrvMailbox.payload > 39) && (XdrvMailbox.payload < 1001)) {
    Settings.deepsleep = XdrvMailbox.payload;
...

This fixes the problem:

//STB MOD

void CmndDeepSleep(void)
{
  if ((XdrvMailbox.payload == 0 ) || ((XdrvMailbox.payload >= 10) && (XdrvMailbox.payload <= 4294967295))) {
    Settings.deepsleep = XdrvMailbox.payload;
  }
  Response_P( PSTR("{\"" D_CMND_DEEPSLEEP "\":\"%d%s (%d%s)\"}"), Settings.deepsleep, (Settings.flag.value_units) ? " mS" : "", Settings.deepsleep, (Settings.flag.value_units) ? " mS" : "");
}
//end

It seems to be a copy&paste failure. The "faulty" boundary check seems to be copied from:

void CmndButtonDebounce(void)
{
  if ((XdrvMailbox.payload > 39) && (XdrvMailbox.payload < 1001)) {
    Settings.button_debounce = XdrvMailbox.payload;
  }
  Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.button_debounce);
}
stefanbode commented 4 years ago

agree!