-
Notifications
You must be signed in to change notification settings - Fork 0
/
VineAlert.h
102 lines (89 loc) · 2.31 KB
/
VineAlert.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef RETAILALERT_H
#define RETAILALERT_H
#include "Particle.h"
#include <vector>
constexpr uint16_t DEBOUNCE_TIME = 125; //milliseconds
template <class T> inline Print& operator <<(Print& obj, T arg)
{
obj.print(arg);
return obj;
}
namespace RetailAlert{
using functionPtr = void(*)(void);
class ButtonPressAction{
public:
ButtonPressAction(functionPtr action);
void bindToPin(uint8_t buttonPin);
static void update(void);
private:
uint8_t pin;
uint32_t lastPressMillis;
bool lastState;
functionPtr callback;
static std::vector<ButtonPressAction*>instances;
};
class IndicatorLED{
public:
IndicatorLED(uint8_t indicatorLed);
void begin(void);
void on(void);
void off(void);
void toggle(void);
private:
uint8_t pin;
bool state;
};
class ToggleSwitchAction{
public:
ToggleSwitchAction(functionPtr openAction, functionPtr closeAction) : onOpen(openAction), onClosed(closeAction){};
void bindToPin(uint8_t togglePin);
static void update(void);
private:
uint8_t pin;
uint32_t lastPressMillis;
functionPtr onOpen;
functionPtr onClosed;
enum SwitchState{
OPEN,
CLOSED,
UNKNOWN,
};
SwitchState lastState = UNKNOWN;
static std::vector<ToggleSwitchAction*>instances;
};
class Buzzer{
public:
Buzzer(uint8_t relayPin) : pin(relayPin){};
void begin();
void alarmOn(const char* deviceID);
void alarmOff(const char* deviceID);
void buzz(void);
private:
uint8_t pin;
std::vector<String> devices;
enum BuzzState{
BUZZER_OFF,
BUZZER_ON,
} state = BUZZER_OFF;
};
class MillisTimer{
public:
MillisTimer(uint32_t time, functionPtr action, bool repeat);
static void processTimers(void);
void start(void);
void start (bool repeat);
void stop(void);
void begin(void);
private:
enum TimerState{
STOPPED,
RUNNING,
}state = STOPPED;
functionPtr callback;
uint32_t delay;
uint32_t lastMillis = 0;
bool repeats;
static std::vector<MillisTimer*>timerArray;
};
};
#endif