-
Notifications
You must be signed in to change notification settings - Fork 0
/
RGBLed.h
272 lines (252 loc) · 5.58 KB
/
RGBLed.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#ifndef RGBLed_h
#define RGBLed_h
#include <Arduino.h>
#define DEFAULT_MAX_LED_NUMBER (32)
/*
#define RGB_RED 0xFF0000
#define RGB_GREEN 0x00FF00
#define RGB_BLUE 0x0000FF
#define RGB_YELLOW 0xFFFF00
#define RGB_PURPLE 0xFF00FF
#define RGB_WHITE 0xFFFFFF
#define RGB_OFF 0
*/
/// @brief Class for RGB Led Module
struct cRGB
{
uint8_t g;
uint8_t r;
uint8_t b;
};
/**
* Class: RGBLed
*
* \par Description
* Declaration of Class RGBLed
*/
class RGBLed
{
public:
/**
* Alternate Constructor which can call your own function to map the RGBLed to arduino port,
* it will assigned the LED display buffer and initialization the GPIO of LED lights. You can
* set any arduino digital pin for the LED data PIN, The default number of light strips is 32.
* \param[in]
* port - arduino port
*/
RGBLed(uint8_t port);
/**
* Alternate Constructor which can call your own function to map the RGBLed to arduino port,
* it will assigned the LED display buffer and initialization the GPIO of LED lights. You can
* set any slot for the LED data PIN, and reset the LED numberby this constructor.
* \param[in]
* port - arduino port
* \param[in]
* led_num - The LED number
*/
RGBLed(uint8_t port, uint8_t led_num);
/**
* Destructor which can call your own function, it will release the LED buffer
*/
~RGBLed(void);
/**
* \par Function
* setpin
* \par Description
* Reset the LED available data PIN by its arduino port.
* \param[in]
* port - arduino port(should digital pin)
* \par Output
* None
* \return
* None
* \par Others
* None
*/
void setpin(uint8_t port);
/**
* \par Function
* getNumber
* \par Description
* Get the LED number you can light it.
* \par Output
* None
* \return
* The total number of LED's
* \par Others
* The index value from 1 to the max
*/
uint8_t getNumber(void);
/**
* \par Function
* getColorAt
* \par Description
* Get the LED color value from its index
* \param[in]
* index - The LED index number you want to read its value
* \par Output
* None
* \return
* The LED color value, include the R,G,B
* \par Others
* The index value from 1 to the max
*/
cRGB getColorAt(uint8_t index);
/**
* \par Function
* fillPixelsBak
* \par Description
* fill the LED color data to pixels_bak.
* \param[in]
* red - Red values
* \param[in]
* green - green values
* \param[in]
* blue - blue values
* \par Output
* None
* \return
* None
* \par Others
* None
*/
void fillPixelsBak(uint8_t red, uint8_t green, uint8_t blue);
/**
* \par Function
* setColorAt
* \par Description
* Set the LED color for any LED.
* \param[in]
* index - The LED index number you want to set its color
* \param[in]
* red - Red values
* \param[in]
* green - green values
* \param[in]
* blue - blue values
* \par Output
* None
* \return
* TRUE: Successful implementation
* FALSE: Wrong execution
* \par Others
* The index value from 0 to the max.
*/
bool setColorAt(uint8_t index, uint8_t red, uint8_t green, uint8_t blue);
/**
* \par Function
* setColor
* \par Description
* Set the LED color for any LED.
* \param[in]
* index - The LED index number you want to set its color
* \param[in]
* red - Red values
* \param[in]
* green - green values
* \param[in]
* blue - blue values
* \par Output
* None
* \return
* TRUE: Successful implementation
* FALSE: Wrong execution
* \par Others
* The index value from 1 to the max, if you set the index 0, all the LED will be lit
*/
bool setColor(uint8_t index, uint8_t red, uint8_t green, uint8_t blue);
/**
* \par Function
* setColor
* \par Description
* Set the LED color for all LED.
* \param[in]
* red - Red values
* \param[in]
* green - green values
* \param[in]
* blue - blue values
* \par Output
* None
* \return
* TRUE: Successful implementation
* FALSE: Wrong execution
* \par Others
* All the LED will be lit.
*/
bool setColor(uint8_t red, uint8_t green, uint8_t blue);
/**
* \par Function
* setColor
* \par Description
* Set the LED color for any LED.
* \param[in]
* value - the LED color defined as long type, for example (white) = 0xFFFFFF
* \par Output
* None
* \return
* TRUE: Successful implementation
* FALSE: Wrong execution
* \par Others
* The index value from 1 to the max, if you set the index 0, all the LED will be lit
*/
bool setColor(uint8_t index, long value);
/**
* \par Function
* setNumber
* \par Description
* Assigned the LED display buffer by the LED number
* \param[in]
* num_leds - The LED number you used
* \par Output
* None
* \return
* None
* \par Others
* None
*/
void setNumber(uint8_t num_led);
/**
* \par Function
* show
* \par Description
* Transmission the data to WS2812
* \par Output
* None
* \return
* None
* \par Others
* None
*/
void show(void);
private:
uint16_t count_led;
uint8_t *pixels;
uint8_t *pixels_bak;
/**
* \par Function
* rgbled_sendarray_mask
* \par Description
* Set the LED color for any LED.
* \param[in]
* *data - the LED color store memory address
* \param[in]
* datlen - the data length need to be transmitted.
* \param[in]
* maskhi - the gpio pin mask
* \param[in]
* *port - the gpio port address
* \par Output
* None
* \return
* TRUE: Successful implementation
* FALSE: Wrong execution
* \par Others
* None
*/
void rgbled_sendarray_mask(uint8_t *array, uint16_t length, uint8_t pinmask, uint8_t *port);
const volatile uint8_t *ws2812_port;
volatile uint8_t *ws2812_port_reg;
uint8_t pinMask;
};
#endif