@@ -139,7 +139,7 @@ namespace core { | |||
tmElements_t time; | |||
rtc::getTime(time); | |||
currentTime = SLEEP_TIMING_TIME(time.Hour, time.Minute); | |||
currentTime = SLEEP_TIMING_TIME(time.hour, time.minute); | |||
} | |||
for (uint8_t i = flash::getArraySize(config::defaultSleepTimings); i--;) { | |||
@@ -197,7 +197,7 @@ namespace debug { | |||
tmElements_t time; | |||
rtc::getTime(time); | |||
NOTICE_FORMAT("getAndDisplayRtcTime", "%d/%d/%d %d:%d:%d %t %d", tmYearToCalendar(time.Year), time.Month, time.Day, time.Hour, time.Minute, time.Second, rtc::isAccurate(), rtc::getTemperature()); | |||
NOTICE_FORMAT("getAndDisplayRtcTime", "%d/%d/%d %d:%d:%d %t %d", tmYearToCalendar(time.year), time.month, time.day, time.hour, time.minute, time.second, rtc::isAccurate(), rtc::getTemperature()); | |||
} | |||
void setRtcTime() { | |||
@@ -105,13 +105,13 @@ namespace gps { | |||
VERBOSE_FORMAT("getTime", "%s", timeStr); | |||
time.Year = CalendarYrToTm(details::parseSubstring(buffer, timeStr + TIME_YEAR_OFFSET, 4)); | |||
time.Month = details::parseSubstring(buffer, timeStr + TIME_MONTH_OFFSET, 2); | |||
time.Day = details::parseSubstring(buffer, timeStr + TIME_DAY_OFFSET, 2); | |||
time.Hour = details::parseSubstring(buffer, timeStr + TIME_HOUR_OFFSET, 2); | |||
time.Minute = details::parseSubstring(buffer, timeStr + TIME_MINUTE_OFFSET, 2); | |||
time.Second = details::parseSubstring(buffer, timeStr + TIME_SECOND_OFFSET, 2); | |||
NOTICE_FORMAT("getTime", "%d/%d/%d %d:%d:%d", tmYearToCalendar(time.Year), time.Month, time.Day, time.Hour, time.Minute, time.Second); | |||
time.year = calendarYrToTm(details::parseSubstring(buffer, timeStr + TIME_YEAR_OFFSET, 4)); | |||
time.month = details::parseSubstring(buffer, timeStr + TIME_MONTH_OFFSET, 2); | |||
time.day = details::parseSubstring(buffer, timeStr + TIME_DAY_OFFSET, 2); | |||
time.hour = details::parseSubstring(buffer, timeStr + TIME_HOUR_OFFSET, 2); | |||
time.minute = details::parseSubstring(buffer, timeStr + TIME_MINUTE_OFFSET, 2); | |||
time.second = details::parseSubstring(buffer, timeStr + TIME_SECOND_OFFSET, 2); | |||
NOTICE_FORMAT("getTime", "%d/%d/%d %d:%d:%d", tmYearToCalendar(time.year), time.month, time.day, time.hour, time.minute, time.second); | |||
} | |||
} |
@@ -20,7 +20,7 @@ namespace mainunit { | |||
void wokeUp() { | |||
tmElements_t wokeUpTime; | |||
rtc::getTime(wokeUpTime); | |||
VERBOSE_FORMAT("wokeUp", "%d:%d:%d", wokeUpTime.Hour, wokeUpTime.Minute, wokeUpTime.Second); | |||
VERBOSE_FORMAT("wokeUp", "%d:%d:%d", wokeUpTime.hour, wokeUpTime.minute, wokeUpTime.second); | |||
hardware::sim808::simSerial.listen(); | |||
} | |||
@@ -48,11 +48,11 @@ namespace rtc { | |||
RTC_A.readTime(time); | |||
hardware::i2c::powerOff(); | |||
VERBOSE_FORMAT("getTime", "%d/%d/%d %d:%d:%d", tmYearToCalendar(time.Year), time.Month, time.Day, time.Hour, time.Minute, time.Second); | |||
VERBOSE_FORMAT("getTime", "%d/%d/%d %d:%d:%d", tmYearToCalendar(time.year), time.month, time.day, time.hour, time.minute, time.second); | |||
} | |||
void setTime(const tmElements_t &time) { | |||
VERBOSE_FORMAT("setTime", "%d/%d/%d %d:%d:%d", tmYearToCalendar(time.Year), time.Month, time.Day, time.Hour, time.Minute, time.Second); | |||
VERBOSE_FORMAT("setTime", "%d/%d/%d %d:%d:%d", tmYearToCalendar(time.year), time.month, time.day, time.hour, time.minute, time.second); | |||
hardware::i2c::powerOn(); | |||
RTC_A.writeTime(time); | |||
@@ -72,13 +72,13 @@ namespace rtc { | |||
void setAlarm(const tmElements_t &time) { | |||
hardware::i2c::powerOn(); | |||
RTC_A.writeAlarm1(DS3231_ALM_HMS, time); | |||
WRITE_ALARM_1(time); | |||
RTC_A.control(DS3231_A1_FLAG, DS3231_OFF); //reset Alarm 1 flag | |||
RTC_A.control(DS3231_A1_INT_ENABLE, DS3231_ON); //Alarm 1 ON | |||
RTC_A.control(DS3231_INT_ENABLE, DS3231_ON); //INTCN ON | |||
NOTICE_FORMAT("setAlarm", "Next alarm : %d:%d:%d", time.Hour, time.Minute, time.Second); | |||
NOTICE_FORMAT("setAlarm", "Next alarm : %d:%d:%d", time.hour, time.minute, time.second); | |||
hardware::i2c::powerOff(); | |||
} | |||
@@ -1,43 +1,49 @@ | |||
#include "RtcAbstraction.h" | |||
void uDS3231_Ext::unpack(tmElements_t &time) { | |||
time.Second = s; | |||
time.Minute = m; | |||
time.Hour = h; | |||
time.Day = dd; | |||
time.Month = mm; | |||
time.Year = yyyy; | |||
#ifndef USE_UDS3231 | |||
#ifdef STOCK_MD_DS3231 | |||
void MDS3231_Ext::unpack(tmElements_t &time) { | |||
time.second = s; | |||
time.minute = m; | |||
time.hour = h; | |||
time.day = dd; | |||
time.month = mm; | |||
time.year = yyyy; | |||
} | |||
void uDS3231_Ext::pack(const tmElements_t &time) { | |||
s = time.Second; | |||
m = time.Minute; | |||
h = time.Hour; | |||
dd = time.Day; | |||
mm = time.Month; | |||
yyyy = time.Year; | |||
void MDS3231_Ext::pack(const tmElements_t &time) { | |||
s = time.second; | |||
m = time.minute; | |||
h = time.hour; | |||
dd = time.day; | |||
mm = time.month; | |||
yyyy = time.year; | |||
} | |||
boolean uDS3231_Ext::readTime(tmElements_t &time) { | |||
boolean MDS3231_Ext::readTime(tmElements_t &time) { | |||
bool result = MD_DS3231::readTime(); | |||
unpack(time); | |||
return result; | |||
} | |||
boolean uDS3231_Ext::writeTime(const tmElements_t &time) { | |||
boolean MDS3231_Ext::writeTime(const tmElements_t &time) { | |||
pack(time); | |||
return MD_DS3231::writeTime(); | |||
} | |||
boolean uDS3231_Ext::readAlarm1(almType_t &almType, tmElements_t &time) { | |||
boolean MDS3231_Ext::readAlarm1(alm1Type_t &almType, tmElements_t &time) { | |||
almType = MD_DS3231::getAlarm1Type(); | |||
bool result = MD_DS3231::readAlarm1(); | |||
return result; | |||
} | |||
boolean uDS3231_Ext::writeAlarm1(almType_t almType, const tmElements_t &time) { | |||
boolean MDS3231_Ext::writeAlarm1(alm1Type_t almType, const tmElements_t &time) { | |||
pack(time); | |||
return MD_DS3231::writeAlarm1(almType); | |||
} | |||
} | |||
#endif | |||
#endif |
@@ -5,48 +5,49 @@ | |||
* When defined, use the modified uDS3231 library instead of | |||
* the stock MD_DS3231 one. | |||
*/ | |||
//#define USE_UDS3231 | |||
// #define USE_UDS3231 | |||
//#define STOCK_MD_DS3231 | |||
#ifdef USE_UDS3231 | |||
#include <uDS3231.h> | |||
#else | |||
#include <MD_DS3231.h> | |||
#endif | |||
#ifndef USE_UDS3231 | |||
//convenience macros to convert to and from tm years | |||
#define tmYearToCalendar(Y) ((Y) + 2000) // full four digit year | |||
#define CalendarYrToTm(Y) ((Y) - 2000) | |||
typedef unsigned long timestamp_t; | |||
typedef struct tmElements_t { | |||
uint8_t Second; | |||
uint8_t Minute; | |||
uint8_t Hour; | |||
uint8_t Day; | |||
uint8_t Month; | |||
uint8_t Year; // year from 2000 | |||
}; | |||
class uDS3231_Ext : public MD_DS3231 | |||
{ | |||
private: | |||
void unpack(tmElements_t &time) | |||
void pack(const tmElements_t &time); | |||
public: | |||
boolean readTime(tmElements_t &time); | |||
boolean writeTime(const tmElements_t &time); | |||
boolean readAlarm1(almType_t &almType, tmElements_t &time); | |||
boolean writeAlarm1(almType_t almType, const tmElements_t &time); | |||
}; | |||
#define RTC_A_CLASS uDS3231_Ext | |||
#include <uDS3231.h> | |||
#define RTC_A_CLASS uDS3231 | |||
#define WRITE_ALARM_1(t) RTC_A.writeAlarm1(DS3231_ALM_HMS, t) | |||
#else | |||
#define RTC_A_CLASS uDS3231 | |||
#endif | |||
#ifdef STOCK_MD_DS3231 | |||
#include <MD_DS3231.h> | |||
typedef unsigned long timestamp_t; | |||
typedef struct tmElements_t { | |||
uint8_t Second; | |||
uint8_t Minute; | |||
uint8_t Hour; | |||
uint8_t Day; | |||
uint8_t month; | |||
uint8_t year; // year from 2000 | |||
}; | |||
class MD_DS3231_Ext : public MD_DS3231 | |||
{ | |||
private: | |||
void unpack(tmElements_t &time); | |||
void pack(const tmElements_t &time); | |||
public: | |||
boolean readTime(tmElements_t &time); | |||
boolean writeTime(const tmElements_t &time); | |||
boolean readAlarm1(almType_t &almType, tmElements_t &time); | |||
boolean writeAlarm1(almType_t almType, const tmElements_t &time); | |||
}; | |||
#define RTC_A_CLASS MD_DS3231_Ext | |||
#define WRITE_ALARM_1(t) RTC_A.writeAlarm1(DS3231_ALM_HMS, t) | |||
#else | |||
#include <MD_DS3231.h> | |||
#define RTC_A_CLASS MD_DS3231 | |||
#define WRITE_ALARM_1(t) RTC_A.writeAlarm1(alm1Type_t::ALM_HMS, t) | |||
typedef unsigned long timestamp_t; | |||
#endif | |||
#endif |
@@ -1,47 +1,47 @@ | |||
#include "Time2.h" | |||
/*==============================================================================*/ | |||
/* Useful Constants */ | |||
#define SECS_PER_MIN (60UL) | |||
#define SECS_PER_HOUR (3600UL) | |||
#define SECS_PER_DAY (SECS_PER_HOUR * 24UL) | |||
#define DAYS_PER_WEEK (7UL) | |||
#define SECS_PER_WEEK (SECS_PER_DAY * DAYS_PER_WEEK) | |||
#define SECS_PER_YEAR (SECS_PER_WEEK * 52UL) | |||
#define SECS_YR_2000 (946684800UL) // the time at the start of y2k | |||
/*==============================================================================*/ | |||
/* Utility functions */ | |||
namespace utils { | |||
namespace time { | |||
__attribute__((__optimize__("O2"))) | |||
timestamp_t makeTimestamp(const tmElements_t &time) { | |||
timestamp_t timestamp; | |||
timestamp += (time.Day - 1) * SECS_PER_DAY; | |||
timestamp += time.Hour * SECS_PER_HOUR; | |||
timestamp += time.Minute * SECS_PER_MIN; | |||
timestamp += time.Second; | |||
return timestamp; | |||
} | |||
__attribute__((__optimize__("O2"))) | |||
void breakTime(timestamp_t timestamp, tmElements_t &time) { | |||
time.Year = 0; | |||
time.Month = 0; | |||
time.Day = 0; | |||
time.Second = timestamp % 60; | |||
timestamp /= 60; // now it is minutes | |||
time.Minute = timestamp % 60; | |||
timestamp /= 60; // now it is hours | |||
time.Hour = timestamp % 24; | |||
timestamp /= 24; // now it is days | |||
time.Day = timestamp; //this is purely for indication / computation only as it might get over the number of days in a month | |||
} | |||
} | |||
#include "Time2.h" | |||
/*==============================================================================*/ | |||
/* Useful Constants */ | |||
#define SECS_PER_MIN (60UL) | |||
#define SECS_PER_HOUR (3600UL) | |||
#define SECS_PER_DAY (SECS_PER_HOUR * 24UL) | |||
#define DAYS_PER_WEEK (7UL) | |||
#define SECS_PER_WEEK (SECS_PER_DAY * DAYS_PER_WEEK) | |||
#define SECS_PER_YEAR (SECS_PER_WEEK * 52UL) | |||
#define SECS_YR_2000 (946684800UL) // the time at the start of y2k | |||
/*==============================================================================*/ | |||
/* Utility functions */ | |||
namespace utils { | |||
namespace time { | |||
__attribute__((__optimize__("O2"))) | |||
timestamp_t makeTimestamp(const tmElements_t &time) { | |||
timestamp_t timestamp; | |||
timestamp += (time.day - 1) * SECS_PER_DAY; | |||
timestamp += time.hour * SECS_PER_HOUR; | |||
timestamp += time.minute * SECS_PER_MIN; | |||
timestamp += time.second; | |||
return timestamp; | |||
} | |||
__attribute__((__optimize__("O2"))) | |||
void breakTime(timestamp_t timestamp, tmElements_t &time) { | |||
time.year = 0; | |||
time.month = 0; | |||
time.day = 0; | |||
time.second = timestamp % 60; | |||
timestamp /= 60; // now it is minutes | |||
time.minute = timestamp % 60; | |||
timestamp /= 60; // now it is hours | |||
time.hour = timestamp % 24; | |||
timestamp /= 24; // now it is days | |||
time.day = timestamp; //this is purely for indication / computation only as it might get over the number of days in a month | |||
} | |||
} | |||
} |