|
@@ -7,6 +7,23 @@ |
|
|
|
|
|
|
|
|
namespace mainunit { |
|
|
namespace mainunit { |
|
|
|
|
|
|
|
|
|
|
|
namespace details { |
|
|
|
|
|
|
|
|
|
|
|
void prepareSleep() { |
|
|
|
|
|
hardware::sim808::simSerial.end(); //avoid woke up by SoftwareSerial interrupt |
|
|
|
|
|
delay(5); //ensure message have been printed out |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void wokeUp() { |
|
|
|
|
|
tmElements_t wokeUpTime; |
|
|
|
|
|
rtc::getTime(wokeUpTime); |
|
|
|
|
|
NOTICE_FORMAT("wokeUp", "%d:%d:%d", wokeUpTime.Hour, wokeUpTime.Minute, wokeUpTime.Second); |
|
|
|
|
|
|
|
|
|
|
|
hardware::sim808::simSerial.listen(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void interrupt() { |
|
|
void interrupt() { |
|
|
detachInterrupt(digitalPinToInterrupt(RTC_WAKE)); |
|
|
detachInterrupt(digitalPinToInterrupt(RTC_WAKE)); |
|
|
} |
|
|
} |
|
@@ -20,17 +37,17 @@ namespace mainunit { |
|
|
|
|
|
|
|
|
void sleep(period_t period) { |
|
|
void sleep(period_t period) { |
|
|
NOTICE_FORMAT("sleep", "Sleeping for period : %d", period); |
|
|
NOTICE_FORMAT("sleep", "Sleeping for period : %d", period); |
|
|
delay(5); |
|
|
|
|
|
|
|
|
details::prepareSleep(); |
|
|
LowPower.powerDown(period, ADC_OFF, BOD_OFF); |
|
|
LowPower.powerDown(period, ADC_OFF, BOD_OFF); |
|
|
NOTICE_MSG("sleep", "Woke up"); |
|
|
|
|
|
|
|
|
details::wokeUp(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void deepSleep(uint16_t seconds) { |
|
|
void deepSleep(uint16_t seconds) { |
|
|
NOTICE_FORMAT("deepSleep", "Deep sleeping for %d seconds", seconds); |
|
|
NOTICE_FORMAT("deepSleep", "Deep sleeping for %d seconds", seconds); |
|
|
interruptIn(seconds); |
|
|
interruptIn(seconds); |
|
|
delay(5); |
|
|
|
|
|
|
|
|
details::prepareSleep(); |
|
|
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); |
|
|
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); |
|
|
NOTICE_MSG("deepSleep", "Woke up"); |
|
|
|
|
|
|
|
|
details::wokeUp(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |