From b2ec826cfbc6d360b7decdce07d7e97961b48f7d Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Mon, 12 Feb 2018 00:30:18 +0100 Subject: [PATCH] Fixed setAlarm(seconds) --- GpsTracker/Rtc.cpp | 16 +++++++++++++++- GpsTracker/Rtc.h | 7 +------ GpsTracker/Time2.cpp | 2 +- GpsTracker/Time2.h | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/GpsTracker/Rtc.cpp b/GpsTracker/Rtc.cpp index 4a066a6..ec38d68 100644 --- a/GpsTracker/Rtc.cpp +++ b/GpsTracker/Rtc.cpp @@ -47,13 +47,27 @@ namespace rtc { RTC.writeTime(); } + void setAlarm(uint16_t seconds) { + tmElements_t currentTime; + tmElements_t alarmTime; + + getTime(currentTime); + + breakTime(makeTimestamp(currentTime) + seconds, alarmTime); + + setAlarm(alarmTime); + } + void setAlarm(tmElements_t &time) { tmElements_t currentTime; + getTime(currentTime); Log.verbose(F("Current time : %d/%d/%d %d:%d:%d\n"), tmYearToCalendar(currentTime.Year), currentTime.Month, currentTime.Day, currentTime.Hour, currentTime.Minute, currentTime.Second); - Log.notice(F("Set alarm to : %d/%d/%d %d:%d:%d\n"), tmYearToCalendar(time.Year), time.Month, time.Day, time.Hour, time.Minute, time.Second); + details::writeTimeToRegisters(time); RTC.writeAlarm1(DS3231_ALM_DTHMS); + getTime(currentTime); + Log.notice(F("Set alarm to : %d/%d/%d %d:%d:%d\n"), tmYearToCalendar(time.Year), time.Month, time.Day, time.Hour, time.Minute, time.Second); RTC.control(DS3231_A1_FLAG, DS3231_OFF); //reset Alarm 1 flag RTC.control(DS3231_A1_INT_ENABLE, DS3231_ON); //Alarm 1 ON diff --git a/GpsTracker/Rtc.h b/GpsTracker/Rtc.h index 66539c6..bdf0032 100644 --- a/GpsTracker/Rtc.h +++ b/GpsTracker/Rtc.h @@ -17,11 +17,6 @@ namespace rtc { void getTime(tmElements_t &time); void setTime(tmElements_t &time); - inline void setAlarm(uint16_t seconds) { - tmElements_t time; - getTime(time); - setAlarm(makeTime(time) + seconds); - } - + void setAlarm(uint16_t seconds); void setAlarm(tmElements_t &time); } \ No newline at end of file diff --git a/GpsTracker/Time2.cpp b/GpsTracker/Time2.cpp index 0bdd1c3..2bee65c 100644 --- a/GpsTracker/Time2.cpp +++ b/GpsTracker/Time2.cpp @@ -95,7 +95,7 @@ void breakTime(const timestamp_t timeInput, tmElements_t &tm) { } __attribute__((__optimize__("O2"))) -timestamp_t makeTime(const tmElements_t &tm) { +timestamp_t makeTimestamp(const tmElements_t &tm) { // assemble time elements into timestamp_t // note year argument is offset from 1970 (see macros in time.h to convert to other formats) // previous version used full four digit year (or digits since 2000),i.e. 2009 was 2009 or 9 diff --git a/GpsTracker/Time2.h b/GpsTracker/Time2.h index 5a545aa..b21a4e2 100644 --- a/GpsTracker/Time2.h +++ b/GpsTracker/Time2.h @@ -24,4 +24,4 @@ typedef struct { /* low level functions to convert to and from system time */ void breakTime(const timestamp_t time, tmElements_t &tm); // break timestamp_t into elements -timestamp_t makeTime(const tmElements_t &tm); // convert time elements into timestamp_t +timestamp_t makeTimestamp(const tmElements_t &tm); // convert time elements into timestamp_t