-
Notifications
You must be signed in to change notification settings - Fork 9
/
statusled.cpp
56 lines (46 loc) · 1.17 KB
/
statusled.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
#include "statusled.h"
/**
* This is the singleton instance
*/
StatusLED* StatusLED::instance;
/**
* Constructor: start the ticker
*/
StatusLED::StatusLED() {
ticker.attach_ms(100, &StatusLED::tickCallback);
}
/**
* Change the GPS status
*/
void StatusLED::setStatus(byte state) {
if (state == gpsStatus) return;
#ifdef DEBUG
Serial.print("Setting status to ");
Serial.print(state);
Serial.print("\n");
#endif
gpsStatus = state;
pos = 0; // reset animation
}
/**
* Handle ticks
*/
void StatusLED::tick() {
if (!gpsStatus) {
// Display sweep animation whene there is no reception
analogWrite(CFG_LED_STATUS, inverted ? 1023 - animPulse[pos] : animPulse[pos]);
pos++;
if (pos >= sizeof(animPulse) / 2) pos = 0;
} else {
// Short pings when reception acquired
if (pos == 0) {
if (GPS::isNight()) {
analogWrite(CFG_LED_STATUS, inverted ? 123 : 900);
} else {
analogWrite(CFG_LED_STATUS, inverted ? 1023 : 1);
}
}
else analogWrite(CFG_LED_STATUS, inverted ? 0 : 1023);
if (++pos >= 150) pos = 0;
}
}