Skip to content

Commit

Permalink
Fix timer data I/O errors
Browse files Browse the repository at this point in the history
5.13.1a
 * Fix several timer data input and output errors (#2597, #2620)
  • Loading branch information
arendst committed May 4, 2018
1 parent e6e1263 commit 5462057
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions sonoff/_releasenotes.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* 5.13.1a
* Change user_config.h otaurl to http://sonoff.maddox.co.uk/tasmota/sonoff.bin (#2588, #2602)
* Fix compile error when ADC is enabled and Rules are disabled (#2608)
* Fix several timer data input and output errors (#2597, #2620)
*
* 5.13.1 20180501
* Fix JSON buffers size too small for execution in some situations (#2580)
Expand Down
24 changes: 16 additions & 8 deletions sonoff/xdrv_09_timers.ino
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ void TimerEverySecond()
void PrepShowTimer(uint8_t index)
{
char days[8] = { 0 };
char sign[2] = { 0 };
char soutput[80];

Timer xtimer = Settings.timer[index -1];
Expand All @@ -318,10 +319,13 @@ void PrepShowTimer(uint8_t index)
#ifdef USE_SUNRISE
int16_t hour = xtimer.time / 60;
if ((1 == xtimer.mode) || (2 == xtimer.mode)) { // Sunrise or Sunset
if (hour > 11) { hour = (hour -12) * -1; }
if (hour > 11) {
hour -= 12;
sign[0] = '-';
}
}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"" D_CMND_TIMER "%d\":{\"" D_JSON_TIMER_ARM "\":%d,\"" D_JSON_TIMER_MODE "\":%d,\"" D_JSON_TIMER_TIME "\":\"%02d:%02d\",\"" D_JSON_TIMER_WINDOW "\":%d,\"" D_JSON_TIMER_DAYS "\":\"%s\",\"" D_JSON_TIMER_REPEAT "\":%d%s,\"" D_JSON_TIMER_ACTION "\":%d}"),
mqtt_data, index, xtimer.arm, xtimer.mode, hour, xtimer.time % 60, xtimer.window, days, xtimer.repeat, soutput, xtimer.power);
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"" D_CMND_TIMER "%d\":{\"" D_JSON_TIMER_ARM "\":%d,\"" D_JSON_TIMER_MODE "\":%d,\"" D_JSON_TIMER_TIME "\":\"%s%02d:%02d\",\"" D_JSON_TIMER_WINDOW "\":%d,\"" D_JSON_TIMER_DAYS "\":\"%s\",\"" D_JSON_TIMER_REPEAT "\":%d%s,\"" D_JSON_TIMER_ACTION "\":%d}"),
mqtt_data, index, xtimer.arm, xtimer.mode, sign, hour, xtimer.time % 60, xtimer.window, days, xtimer.repeat, soutput, xtimer.power);
#else
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"" D_CMND_TIMER "%d\":{\"" D_JSON_TIMER_ARM "\":%d,\"" D_JSON_TIMER_TIME "\":\"%02d:%02d\",\"" D_JSON_TIMER_WINDOW "\":%d,\"" D_JSON_TIMER_DAYS "\":\"%s\",\"" D_JSON_TIMER_REPEAT "\":%d%s,\"" D_JSON_TIMER_ACTION "\":%d}"),
mqtt_data, index, xtimer.arm, xtimer.time / 60, xtimer.time % 60, xtimer.window, days, xtimer.repeat, soutput, xtimer.power);
Expand Down Expand Up @@ -374,13 +378,18 @@ boolean TimerCommand()
if (root[UpperCase_P(parm_uc, PSTR(D_JSON_TIMER_TIME))].success()) {
uint16_t itime = 0;
int8_t value = 0;
uint8_t sign = 0;
char time_str[10];

snprintf(time_str, sizeof(time_str), root[parm_uc]);
const char *substr = strtok(time_str, ":");
if (substr != NULL) {
if (strchr(substr, '-')) {
sign = 1;
substr++;
}
value = atoi(substr);
if (value < 0) { value = abs(value) +12; } // Allow entering timer offset from -11:59 to -00:01 converted to 12:01 to 23:59
if (sign) { value += 12; } // Allow entering timer offset from -11:59 to -00:01 converted to 12:01 to 23:59
if (value > 23) { value = 23; }
itime = value * 60;
substr = strtok(NULL, ":");
Expand All @@ -401,14 +410,13 @@ boolean TimerCommand()
// SMTWTFS = 1234567 = 0011001 = 00TW00S = --TW--S
Settings.timer[index].days = 0;
const char *tday = root[parm_uc];
char ch = '.';

uint8_t i = 0;
char ch = *tday++;
while ((ch != '\0') && (i < 7)) {
ch = *tday++;
if (ch == '-') { ch = '0'; }
uint8_t mask = 1 << i++;
Settings.timer[index].days |= (ch == '0') ? 0 : mask;
ch = *tday++;
}
}
if (root[UpperCase_P(parm_uc, PSTR(D_JSON_TIMER_REPEAT))].success()) {
Expand All @@ -419,7 +427,7 @@ boolean TimerCommand()
Settings.timer[index].device = (device < devices_present) ? device : 0;
}
if (root[UpperCase_P(parm_uc, PSTR(D_JSON_TIMER_ACTION))].success()) {
uint8_t action = ((uint8_t)root[parm_uc] -1) & 0x03;
uint8_t action = (uint8_t)root[parm_uc] & 0x03;
Settings.timer[index].power = (devices_present) ? action : 3; // If no devices than only allow rules
}

Expand Down

0 comments on commit 5462057

Please sign in to comment.