-
Notifications
You must be signed in to change notification settings - Fork 5
/
snoozer.h
30 lines (24 loc) · 878 Bytes
/
snoozer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <Snooze.h>
SnoozeDigital digital;
SnoozeBlock config(digital);
//------------------------------------------------------------------------
// start up snooze mode
// the power module has a tendency to cycle in snooze mode, tso this might exit early
// so we keep track of what state we atre in in NV ram so we can resume snoozing
void startSnooze(int address)
{
EEPROM.write(address, 0); // we are sleeping
Snooze.sleep( config ); // go to sleep
EEPROM.write(address, 1); // we woke up normally
}
// if we power up in snooze modce, go back to sleep
void waitSnooze(int address,int pin)
{
digital.pinMode(pin, INPUT_PULLUP, RISING);//pin, mode, type
byte sleepstate = EEPROM.read(address);
if (sleepstate == 0)
{
Snooze.sleep( config ); // go back to sleep
EEPROM.write(address, 1); // we woke up from a power snooze
}
}