diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 7338772bd..834ba3f40 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -100,9 +100,6 @@ typedef unsigned long power_t; // Power (Relay) type #define APP_BAUDRATE 115200 // Default serial baudrate #define MAX_STATUS 11 // Max number of status lines -#define XDRV_MAX 10 // Max number of allowed Xdrv drivers (Update xdrv_interface.ino if changed) -#define XSNS_MAX 20 // Max number of allowed Xsns External Sensors (Update xsns_interface.ino if changed) - /* // Removed from esp8266 core since 20171105 #define min(a,b) ((a)<(b)?(a):(b)) diff --git a/sonoff/support.ino b/sonoff/support.ino index d34cbefe6..b1196f7f1 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -1156,34 +1156,34 @@ uint32_t MakeTime(TIME_T &tm) uint32_t RuleToTime(TimeChangeRule r, int yr) { - TIME_T tm; - uint32_t t; - uint8_t m; - uint8_t w; // temp copies of r.month and r.week + TIME_T tm; + uint32_t t; + uint8_t m; + uint8_t w; // temp copies of r.month and r.week - m = r.month; - w = r.week; - if (0 == w) { // Last week = 0 - if (++m > 12) { // for "Last", go to the next month - m = 1; - yr++; - } - w = 1; // and treat as first week of next month, subtract 7 days later + m = r.month; + w = r.week; + if (0 == w) { // Last week = 0 + if (++m > 12) { // for "Last", go to the next month + m = 1; + yr++; } + w = 1; // and treat as first week of next month, subtract 7 days later + } - tm.hour = r.hour; - tm.minute = 0; - tm.second = 0; - tm.day_of_month = 1; - tm.month = m; - tm.year = yr - 1970; - t = MakeTime(tm); // First day of the month, or first day of next month for "Last" rules - BreakTime(t, tm); - t += (7 * (w - 1) + (r.dow - tm.day_of_week + 7) % 7) * SECS_PER_DAY; - if (0 == r.week) { - t -= 7 * SECS_PER_DAY; //back up a week if this is a "Last" rule - } - return t; + tm.hour = r.hour; + tm.minute = 0; + tm.second = 0; + tm.day_of_month = 1; + tm.month = m; + tm.year = yr - 1970; + t = MakeTime(tm); // First day of the month, or first day of next month for "Last" rules + BreakTime(t, tm); + t += (7 * (w - 1) + (r.dow - tm.day_of_week + 7) % 7) * SECS_PER_DAY; + if (0 == r.week) { + t -= 7 * SECS_PER_DAY; // back up a week if this is a "Last" rule + } + return t; } String GetTime(int type) @@ -1211,9 +1211,7 @@ uint32_t Midnight() boolean MidnightNow() { boolean mnflg = midnight_now; - if (mnflg) { - midnight_now = 0; - } + if (mnflg) midnight_now = 0; return mnflg; } @@ -1229,19 +1227,16 @@ void RtcSecond() ntp_time = sntp_get_current_timestamp(); if (ntp_time) { utc_time = ntp_time; + ntp_sync_minute = 60; // Sync so block further requests BreakTime(utc_time, tmpTime); RtcTime.year = tmpTime.year + 1970; daylight_saving_time = RuleToTime(DaylightSavingTime, RtcTime.year); standard_time = RuleToTime(StandardTime, RtcTime.year); - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION "(" D_UTC_TIME ") %s"), GetTime(0).c_str()); + snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION "(" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"), + GetTime(0).c_str(), GetTime(2).c_str(), GetTime(3).c_str()); AddLog(LOG_LEVEL_DEBUG); - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION "(" D_DST_TIME ") %s"), GetTime(2).c_str()); - AddLog(LOG_LEVEL_DEBUG); - snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION "(" D_STD_TIME ") %s"), GetTime(3).c_str()); - AddLog(LOG_LEVEL_DEBUG); - ntp_sync_minute = 60; // Sync so block further requests } else { - ntp_sync_minute++; // Try again in next minute + ntp_sync_minute++; // Try again in next minute } } utc_time++; diff --git a/sonoff/xdrv_interface.ino b/sonoff/xdrv_interface.ino index ba4547bdf..bf65ed4f1 100644 --- a/sonoff/xdrv_interface.ino +++ b/sonoff/xdrv_interface.ino @@ -57,6 +57,84 @@ boolean (* const xdrv_func_ptr[])(byte) PROGMEM = { // Driver Function Pointer #ifdef XDRV_10 &Xdrv10, #endif + +#ifdef XDRV_11 + &Xdrv11, +#endif + +#ifdef XDRV_12 + &Xdrv12, +#endif + +#ifdef XDRV_13 + &Xdrv13, +#endif + +#ifdef XDRV_14 + &Xdrv14, +#endif + +#ifdef XDRV_15 + &Xdrv15, +#endif + +#ifdef XDRV_16 + &Xdrv16, +#endif + +#ifdef XDRV_17 + &Xdrv17, +#endif + +#ifdef XDRV_18 + &Xdrv18, +#endif + +#ifdef XDRV_19 + &Xdrv19, +#endif + +#ifdef XDRV_20 + &Xdrv20, +#endif + +// Optional user defined drivers in range 91 - 99 + +#ifdef XDRV_91 + &Xdrv91, +#endif + +#ifdef XDRV_92 + &Xdrv92, +#endif + +#ifdef XDRV_93 + &Xdrv93, +#endif + +#ifdef XDRV_94 + &Xdrv94, +#endif + +#ifdef XDRV_95 + &Xdrv95, +#endif + +#ifdef XDRV_96 + &Xdrv96, +#endif + +#ifdef XDRV_97 + &Xdrv97, +#endif + +#ifdef XDRV_98 + &Xdrv98, +#endif + +#ifdef XDRV_99 + &Xdrv99 +#endif }; const uint8_t xdrv_present = sizeof(xdrv_func_ptr) / sizeof(xdrv_func_ptr[0]); // Number of drivers found diff --git a/sonoff/xsns_interface.ino b/sonoff/xsns_interface.ino index 633c6955c..02e380a95 100644 --- a/sonoff/xsns_interface.ino +++ b/sonoff/xsns_interface.ino @@ -97,6 +97,92 @@ boolean (* const xsns_func_ptr[])(byte) PROGMEM = { // Sensor Function Pointers #ifdef XSNS_20 &Xsns20, #endif + +#ifdef XSNS_21 + &Xsns21, +#endif + +#ifdef XSNS_22 + &Xsns22, +#endif + +#ifdef XSNS_23 + &Xsns23, +#endif + +#ifdef XSNS_24 + &Xsns24, +#endif + +#ifdef XSNS_25 + &Xsns25, +#endif + +#ifdef XSNS_26 + &Xsns26, +#endif + +#ifdef XSNS_27 + &Xsns27, +#endif + +#ifdef XSNS_28 + &Xsns28, +#endif + +#ifdef XSNS_29 + &Xsns29, +#endif + +#ifdef XSNS_30 + &Xsns30, +#endif + +#ifdef XSNS_31 + &Xsns31, +#endif + +#ifdef XSNS_32 + &Xsns32, +#endif + +// Optional user defined sensors in range 91 - 99 + +#ifdef XSNS_91 + &Xsns91, +#endif + +#ifdef XSNS_92 + &Xsns92, +#endif + +#ifdef XSNS_93 + &Xsns93, +#endif + +#ifdef XSNS_94 + &Xsns94, +#endif + +#ifdef XSNS_95 + &Xsns95, +#endif + +#ifdef XSNS_96 + &Xsns96, +#endif + +#ifdef XSNS_97 + &Xsns97, +#endif + +#ifdef XSNS_98 + &Xsns98, +#endif + +#ifdef XSNS_99 + &Xsns99 +#endif }; const uint8_t xsns_present = sizeof(xsns_func_ptr) / sizeof(xsns_func_ptr[0]); // Number of External Sensors found