@@ -32,5 +32,5 @@ void loop() { | |||||
positions::send(); | positions::send(); | ||||
} | } | ||||
mainunit::deepSleep(10); //duration TBD | |||||
mainunit::deepSleep(10); //TODO : duration | |||||
} | } |
@@ -73,6 +73,8 @@ namespace hardware { | |||||
uint8_t powered = 0; | uint8_t powered = 0; | ||||
void powerOn() { | void powerOn() { | ||||
if (powered > 0) return; | |||||
digitalWrite(I2C_PWR, HIGH); | digitalWrite(I2C_PWR, HIGH); | ||||
pinMode(I2C_PWR, OUTPUT); | pinMode(I2C_PWR, OUTPUT); | ||||
@@ -9,7 +9,9 @@ namespace mainunit { | |||||
} | } | ||||
void interruptIn(uint16_t seconds) { | void interruptIn(uint16_t seconds) { | ||||
rtc::powerOn(); | |||||
rtc::setAlarm(seconds); | rtc::setAlarm(seconds); | ||||
rtc::powerOff(); | |||||
pinMode(RTC_WAKE, INPUT); | pinMode(RTC_WAKE, INPUT); | ||||
attachInterrupt(digitalPinToInterrupt(RTC_WAKE), interrupt, FALLING); | attachInterrupt(digitalPinToInterrupt(RTC_WAKE), interrupt, FALLING); | ||||
@@ -38,7 +38,7 @@ | |||||
static const uint8_t monthDays[] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; // API starts months from 1, this array starts from 0 | static const uint8_t monthDays[] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; // API starts months from 1, this array starts from 0 | ||||
__attribute__((__optimize__("O2"))) | __attribute__((__optimize__("O2"))) | ||||
void breakTime(timestamp_t timeInput, tmElements_t &tm) { | |||||
void breakTime(const timestamp_t timeInput, tmElements_t &tm) { | |||||
// break the given timestamp_t into time components | // break the given timestamp_t into time components | ||||
// this is a more compact version of the C library localtime function | // this is a more compact version of the C library localtime function | ||||
// note that year is offset from 1970 !!! | // note that year is offset from 1970 !!! | ||||
@@ -95,7 +95,7 @@ void breakTime(timestamp_t timeInput, tmElements_t &tm) { | |||||
} | } | ||||
__attribute__((__optimize__("O2"))) | __attribute__((__optimize__("O2"))) | ||||
timestamp_t makeTime(tmElements_t &tm) { | |||||
timestamp_t makeTime(const tmElements_t &tm) { | |||||
// assemble time elements into timestamp_t | // assemble time elements into timestamp_t | ||||
// note year argument is offset from 1970 (see macros in time.h to convert to other formats) | // 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 | // previous version used full four digit year (or digits since 2000),i.e. 2009 was 2009 or 9 | ||||
@@ -23,5 +23,17 @@ | |||||
} tmElements_t, TimeElements, *tmElementsPtr_t; | } tmElements_t, TimeElements, *tmElementsPtr_t; | ||||
/* low level functions to convert to and from system time */ | /* low level functions to convert to and from system time */ | ||||
void breakTime(timestamp_t time, tmElements_t &tm); // break timestamp_t into elements | |||||
timestamp_t makeTime(tmElements_t &tm); // convert time elements into timestamp_t | |||||
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 | |||||
tmElements_t operator += (const timestamp_t b) { | |||||
} | |||||
tmElements_t operator + (const tmElements_t a, const timestamp_t b) { | |||||
tmElements_t result; | |||||
timestamp_t aTimestamp = makeTime(a); | |||||
breakTime(aTimestamp + b, result); | |||||
return result; | |||||
} |