diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index edd41da27..9c1c9d92b 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,6 +1,7 @@ /*********************************************************************************************\ * 6.6.0.4 20190806 * Add support for CHIRP soil moisture sensor by Christian Baars + * Add debug compile features using defines DEBUG_TASMOTA_DRIVER and DEBUG_TASMOTA_SENSOR. See example in xdrv_09_timers.ino * * 6.6.0.3 20190725 * Change filename of configuration backup from using FriendlyName1 to Hostname solving diacritic issues (#2422) diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 589068166..9a1fadb44 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -493,9 +493,11 @@ //#define USE_HRE // Add support for Badger HR-E Water Meter (+1k4 code) /*********************************************************************************************\ - * Debug features are only supported in development branch + * Debug features \*********************************************************************************************/ +//#define DEBUG_TASMOTA_DRIVER // Enable driver debug messages +//#define DEBUG_TASMOTA_SENSOR // Enable sensor debug messages //#define USE_DEBUG_DRIVER // Use xdrv_99_debug.ino providing commands CpuChk, CfgXor, CfgDump, CfgPeek and CfgPoke /*********************************************************************************************\ diff --git a/sonoff/sonoff_post.h b/sonoff/sonoff_post.h index 1a218311f..4eca7aafd 100644 --- a/sonoff/sonoff_post.h +++ b/sonoff/sonoff_post.h @@ -517,4 +517,16 @@ void KNX_CB_Action(message_t const &msg, void *arg); #undef USE_MQTT_TLS_CA_CERT #endif +#ifdef DEBUG_TASMOTA_DRIVER +#define DEBUG_DRIVER_LOG(...) AddLog_Debug(__VA_ARGS__) +#else +#define DEBUG_DRIVER_LOG(...) +#endif + +#ifdef DEBUG_TASMOTA_SENSOR +#define DEBUG_SENSOR_LOG(...) AddLog_Debug(__VA_ARGS__) +#else +#define DEBUG_SENSOR_LOG(...) +#endif + #endif // _SONOFF_POST_H_ diff --git a/sonoff/support.ino b/sonoff/support.ino index 1f263a466..9d7a5ef3b 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -1511,6 +1511,16 @@ void AddLog_P2(uint32_t loglevel, PGM_P formatP, ...) AddLog(loglevel); } +void AddLog_Debug(PGM_P formatP, ...) +{ + va_list arg; + va_start(arg, formatP); + vsnprintf_P(log_data, sizeof(log_data), formatP, arg); + va_end(arg); + + AddLog(LOG_LEVEL_DEBUG); +} + void AddLogBuffer(uint32_t loglevel, uint8_t *buffer, uint32_t count) { snprintf_P(log_data, sizeof(log_data), PSTR("DMP:")); diff --git a/sonoff/xdrv_09_timers.ino b/sonoff/xdrv_09_timers.ino index 193456df5..90a61c250 100644 --- a/sonoff/xdrv_09_timers.ino +++ b/sonoff/xdrv_09_timers.ino @@ -282,9 +282,14 @@ void TimerEverySecond(void) } #endif if (xtimer.arm) { - set_time += timer_window[i]; // Add random time offset - if (set_time < 0) { set_time = 0; } // Stay today; - if (set_time > 1439) { set_time = 1439; } + set_time += timer_window[i]; // Add random time offset + if (set_time < 0) { set_time = abs(timer_window[i]); } // After midnight and within negative window so stay today but allow positive randomness; + if (set_time > 1439) { set_time = 1439; } // Stay today + + if (0 == i) { + DEBUG_DRIVER_LOG(PSTR("TIM: Timer 1 XTimerTime %d, Window %d, SetTime %d"), xtimer.time, timer_window[i], set_time); + } + if (time == set_time) { if (xtimer.days & days) { Settings.timer[i].arm = xtimer.repeat;