rtctime.cpp: compiled time init option

This commit is contained in:
Verkehrsrot 2019-03-19 20:56:08 +01:00
parent 6c3641fa42
commit f8ba6e9e31

View File

@ -24,17 +24,17 @@ uint8_t rtc_init(void) {
Rtc.SetIsRunning(true); Rtc.SetIsRunning(true);
} }
// If you want to initialize a fresh RTC to compiled time, use this code #ifdef TIME_SYNC_COMPILEDATE
/* // initialize a blank RTC without battery backup with compiled time
RtcDateTime tt = Rtc.GetDateTime(); RtcDateTime tt = Rtc.GetDateTime();
time_t t = tt.Epoch32Time(); // sec2000 -> epoch time_t t = tt.Epoch32Time(); // sec2000 -> epoch
if (!Rtc.IsDateTimeValid() || !timeIsValid(t)) { if (!Rtc.IsDateTimeValid() || !timeIsValid(t)) {
ESP_LOGW(TAG, "RTC has no recent time, setting to compilation date"); ESP_LOGW(TAG, "RTC has no recent time, setting to compiled time");
Rtc.SetDateTime( Rtc.SetDateTime(
RtcDateTime(compiledUTC() - SECS_YR_2000)); // epoch -> sec2000 RtcDateTime(compiledUTC() - SECS_YR_2000)); // epoch -> sec2000
} }
*/ #endif
I2C_MUTEX_UNLOCK(); // release i2c bus access I2C_MUTEX_UNLOCK(); // release i2c bus access
ESP_LOGI(TAG, "RTC initialized"); ESP_LOGI(TAG, "RTC initialized");
@ -50,7 +50,7 @@ uint8_t set_rtctime(time_t t) { // t is UTC in seconds epoch time
if (I2C_MUTEX_LOCK()) { if (I2C_MUTEX_LOCK()) {
Rtc.SetDateTime(RtcDateTime(t - SECS_YR_2000)); // epoch -> sec2000 Rtc.SetDateTime(RtcDateTime(t - SECS_YR_2000)); // epoch -> sec2000
#ifdef RTC_INT // sync rtc 1Hz pulse on top of second #ifdef RTC_INT // sync rtc 1Hz pulse on top of second
Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone); // off Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone); // off
Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeClock); // start Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeClock); // start
#endif #endif
I2C_MUTEX_UNLOCK(); I2C_MUTEX_UNLOCK();