diff --git a/sonoff/xsns_33_ds3231.ino b/sonoff/xsns_33_ds3231.ino index 48cb12553b07..d98f7163b529 100644 --- a/sonoff/xsns_33_ds3231.ino +++ b/sonoff/xsns_33_ds3231.ino @@ -62,27 +62,23 @@ #define HR1224 6 //Hours register 12 or 24 hour mode (24 hour mode==0) #define CENTURY 7 //Century bit in Month register #define DYDT 6 //Day/Date flag bit in alarm Day/Date registers -boolean ds3231ReadStatus = false , ds3231WriteStatus = false; //flag, we want to wriet/write to DS3231 onlu once -boolean DS3231chipDetected; - +boolean ds3231ReadStatus = false; +boolean ds3231WriteStatus = false; //flag, we want to wriet/write to DS3231 onlu once +boolean DS3231chipDetected = false; /*----------------------------------------------------------------------* Detect the DS3231 Chip ----------------------------------------------------------------------*/ -boolean DS3231Detect(void) +void DS3231Detect(void) { - if (I2cValidRead(USE_RTC_ADDR, RTC_STATUS, 1)) - { + DS3231chipDetected = false; + if (I2cValidRead(USE_RTC_ADDR, RTC_STATUS, 1)) { snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "DS3231", USE_RTC_ADDR); - AddLog(LOG_LEVEL_INFO); - return true; - } - else - { + DS3231chipDetected = true; + } else { snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "%s *NOT* " D_FOUND_AT " 0x%x"), "DS3231", USE_RTC_ADDR); - AddLog(LOG_LEVEL_INFO); - return false; } + AddLog(LOG_LEVEL_INFO); } /*----------------------------------------------------------------------* @@ -143,10 +139,8 @@ boolean Xsns33(byte function) if (i2c_flg) { switch (function) { case FUNC_INIT: - DS3231chipDetected = DS3231Detect(); - result = DS3231chipDetected; + DS3231Detect(); break; - case FUNC_EVERY_SECOND: TIME_T tmpTime; if (!ds3231ReadStatus && DS3231chipDetected && utc_time < 1451602800 ) { // We still did not sync with NTP (time not valid) , so, read time from DS3231 @@ -169,7 +163,6 @@ boolean Xsns33(byte function) } else { rules_flag.time_set = 1; } - result = true; } else if (!ds3231WriteStatus && DS3231chipDetected && utc_time > 1451602800 && abs(utc_time - ReadFromDS3231()) > 60) {//if time is valid and is drift from RTC in more that 60 second snprintf_P(log_data, sizeof(log_data), PSTR("Write Time TO DS3231 from NTP (" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"), @@ -178,9 +171,6 @@ boolean Xsns33(byte function) SetDS3231Time (utc_time); //update the DS3231 time ds3231WriteStatus = true; } - else { - result = false; - } break; } }