-
Notifications
You must be signed in to change notification settings - Fork 9
/
statusled.h
74 lines (55 loc) · 1.76 KB
/
statusled.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
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
#ifndef H_STATUSLED
#define H_STATUSLED
#include "config.h"
#include <EventManager.h>
#include <Ticker.h>
#include "gps.h"
class StatusLED {
public:
static StatusLED* getInstance() {return StatusLED::instance;};
/**
* Register event handlers, and start timer
* @param EventManager the event manager used for events
*/
static void init(EventManager* eventManager, bool inverted) {
instance = new StatusLED();
instance->inverted = inverted;
eventManager->addListener(GPS_STATUS_CHANGED, &StatusLED::statusChangedCallback);
};
/**
* GPS Status has been changed
*/
static void statusChangedCallback(int eventCode, int eventParam) {getInstance()->setStatus(eventParam);};
/**
* Change the GPS status
*/
void setStatus(byte state);
/**
* Callback on timer ticks
*/
static void tickCallback() {getInstance()->tick();};
protected:
// Constructor
StatusLED();
// This is the singleton instance
static StatusLED* instance;
// Should we work in inverted mode?
bool inverted = false;
// Status of the gps
byte gpsStatus = -1;
// Timer used for event timing
Ticker ticker;
/**
* Handler timer ticks
*/
void tick();
/**
* Position in the animation
*/
word pos = 0;
/**
* Map for the pulse animation
*/
const uint16_t animPulse[25] = {1023, 980, 900, 800, 600, 400, 200, 0, 200, 400, 600, 800, 900, 1000, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023};
};
#endif