mirror of
https://github.com/arendst/Tasmota.git
synced 2025-08-02 15:37:42 +00:00
parent
e5c38da52c
commit
fb4fe0fd55
@ -62,27 +62,23 @@
|
|||||||
#define HR1224 6 //Hours register 12 or 24 hour mode (24 hour mode==0)
|
#define HR1224 6 //Hours register 12 or 24 hour mode (24 hour mode==0)
|
||||||
#define CENTURY 7 //Century bit in Month register
|
#define CENTURY 7 //Century bit in Month register
|
||||||
#define DYDT 6 //Day/Date flag bit in alarm Day/Date registers
|
#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 ds3231ReadStatus = false;
|
||||||
boolean DS3231chipDetected;
|
boolean ds3231WriteStatus = false; //flag, we want to wriet/write to DS3231 onlu once
|
||||||
|
boolean DS3231chipDetected = false;
|
||||||
|
|
||||||
/*----------------------------------------------------------------------*
|
/*----------------------------------------------------------------------*
|
||||||
Detect the DS3231 Chip
|
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);
|
snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "DS3231", USE_RTC_ADDR);
|
||||||
AddLog(LOG_LEVEL_INFO);
|
DS3231chipDetected = true;
|
||||||
return true;
|
} else {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "%s *NOT* " D_FOUND_AT " 0x%x"), "DS3231", USE_RTC_ADDR);
|
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) {
|
if (i2c_flg) {
|
||||||
switch (function) {
|
switch (function) {
|
||||||
case FUNC_INIT:
|
case FUNC_INIT:
|
||||||
DS3231chipDetected = DS3231Detect();
|
DS3231Detect();
|
||||||
result = DS3231chipDetected;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FUNC_EVERY_SECOND:
|
case FUNC_EVERY_SECOND:
|
||||||
TIME_T tmpTime;
|
TIME_T tmpTime;
|
||||||
if (!ds3231ReadStatus && DS3231chipDetected && utc_time < 1451602800 ) { // We still did not sync with NTP (time not valid) , so, read time from DS3231
|
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 {
|
} else {
|
||||||
rules_flag.time_set = 1;
|
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
|
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"),
|
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
|
SetDS3231Time (utc_time); //update the DS3231 time
|
||||||
ds3231WriteStatus = true;
|
ds3231WriteStatus = true;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user