diff --git a/GpsTracker/GpsTracker.ino b/GpsTracker/GpsTracker.ino index 58b26dc..9647e3e 100644 --- a/GpsTracker/GpsTracker.ino +++ b/GpsTracker/GpsTracker.ino @@ -32,5 +32,5 @@ void loop() { positions::send(); } - mainunit::deepSleep(10); //duration TBD + mainunit::deepSleep(10); //TODO : duration } diff --git a/GpsTracker/Hardware.cpp b/GpsTracker/Hardware.cpp index 11033ae..44e0f56 100644 --- a/GpsTracker/Hardware.cpp +++ b/GpsTracker/Hardware.cpp @@ -73,6 +73,8 @@ namespace hardware { uint8_t powered = 0; void powerOn() { + if (powered > 0) return; + digitalWrite(I2C_PWR, HIGH); pinMode(I2C_PWR, OUTPUT); diff --git a/GpsTracker/MainUnit.cpp b/GpsTracker/MainUnit.cpp index f2e1f82..da7e796 100644 --- a/GpsTracker/MainUnit.cpp +++ b/GpsTracker/MainUnit.cpp @@ -9,7 +9,9 @@ namespace mainunit { } void interruptIn(uint16_t seconds) { + rtc::powerOn(); rtc::setAlarm(seconds); + rtc::powerOff(); pinMode(RTC_WAKE, INPUT); attachInterrupt(digitalPinToInterrupt(RTC_WAKE), interrupt, FALLING); diff --git a/GpsTracker/Time2.cpp b/GpsTracker/Time2.cpp index 374a805..0bdd1c3 100644 --- a/GpsTracker/Time2.cpp +++ b/GpsTracker/Time2.cpp @@ -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 __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 // this is a more compact version of the C library localtime function // note that year is offset from 1970 !!! @@ -95,7 +95,7 @@ void breakTime(timestamp_t timeInput, tmElements_t &tm) { } __attribute__((__optimize__("O2"))) -timestamp_t makeTime(tmElements_t &tm) { +timestamp_t makeTime(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 d62535e..3afa0c8 100644 --- a/GpsTracker/Time2.h +++ b/GpsTracker/Time2.h @@ -23,5 +23,17 @@ } tmElements_t, TimeElements, *tmElementsPtr_t; /* 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; + }