-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_LED_CTRLR.ino
More file actions
397 lines (321 loc) · 9.15 KB
/
Copy pathTest_LED_CTRLR.ino
File metadata and controls
397 lines (321 loc) · 9.15 KB
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
#include "Arduino.h"
//class Foo : public Stream {
//private:
// Stream *_dev; // Somewhere to store the object's pointer
//
//public:
// Foo(Stream& dev) : _dev(&dev) {} // Store the pointer to the object
// size_t write(uint8_t val) { return _dev->write(val); } // Call a function on the stored object pointer
//};
//
//Foo myFoo(Serial); // Create a new instance of the class with the Serial object as a parameter
#define LED232 Serial1 //define Serial port used for LED ctrlr
void setup()
{
Serial.begin(115200);
LED232.begin(115200);
/* add setup code here */
}
void loop()
{
//LED232.println("TEST_COM");
//LED232.println(millis()); // Print something via your class.
// char CC[50] = {};
// char Cmdout[100] = {};/
// int len;
// int packetlen;
char *string;
string = "hey";
int brt = 0;
//char cout = *CCcmd;
setBrightness(0xFF, 0);
playProgram(0xFF, 1, 2);
while(1)
{
//for (int x = 1; x < 4; x++)
//{
// delay(500);
// LEDPlayProg_compact(0xFF, 0, x);
// delay(500);
// LEDPlayTxtWindow_compact(0xFF, 0, 0, 5, 100, 3, 2, 255, 255, 255, string);
// //for (int i = 0; i < 32; i++)
// //{
// // LEDBrightness(0xFF, i);
// // delay(2500);
// // Serial.print("Brightness ");
// // Serial.println(i);
// //}
//
//}
//for (int i = 0; i < 3; i++)
//{
// LEDPower_OnOff(0xFF, 0);
// delay(1000);
// LEDPower_OnOff(0xFF, 1);
// delay(1500);
//}
setBrightness(0xFF, brt);
brt=brt+3;
if (brt>31)
{
brt = 0;
}
}
}
/**
Compose CC data for Play desired program on LED screen. CC:0x08
@ID - id of display (0xFF for any)
@option Bit0: Whether to save select play message to flash. 0 not to save,1 save。Bit1~7: Reserved, set to 0
@prog_num Number of program to play 1~255 or 0
note that limit is for 1 program at once only!!!!
*/
void playProgram(uint8_t ID, uint8_t option, uint8_t prog_num) //option
{
char CCout[100] = {};
int pCCoutlength;
char Cmd_out[100] = {};
int paclen;
//function logic
CCout[0] = 0x08; //command ID
CCout[1] = option;
CCout[2] = 0x01; //1 program only
CCout[3] = prog_num;
pCCoutlength = 4;
packCMD(ID, CCout, pCCoutlength, Cmd_out, &paclen);//pack CMD data
sendCMD(Cmd_out, paclen); //send CMD data
}
/**
Compose CC data for: Play text in window CC=0x12
@ID - id of display (0xFF for any)
@window - window number 0-7
@effect - effects for text (0-draw, 1 open from čleft,... se document Special effect for text and picture
@alignment - alignment of text (0-2) Bit0~1: the horizontal alignment (
//////////////0: Left-aligned
//////////////1: Horizontal center
//////////////2: Right- aligned)
//////////////Bit2~3: vertical alignment (
//////////////0:Top-aligned
//////////////1:Vertically center,
//////////////2: Bottom- aligned)
//////////////Bit4~6: Reserved, set to 0
//////////////Bit7: Reserved, set to 0
@speed 1-100 (100 fastest)
@stayTime: seconds
@font: Bit0~3: font size,see:Font size code 0 8
//////1 12
//////2 16
//////3 24
//////4 32
//////5 40
//////6 48
//////7 56
//////Bit4~6 :font style,see :Font style code Font style code Font style describe
//////0 Default font style
//////1 Font style 1
//////2 Font style 2
//////3 Font style 3
//////4 Font style 4
//////5 Font style 5
//////6 Font style 6
//////7 Font style 7
//////Bit7 : reserved (set to 0)
@Red, Green, Blue: 0-255 color component
@*Text - text string to show
*/
void playTextWindow(uint8_t ID, uint8_t window, uint8_t effect, uint8_t alignment, uint8_t speed, uint16_t stayTime, uint8_t font, uint8_t Red, uint8_t Green, uint8_t Blue, char *Text) //option
{
char CCout[100] = {};
int pCCoutlength;
char Cmd_out[100] = {};
int paclen;
int length;
char *temp = Text;
// function logic
CCout[0] = 0x12;
CCout[1] = window;
CCout[2] = effect; //special effect
CCout[3] = alignment;
CCout[4] = speed;
CCout[5] = highByte(stayTime);
CCout[6] = lowByte(stayTime);
CCout[7] = font;
CCout[8] = Red; //R 0-255
CCout[9] = Green; //G 0-255
CCout[10] = Blue; //B
length = strlen(temp);
for (int i = 0; i < length; i++)
{
CCout[11 + i] = Text[i];
}
pCCoutlength = 11 + length;
packCMD(ID, CCout, pCCoutlength, Cmd_out, &paclen);//pack CMD data
sendCMD(Cmd_out, paclen); //send CMD data
}
void setBrightness(uint8_t ID, uint8_t brightness)
{
uint8_t protocol = 0x46;//power control code
char CCout[100] = {};
int pCCoutlength;
char Cmd_out[100] = {};
int paclen;
int count = 0;
//function logic
CCout[count++] = 0x00;
for (int i = 0; i < 24; i++) //calculation of packet CRC
{powerOnOff
CCout[count++] = brightness; // sets same brightness for all 24 hours
}
pCCoutlength = count;
packBasicCMD(ID, protocol, CCout, pCCoutlength, Cmd_out, &paclen);//pack CMD data
sendCMD(Cmd_out, paclen); //send CMD data
}
void powerOnOff(uint8_t ID, uint8_t power)
{
uint8_t protocol = 0x76;//power control code
char CCout[100] = {};
int pCCoutlength;
char Cmd_out[100] = {};
int paclen;
int count = 0;
//function logic
CCout[count++] = 0x00;
CCout[count++] = power; //power status 0 off, 1 on
for (int i = 0; i < 7; i++) //calculation of packet CRC
{
CCout[count++]=0x00; // fill 0
}
pCCoutlength = count;
packBasicCMD(ID, protocol, CCout, pCCoutlength, Cmd_out, &paclen);//pack CMD data
sendCMD(Cmd_out, paclen); //send CMD data
}
/**
Compose Led command package for sending over serial.
@id ID of the controller card (FF for all)
@*CCdata CCdata sub command
@*CClength length of CCdata command buffer
@*outbuffer output buffer of packed command
@*bufflength legth of outbuffer
*/
void packCMD(uint8_t id, char *CCdata, int CClength, char *outbuffer, int *pBufflength)
{
uint16_t crc = 0;
int count = 0;
outbuffer[count++] = 0x68;
outbuffer[count++] = 0x32;
outbuffer[count++] = id;
outbuffer[count++] = 0x7B;
outbuffer[count++] = 0x00; //0-not returning back info, 1 - return back info
outbuffer[count++] = lowByte(CClength); //
outbuffer[count++] = highByte(CClength);
outbuffer[count++] = 0x00; //When the packet sequence number is equal to when the last packet sequence number, indicating that this is the last one package.
outbuffer[count++] = 0x00; //The total number of packages minus 1.
for (int i = 0; i < CClength; i++)
{
outbuffer[count++] = CCdata[i];
}
for (int i = 0; i < count; i++) //calculation of packet CRC
{
uint8_t a = outbuffer[i]; // to cast a number- if not, 128 is negative
crc = crc + a;
}
outbuffer[count++] = lowByte(crc);
outbuffer[count++] = highByte(crc);
//strcat(LEDcmd, buffer);
*pBufflength = count;
}
/**
Compose Led command package for sending over serial. basic commands
@id ID of the controller card (FF for all)
@protocolCode:
Restart hardware 0x2d
Restart APP 0xfe
Write file(Open) 0x30
Write file (Write) 0x32
Write file (Close) 0x33
Quick write file (Open) 0x50
Quick write file (Write) 0x51
Quick write file (Close) 0x52
Time query and set 0x47
Brightness query and set 0x46
Query version info 0x2e
Power ON/OFF info 0x45
Power ON/OFF control 0x76
Query temperature 0x75
Remove file 0x2c
Query free disk space 0x29
@*CCdata CCdata sub command
@*CClength length of CCdata command buffer
@*outbuffer output buffer of packed command
@*bufflength legth of outbuffer
*/
void packBasicCMD(uint8_t id, uint8_t protocolCode, char *CCdata, int CClength, char *outbuffer, int *pBufflength)
{
uint16_t crc = 0;
int count = 0;
outbuffer[count++] = 0x68;
outbuffer[count++] = 0x32;
outbuffer[count++] = id;
outbuffer[count++] = protocolCode;
outbuffer[count++] = 0x01; //0-not returning back info, 1 - return back info
for (int i = 0; i < CClength; i++)
{
outbuffer[count++] = CCdata[i];
}
for (int i = 0; i < count; i++) //calculation of packet CRC
{
uint8_t a = outbuffer[i]; // to cast a number- if not, 128 is negative
crc = crc + a;
}
outbuffer[count++] = lowByte(crc);
outbuffer[count++] = highByte(crc);
//strcat(LEDcmd, buffer);
*pBufflength = count;
}
/**
Send command packet to Led controller over serial port
adds start and end byte and inserts needed escaped chars
*/
void sendCMD(char *buffer, int bufflen) //add start+stop and escaped chars and send them to serial port
{
uint8_t tempval;
uint8_t cnt = 0;
char outbuf[50] = {};
outbuf[0] = 0xa5; //start byte
cnt++;
for (int i = 0; i < bufflen; i++) //check for inception of ecsaped char
{
tempval = buffer[i];
switch (tempval)
{
case 0xa5:
outbuf[cnt] = 0xaa;
cnt++;
outbuf[cnt] = 0x05;
cnt++;
break;
case 0xae:
outbuf[cnt] = 0xaa;
cnt++;
outbuf[cnt] = 0x0e;
cnt++;
break;
case 0xaa:
outbuf[cnt] = 0xaa;
cnt++;
outbuf[cnt] = 0x0a;
cnt++;
break;
default:
outbuf[cnt] = buffer[i];
cnt++;
break;
}
}
outbuf[cnt] = 0xae;//end byte
cnt++;
for (int i = 0; i < cnt; i++) //outbuffer scan
{
LED232.write(outbuf[i]);
Serial.print(outbuf[i]);//debug
}
}