-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSleep.cpp
93 lines (71 loc) · 1.85 KB
/
Sleep.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <Arduino.h>
#include "Sleep.h"
Sleep::Sleep() {
// Constructor
// when we were made
_now = 0;
_time = 0;
// 1st time
// time = 0, now = 0
// having run 4200 millis since boot
// time = 0 + 8000 + 4200 - 0
// after 8 sec sleep,
// millis = 4200 (does not increase on sleep)
// time == 12200
// wake now = 4200 (as we capture millis() on wake)
// 2nd time
// assume 1 second run time
// millis = 5200
// time = 12200 + 8000 + 5200 - 4200
// time = 21200
// time should be ... 12.2 secs + 1 sec + 8 secs = 21200 millis
// correct !!!
}
uint32_t Sleep::time(void){
// actual time is time + millis() - now
// first boot this should be just millis()
// after any sleep should be adjusted for sleep
return _time + millis() - _now;
}
void Sleep::kip8Secs(void) {
Serial.println("Sleep ... 8 secs");
// flush serials
Serial.flush();
Serial1.flush();
// set time before kipping
_time = _time + 8000 + millis() - _now;
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
// woke up and track millis now;
_now = millis();
// flush serials
Serial.flush();
Serial1.flush();
}
void Sleep::kip2Secs(void) {
Serial.println("Sleep ... 2 secs");
// flush serials
Serial.flush();
Serial1.flush();
// set time before kipping
_time = _time + 2000 + millis() - _now;
LowPower.powerDown(SLEEP_2S, ADC_OFF, BOD_OFF);
// woke up and track millis now;
_now = millis();
// flush serials
Serial.flush();
Serial1.flush();
}
void Sleep::kip1Sec(void) {
Serial.println("sleep ... 1sec");
// flush serials
Serial.flush();
Serial1.flush();
// set time before kipping
_time = _time + 1000 + millis() - _now;
LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF);
// woke up and track millis now;
_now = millis();
// flush serials
Serial.flush();
Serial1.flush();
}