-
Notifications
You must be signed in to change notification settings - Fork 1
/
LED.h
222 lines (189 loc) · 4.32 KB
/
LED.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/**
* @brief LED controller singleton for Seeed XIAO nRF52840 BLE (Sense)
* @file LED.h
* @author TANAHASHI, Jiro (aka jtFuruhata) <[email protected]>
* @version 1.2.0
* @date 2023-03-22
*
* @copyright Copyright (c) 2023 jtLab, Hokkaido Information University,
* Release under the MIT License.
* See LICENSE.
*/
#pragma once
#ifndef LED_H_INCLUDE
#define LED_H_INCLUDE
#include <Arduino.h> // Arduino core
/**
* @brief 8 colors LED class
*/
class LED {
public:
/**
* @brief LED color code (8 colors, old BRG style)
*/
typedef enum {
BLACK = 0,
BLUE = 1,
RED = 2,
MAGENTA = 3,
GREEN = 4,
CYAN = 5,
YELLOW = 6,
WHITE = 7
} COLOR;
/**
* @brief LED color mask
*/
typedef enum {
B = 0x01,
R = 0x02,
G = 0x04
} BRG;
private:
LED::COLOR color; // LED color code
static LED* instance; // singleton instance
/**
* @brief Construct a new LED singleton object
*/
LED();
/**
* @brief Write status to the LED
*/
void writeLED();
public:
/**
* @brief Get the singleton instance of LED
*
* @return LED* singleton instance
*/
static LED* getInstance();
/**
* @brief Set the color of the LED
*
* @param color specify the color to set
*/
void setColor(LED::COLOR color);
/**
* @brief Turn on the specified LED
*
* @param brg specify the LED to turn on
*/
void setLED(LED::BRG brg);
/**
* @brief Turn on the Red LED
*/
void setR();
/**
* @brief Turn on the Green LED
*/
void setG();
/**
* @brief Turn on the Blue LED
*/
void setB();
/**
* @brief Flash the LED
*
* @param color color to flash
* @param delayTime delay time between each flash
* @param times flash times
*/
void flashLED(LED::COLOR color, int delayTime=100, int times=1);
/**
* @brief Flash the specified LED
*
* @param delayTime delay time between each flash
* @param times flash times
*/
void flashLED(LED::BRG brg, int delayTime=100, int times=1);
/**
* @brief Flash the Red LED
*
* @param delayTime delay time between each flash
* @param times flash times
*/
void flashR(int delayTime=100, int times=1);
/**
* @brief Flash the Green LED
*
* @param delayTime delay time between each flash
* @param times flash times
*/
void flashG(int delayTime=100, int times=1);
/**
* @brief Flash the Blue LED
*
* @param delayTime delay time between each flash
* @param times flash times
*/
void flashB(int delayTime=100, int times=1);
/**
* @brief Turn off the specified LED
*
* @param brg specify the LED to turn off
*/
void resetLED(LED::BRG brg);
/**
* @brief Turn off the Red LED
*/
void resetR();
/**
* @brief Turn off the Green LED
*/
void resetG();
/**
* @brief Turn off the Blue LED
*/
void resetB();
/**
* @brief Flip the specified LED
*
* @param brg specify the LED to flip
*/
void flipLED(LED::BRG brg);
/**
* @brief Flip the Red LED
*/
void flipR();
/**
* @brief Flip the Green LED
*/
void flipG();
/**
* @brief Flip the Blue LED
*/
void flipB();
/**
* @brief Get the color of the LED
*
* @return LED::COLOR the color of the LED
*/
LED::COLOR getColor();
/**
* @brief Get the LEDs state
*
* @param brg specify the LED to get the state
* @return true if the specyfied LED is on, false if the specyfied LED is off
*/
bool getLED(LED::BRG brg);
/**
* @brief Get the Red LED state
*
* @return true if the Red LED is on, false if the Red LED is off
*/
bool getR();
/**
* @brief Get the Green LED state
*
* @return true if the Green LED is on, false if the Green LED is off
*/
bool getG();
/**
* @brief Get the Blue LED state
*
* @return true if the Blue LED is on, false if the Blue LED is off
*/
bool getB();
};
extern LED& led;
#endif // _LED_H_