-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoDrone_led.cpp
435 lines (358 loc) · 13.9 KB
/
CoDrone_led.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
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
#include "CoDrone.h"
#include "Arduino.h"
#include <EEPROM.h>
//-------------------------------------------------------------------------------------------------------//
//----------------------------------------- LED Event ---------------------------------------------------//
//-------------------------------------------------------------------------------------------------------//
void CoDroneClass::LedColorProcess(byte _dType, byte sendMode, byte r, byte g, byte b, byte sendInterval)
{
byte _packet[9];
byte _crc[2];
byte _len = 0;
if(_dType == dType_LedMode && _dType)
{
_len = 0x03;
g = sendInterval;
}
else if(_dType == dType_LedModeColor || _dType == dType_LedDefaultColor){
_len = 0x05;
}
//header
_packet[0] = _dType;
_packet[1] = _len;
//data
_packet[2] = sendMode;
_packet[3] = r;
_packet[4] = g;
_packet[5] = b;
_packet[6] = sendInterval;
unsigned short crcCal = CRC16_Make(_packet, _len+2);
_crc[0] = (crcCal >> 8) & 0xff;
_crc[1] = crcCal & 0xff;
Send_Processing(_packet,_len,_crc);
delay(100);
}
void CoDroneClass::LedColor2Process(byte _dType, byte sendMode1, byte r1, byte g1, byte b1, byte sendInterval1, byte sendMode2, byte r2, byte g2, byte b2, byte sendInterval2)
{
byte _packet[12];
byte _crc[2];
byte _len = 0;
if(_dType == dType_LedMode2){
g1 = sendInterval1;
b1 = sendMode2;
sendInterval1 = r2;
sendMode2 = sendInterval2;
_len=0x6;
}
else if(_dType == dType_LedModeColor2 || _dType == dType_LedDefaultColor2){
_len = 0xa;
}
//header
_packet[0] = _dType;
_packet[1] = _len;
//data
_packet[2] = sendMode1;
_packet[3] = r1;
_packet[4] = g1;
_packet[5] = b1;
_packet[6] = sendInterval1;
_packet[7] = sendMode2;
_packet[8] = r2;
_packet[9] = g2;
_packet[10] = b2;
_packet[11] = sendInterval2;
unsigned short crcCal = CRC16_Make(_packet, _packet[1]+2);
_crc[0] = (crcCal >> 8) & 0xff;
_crc[1] = crcCal & 0xff;
Send_Processing(_packet,_packet[1],_crc);
delay(100);
}
//-------------------------------------- LedColor -------------------------------------------------------//
void CoDroneClass::LedColor(byte sendMode, byte sendColor, byte sendInterval)
{
LedColorProcess(dType_LedMode, sendMode, sendColor, 0, 0, sendInterval);
}
void CoDroneClass::LedColor(byte sendMode, byte r, byte g, byte b, byte sendInterval)
{
LedColorProcess(dType_LedModeColor, sendMode, r, g, b,sendInterval);
}
void CoDroneClass::LedColor(byte sendMode, byte sendColor[], byte sendInterval)
{
LedColorProcess(dType_LedModeColor, sendMode, sendColor[0], sendColor[1], sendColor[2], sendInterval);
}
//----------------------------------- LedColorDefault ---------------------------------------------------//
void CoDroneClass::LedColorDefault(byte sendMode, byte r, byte g, byte b, byte sendInterval)
{
LedColorProcess(dType_LedDefaultColor, sendMode, r, g, b,sendInterval);
}
void CoDroneClass::LedColorDefault(byte sendMode, byte sendColor[], byte sendInterval)
{
LedColorProcess(dType_LedDefaultColor, sendMode, sendColor[0], sendColor[1], sendColor[2], sendInterval);
}
void CoDroneClass::LedColorDefault(byte sendMode, byte sendColor[], byte sendInterval, byte sendMode2, byte sendColor2[], byte sendInterval2)
{
byte _packet[12];
byte _crc[2];
//header
_packet[0] = dType_LedDefaultColor2;
_packet[1] = 10;
//data
_packet[2] = sendMode;
_packet[3] = sendColor[0];
_packet[4] = sendColor[1];
_packet[5] = sendColor[2];
_packet[6] = sendInterval;
_packet[7] = sendMode2;
_packet[8] = sendColor2[0];
_packet[9] = sendColor2[1];
_packet[10] = sendColor2[2];
_packet[11] = sendInterval2;
unsigned short crcCal = CRC16_Make(_packet, _packet[1]+2);
_crc[0] = (crcCal >> 8) & 0xff;
_crc[1] = crcCal & 0xff;
Send_Processing(_packet,_packet[1],_crc);
}
//-------------------------------------------------------------------------------------------------------//
/* Parameter descriptions for all functions:
*
* Color: The name of the desired color
enum Colors
{
AliceBlue, AntiqueWhite, Aqua,
Aquamarine, Azure, Beige,
Bisque, Black, BlanchedAlmond,
Blue, BlueViolet, Brown,
BurlyWood, CadetBlue, Chartreuse,
Chocolate, Coral, CornflowerBlue,
Cornsilk, Crimson, Cyan,
DarkBlue, DarkCyan, DarkGoldenRod,
DarkGray, DarkGreen, DarkKhaki,
DarkMagenta, DarkOliveGreen, DarkOrange,
DarkOrchid, DarkRed, DarkSalmon,
DarkSeaGreen, DarkSlateBlue, DarkSlateGray,
DarkTurquoise, DarkViolet, DeepPink,
DeepSkyBlue, DimGray, DodgerBlue,
FireBrick, FloralWhite, ForestGreen,
Fuchsia, Gainsboro, GhostWhite,
Gold, GoldenRod, Gray,
Green, GreenYellow, HoneyDew,
HotPink, IndianRed, Indigo,
Ivory, Khaki, Lavender,
LavenderBlush, LawnGreen, LemonChiffon,
LightBlue, LightCoral, LightCyan,
LightGoldenRodYellow, LightGray, LightGreen,
LightPink, LightSalmon, LightSeaGreen,
LightSkyBlue, LightSlateGray, LightSteelBlue,
LightYellow, Lime, LimeGreen,
Linen, Magenta, Maroon,
MediumAquaMarine, MediumBlue, MediumOrchid,
MediumPurple, MediumSeaGreen, MediumSlateBlue,
MediumSpringGreen, MediumTurquoise, MediumVioletRed,
MidnightBlue, MintCream, MistyRose,
Moccasin, NavajoWhite, Navy,
OldLace, Olive, OliveDrab,
Orange, OrangeRed, Orchid,
PaleGoldenRod, PaleGreen, PaleTurquoise,
PaleVioletRed, PapayaWhip, PeachPuff,
Peru, Pink, Plum,
PowderBlue, Purple, RebeccaPurple,
Red, RosyBrown, RoyalBlue,
SaddleBrown, Salmon, SandyBrown,
SeaGreen, SeaShell, Sienna,
Silver, SkyBlue, SlateBlue,
SlateGray, Snow, SpringGreen,
SteelBlue, Tan, Teal,
Thistle, Tomato, Turquoise,
Violet, Wheat, White,
WhiteSmoke, Yellow, YellowGreen,
EndOfColor
};
* Mode: mode refers to the pattern of the LEDs
SOLID - LED remains on
STROBE - LED cycles through all of the colors in Colors
BLINK - LED flashes on and off
DOUBLE_BLINK - LED turns on twice and then turns off for that interval
DIMMING - LED fades in and out
PULSE - LED on one arm turns on and off then cycles to the next arm
PULSE_REVERSE - same as PULSE but in the opposite direction
* R, G, B: The red, green, and blue values for the desired color
R: 0 ~ 255
G: 0 ~ 255
B: 0 ~ 255
* Interval: When used with SOLID, interval is the brightness. When
When used with other modes, interval is flashes per second.
Value can be 0 ~ 255
Default value is 100
*
*
*/
/*
* function : setEyeLed
* description : Sets the color, mode, and interval for the eyes
* param : Color, Mode, R, G, B, Interval
* return : none
*/
void CoDroneClass::setEyeLED(byte Color, byte Mode){
LedColorProcess(dType_LedMode, Mode, Color, 0, 0, 100);
}
void CoDroneClass::setEyeLED(byte Color, byte Mode, byte Interval){
LedColorProcess(dType_LedMode, Mode, Color, 0, 0, Interval);
}
void CoDroneClass::setEyeLED(byte R, byte G, byte B, byte Mode){
LedColorProcess(dType_LedModeColor, Mode, R, G, B, 100);
}
void CoDroneClass::setEyeLED(byte R, byte G, byte B, byte Mode, byte Interval){
LedColorProcess(dType_LedModeColor, Mode, R, G, B, Interval);
}
/*
* function : setArmLED
* description : Sets the color, mode, and interval for the eyes
* param : Color, Mode, R, G, B, Interval
* return : none
*/
void CoDroneClass::setArmLED(byte Color, byte Mode){
LedColorProcess(dType_LedMode, Mode+0x30, Color, 0, 0, 100);
}
void CoDroneClass::setArmLED(byte Color, byte Mode, byte Interval){
LedColorProcess(dType_LedMode, Mode+0x30, Color, 0, 0, Interval);
}
void CoDroneClass::setArmLED(byte R, byte G, byte B, byte Mode){
LedColorProcess(dType_LedModeColor, Mode+0x30, R, G, B, 100);
}
void CoDroneClass::setArmLED(byte R, byte G, byte B, byte Mode, byte Interval){
LedColorProcess(dType_LedModeColor, Mode+0x30, R, G, B, Interval);
}
/*
* function : setAllLED
* description : Sets color, mode, and interval for both the eyes and arms
* param : Color, Mode, R, G, B, Interval
* return : none
*/
void CoDroneClass::setAllLED(byte Color, byte Mode){
LedColor2Process(dType_LedMode2, Mode, Color, 0, 0, 100, Mode+0x30, Color, 0, 0, 100);
}
void CoDroneClass::setAllLED(byte Color, byte Mode, byte Interval){
LedColor2Process(dType_LedMode2, Mode, Color, 0, 0, Interval, Mode+0x30, Color, 0, 0, Interval);
}
void CoDroneClass::setAllLED(byte R, byte G, byte B, byte Mode){
LedColor2Process(dType_LedModeColor2, Mode, R, G, B, 100, Mode+0x30, R, G, B, 100);
}
void CoDroneClass::setAllLED(byte R, byte G, byte B, byte Mode, byte Interval){
LedColor2Process(dType_LedModeColor2, Mode, R, G, B, Interval, Mode+0x30, R, G, B, Interval);
}
// not support yet
// void CoDroneClass::setEyeDefaultLED(byte Color, byte Mode)
// void CoDroneClass::setEyeDefaultLED(byte Color, byte Mode, byte Interval)
/*
* function : setEyeDefaultLED
* description : Sets the default color, mode, and interval for the eyes for
* when CoDrone is powered on. Settings will remain even after
* battery is removed
* param : R, G, B, Mode, Interval
* return : none
*/
void CoDroneClass::setEyeDefaultLED(byte R, byte G, byte B, byte Mode){
LedColorProcess(dType_LedDefaultColor, Mode, R, G, B, 100);
}
void CoDroneClass::setEyeDefaultLED(byte R, byte G, byte B, byte Mode, byte Interval){
LedColorProcess(dType_LedDefaultColor, Mode, R, G, B, Interval);
}
// not support yet
// void CoDroneClass::setArmDefaultLED(byte Color, byte Mode)
// void CoDroneClass::setArmDefaultLED(byte Color, byte Mode, byte Interval)
/*
* function : setArmDefaultLED
* description : Sets the default color, mode, and interval for the arms for
* when CoDrone is powered on. Settings will remain even after
* battery is removed
* param : R, G, B, Mode, Interval
* return : none
*/
void CoDroneClass::setArmDefaultLED(byte R, byte G, byte B, byte Mode){
LedColorProcess(dType_LedDefaultColor, Mode+0x30, R, G, B, 100);
}
void CoDroneClass::setArmDefaultLED(byte R, byte G, byte B, byte Mode, byte Interval){
LedColorProcess(dType_LedDefaultColor, Mode+0x30, R, G, B, Interval);
}
// not support
// void CoDroneClass::setAllDefaultLED(byte Color, byte Mode)
// void CoDroneClass::setAllDefaultLED(byte Color, byte Mode, byte Interval)
/*
* function : setAllDefaultLED
* description : Sets the default color, mode, and interval for both eyes
* and arms for when CoDrone is powered on. Settings will
* remain even after battery is removed
* param : R, G, B, Mode, Interval
* return : none
*/
void CoDroneClass::setAllDefaultLED(byte R, byte G, byte B, byte Mode){
LedColor2Process(dType_LedDefaultColor2, Mode, R, G, B, 100, Mode+0x30, R, G, B, 100);
}
void CoDroneClass::setAllDefaultLED(byte R, byte G, byte B, byte Mode, byte Interval){
LedColor2Process(dType_LedDefaultColor2, Mode, R, G, B, Interval, Mode+0x30, R, G, B, Interval);
}
/*
* function : resetDefaultLED()
* description : resetDefaultLED() is function for make LED default color and mode
* It will change to red LED is hold
* param : none
* return : none
*/
void CoDroneClass::resetDefaultLED()
{
LedColor2Process(dType_LedDefaultColor2, SOLID, 255, 0, 0, 100, SOLID+0x30, 255, 0, 0, 100);
}
//------------------------------------------------------------------------------------------------
void CoDroneClass::eyeColor(byte Color, byte brightness){
LedColorProcess(dType_LedMode, LED_SOLID, Color, 0, 0, brightness);
}
void CoDroneClass::eyeColor(byte R, byte G, byte B, byte brightness){
LedColorProcess(dType_LedModeColor, LED_SOLID, R, G, B, brightness);
}
void CoDroneClass::armColor(byte Color, byte brightness){
LedColorProcess(dType_LedMode, LED_SOLID+0x30, Color, 0, 0, brightness);
}
void CoDroneClass::armColor(byte R, byte G, byte B, byte brightness){
LedColorProcess(dType_LedModeColor, LED_SOLID+0x30, R, G, B, brightness);
}
//------------------------------------------------------------------------------------------------
void CoDroneClass::eyeDefaultColor(byte R, byte G, byte B, byte Interval){
LedColorProcess(dType_LedDefaultColor, LED_SOLID, R, G, B, Interval);
}
void CoDroneClass::armDefaultColor(byte R, byte G, byte B, byte Interval){
LedColorProcess(dType_LedDefaultColor, LED_SOLID+0x30, R, G, B, Interval);
}
//------------------------------------------------------------------------------------------------
void CoDroneClass::eyePattern(byte Color, byte pattern, byte brightness){
LedColorProcess(dType_LedMode, pattern, Color, 0, 0, brightness);
}
void CoDroneClass::eyePattern(byte R, byte G, byte B, byte pattern, byte brightness){
LedColorProcess(dType_LedModeColor, pattern, R, G, B, brightness);
}
void CoDroneClass::armPattern(byte Color, byte pattern, byte brightness){
LedColorProcess(dType_LedMode, pattern+0x30, Color, 0, 0, brightness);
}
void CoDroneClass::armPattern(byte R, byte G, byte B, byte pattern, byte brightness){
LedColorProcess(dType_LedModeColor, pattern+0x30, R, G, B, brightness);
}
//------------------------------------------------------------------------------------------------
void CoDroneClass::eyeDefaultPattern(byte R, byte G, byte B, byte Mode, byte Interval){
LedColorProcess(dType_LedDefaultColor, Mode, R, G, B, Interval);
}
void CoDroneClass::armDefaultPattern(byte R, byte G, byte B, byte Mode, byte Interval){
LedColorProcess(dType_LedDefaultColor, Mode+0x30, R, G, B, Interval);
}
//------------------------------------------------------------------------------------------------
void CoDroneClass::eyeStrobe(){
LedColorProcess(dType_LedMode, LED_STROBE, 0, 0, 0, 100);
}
void CoDroneClass::armStrobe(){
LedColorProcess(dType_LedModeColor, LED_STROBE+0x30, 0, 0, 0, 100);
}
//------------------------------------------------------------------------------------------------
void CoDroneClass::eyeOff(){
LedColorProcess(dType_LedMode, LED_NONE, 0, 0, 0, 0);
}
void CoDroneClass::armOff(){
LedColorProcess(dType_LedModeColor, LED_NONE+0x30, 0, 0, 0, 0);
}