-
Notifications
You must be signed in to change notification settings - Fork 0
/
slcp_led_cmds.c
183 lines (119 loc) · 3.12 KB
/
slcp_led_cmds.c
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
/*
* slcp_led_cmds.c
*/
#include "com_utils.h"
#include "slcp_led_cmds.h"
#include <stdio.h>
#include <stdlib.h>
uchar* setLED(uchar x, uchar y, uchar red, uchar green, uchar blue)
{
uchar r = 0, g = 0, b = 0;
uchar data[6];
uchar *frame;
if (x > 7 || y > 7) {
fprintf(stderr, "Bad coordinates, must be 0-7! setLED: (%d, %d)\n", x, y);
return NULL;
}
if (red >= 16)
fprintf(stderr, "setLED is clipping extraneous bits from red!\n");
if (green >= 16)
fprintf(stderr, "setLED is clipping extraneous bits from green!\n");
if (blue >= 16)
fprintf(stderr, "setLED is clipping extraneous bits from blue!\n");
r |= (0xF & red);
g |= (0xF & green);
b |= (0xF & blue);
data[0] = CMD_L8_LED_SET;
data[1] = x;
data[2] = y;
data[3] = b;
data[4] = g;
data[5] = r;
frame = makeSLCPFrame((uchar *) &data, 6);
if (!frame) return NULL;
sendSLCPFrame(frame);
free(frame);
return (uchar *) 0;
}
uchar* setSuperLED(uchar red, uchar green, uchar blue)
{
uchar r = 0, g = 0, b = 0;
uchar data[4];
uchar *frame;
if (red >= 16)
fprintf(stderr, "setLED is clipping extraneous bits from red!\n");
if (green >= 16)
fprintf(stderr, "setLED is clipping extraneous bits from green!\n");
if (blue >= 16)
fprintf(stderr, "setLED is clipping extraneous bits from blue!\n");
r |= (0xF & red);
g |= (0xF & green);
b |= (0xF & blue);
data[0] = CMD_L8_SUPERLED_SET;
data[1] = b;
data[2] = g;
data[3] = r;
frame = makeSLCPFrame((uchar *) &data, 4);
if (!frame) return NULL;
sendSLCPFrame(frame);
free(frame);
return (uchar *) 0;
}
uchar* matrixSetSolid(uchar red, uchar green, uchar blue)
{
uchar r = 0, g = 0, b = 0;
uchar data[128], i;
if (red >= 16)
fprintf(stderr, "matrixSetSolid is clipping extraneous bits from red!\n");
if (green >= 16)
fprintf(stderr, "matrixSetSolid is clipping extraneous bits from green!\n");
if (blue >= 16)
fprintf(stderr, "matrixSetSolid is clipping extraneous bits from blue!\n");
r |= (0xF & red);
g |= (0xF & green);
b |= (0xF & blue);
data[0] = CMD_L8_MATRIX_SET;
for (i = 1; i < 128; i += 2) {
data[i] = ((0x00 & 0xF0) & b);
data[i+1] = ((g << 4) & r);
}
return matrixSet((uchar *) &data);
}
uchar* matrixSet(uchar *matrix)
{
uchar *frame;
if (matrix[0] != CMD_L8_MATRIX_SET) {
fprintf(stderr, "matrixSet received a matrix that didn't have CMD_L8_MATRIX_SET!\n");
return NULL;
}
frame = makeSLCPFrame(matrix, 128);
if (!frame) return NULL;
sendSLCPFrame(frame);
free(frame);
return (uchar *) 0;
}
uchar* matrixOff()
{
uchar *frame;
frame = makeQueryFrame(CMD_L8_MATRIX_OFF);
if (!frame) return NULL;
sendSLCPFrame(frame);
free(frame);
return (uchar *) 0;
}
uchar* setStatusLEDs(uchar enable)
{
if (enable > 1) {
fprintf(stderr, "setStatusLEDs recevied invalid 'enable' bool param\n");
return NULL;
}
uchar data[2];
uchar *frame;
data[0] = CMD_L8_STATUSLEDS_ENABLE;
data[1] = enable;
frame = makeSLCPFrame((uchar *) &data, 2);
if (!frame) return NULL;
sendSLCPFrame(frame);
free(frame);
return (uchar *) 0;
}