-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsevenseg.cpp
More file actions
323 lines (284 loc) · 9.99 KB
/
sevenseg.cpp
File metadata and controls
323 lines (284 loc) · 9.99 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
/* support for drawing 7-segment digits and a few characters using tft drawing or direct img array.
*/
#include "HamClock.h"
// handy image array segment drawers
#define ImgHLine(x,y,w) for(int i = 0; i < (w); i++) \
memcpy (&img[(y)*LIVE_BYPPIX*BUILD_W + ((x)+i)*LIVE_BYPPIX], txt_clr, LIVE_BYPPIX)
#define ImgVLine(x,y,h) for(int i = 0; i < (h); i++) \
memcpy (&img[((y)+i)*LIVE_BYPPIX*BUILD_W + (x)*LIVE_BYPPIX], txt_clr, LIVE_BYPPIX)
#define ImgForwardslash(x,y,h) for(int i = 0; i < (h); i++) \
memcpy (&img[((y)+(h)-1-i)*LIVE_BYPPIX*BUILD_W + ((x)+i)*LIVE_BYPPIX], txt_clr, LIVE_BYPPIX)
#define ImgBackslash(x,y,h) for(int i = 0; i < (h); i++) \
memcpy (&img[((y)+i)*LIVE_BYPPIX*BUILD_W + ((x)+i)*LIVE_BYPPIX], txt_clr, LIVE_BYPPIX)
/* draw a digit in the given frame buffer of size and location given by the given box.
*/
void drawImgDigit (unsigned digit, uint8_t *img, const SBox &b, const uint8_t txt_clr[LIVE_BYPPIX])
{
switch (digit) {
#if BUILD_W == 800
// only room for square corners
case 0:
ImgHLine(b.x, b.y, b.w);
ImgVLine(b.x, b.y, b.h);
ImgVLine(b.x+b.w-1, b.y, b.h);
ImgHLine(b.x, b.y+b.h-1, b.w);
break;
case 1:
ImgHLine(b.x, b.y, b.w/2);
ImgVLine(b.x+b.w/2, b.y, b.h);
ImgHLine(b.x, b.y+b.h-1, b.w);
break;
case 2:
ImgHLine(b.x, b.y, b.w);
ImgVLine(b.x+b.w-1, b.y, b.h/2);
ImgHLine(b.x, b.y+b.h/2, b.w);
ImgVLine(b.x, b.y+b.h/2, b.h/2);
ImgHLine(b.x, b.y+b.h-1, b.w);
break;
case 3:
ImgHLine(b.x, b.y, b.w);
ImgVLine(b.x+b.w-1, b.y, b.h);
ImgHLine(b.x, b.y+b.h/2, b.w);
ImgHLine(b.x, b.y+b.h-1, b.w);
break;
case 4:
ImgVLine(b.x, b.y, b.h/2);
ImgVLine(b.x+b.w-1, b.y, b.h);
ImgHLine(b.x, b.y+b.h/2, b.w);
break;
case 5:
ImgHLine(b.x, b.y, b.w);
ImgVLine(b.x, b.y, b.h/2);
ImgHLine(b.x, b.y+b.h/2, b.w);
ImgVLine(b.x+b.w-1, b.y+b.h/2, b.h/2);
ImgHLine(b.x, b.y+b.h-1, b.w);
break;
case 6:
ImgHLine(b.x, b.y, b.w);
ImgVLine(b.x, b.y, b.h);
ImgHLine(b.x, b.y+b.h/2, b.w);
ImgVLine(b.x+b.w-1, b.y+b.h/2, b.h/2);
ImgHLine(b.x, b.y+b.h-1, b.w);
break;
case 7:
ImgHLine(b.x, b.y, b.w);
ImgVLine(b.x+b.w-1, b.y, b.h);
break;
case 8:
ImgHLine(b.x, b.y, b.w);
ImgVLine(b.x, b.y, b.h);
ImgVLine(b.x+b.w-1, b.y, b.h);
ImgHLine(b.x, b.y+b.h/2, b.w);
ImgHLine(b.x, b.y+b.h-1, b.w);
break;
case 9:
ImgHLine(b.x, b.y, b.w);
ImgVLine(b.x, b.y, b.h/2);
ImgHLine(b.x, b.y+b.h/2, b.w);
ImgVLine(b.x+b.w-1, b.y, b.h);
ImgHLine(b.x, b.y+b.h-1, b.w);
break;
#else
// BUILD_W != 800 has room for rounded corners
case 0:
ImgHLine(b.x+1, b.y, b.w-2);
ImgVLine(b.x, b.y+1, b.h-2);
ImgVLine(b.x+b.w-1, b.y+1, b.h-2);
ImgHLine(b.x+1, b.y+b.h-1, b.w-2);
ImgForwardslash(b.x, b.y+b.h/4, b.w);
break;
case 1:
ImgHLine(b.x+1, b.y, b.w/2-1);
ImgVLine(b.x+b.w/2, b.y, b.h);
ImgHLine(b.x, b.y+b.h-1, b.w);
break;
case 2:
ImgHLine(b.x, b.y, b.w-1);
ImgVLine(b.x+b.w-1, b.y+1, b.h/2-1);
ImgHLine(b.x+1, b.y+b.h/2, b.w-2);
ImgVLine(b.x, b.y+b.h/2+1, b.h/2-2);
ImgHLine(b.x+1, b.y+b.h-1, b.w-1);
break;
case 3:
ImgHLine(b.x, b.y, b.w-1);
ImgVLine(b.x+b.w-1, b.y+1, b.h-2);
ImgHLine(b.x, b.y+b.h/2, b.w);
ImgHLine(b.x, b.y+b.h-1, b.w-1);
break;
case 4:
ImgVLine(b.x, b.y, b.h/2);
ImgVLine(b.x+b.w-1, b.y, b.h);
ImgHLine(b.x+1, b.y+b.h/2, b.w-1);
break;
case 5:
ImgHLine(b.x+1, b.y, b.w-1);
ImgVLine(b.x, b.y+1, b.h/2-1);
ImgHLine(b.x+1, b.y+b.h/2, b.w-1);
ImgVLine(b.x+b.w-1, b.y+b.h/2+1, b.h/2-1);
ImgHLine(b.x, b.y+b.h-1, b.w-1);
break;
case 6:
ImgHLine(b.x+1, b.y, b.w-1);
ImgVLine(b.x, b.y+1, b.h-2);
ImgHLine(b.x+1, b.y+b.h/2, b.w-2);
ImgVLine(b.x+b.w-1, b.y+b.h/2+1, b.h/2-1);
ImgHLine(b.x+1, b.y+b.h-1, b.w-2);
break;
case 7:
ImgHLine(b.x, b.y, b.w-1);
ImgVLine(b.x+b.w-1, b.y+1, b.h-1);
break;
case 8:
ImgHLine(b.x+1, b.y, b.w-2);
ImgVLine(b.x, b.y+1, b.h-2);
ImgVLine(b.x+b.w-1, b.y+1, b.h-2);
ImgHLine(b.x, b.y+b.h/2, b.w);
ImgHLine(b.x+1, b.y+b.h-1, b.w-2);
break;
case 9:
ImgHLine(b.x+1, b.y, b.w-2);
ImgVLine(b.x, b.y+1, b.h/2-1);
ImgHLine(b.x+1, b.y+b.h/2, b.w-1);
ImgVLine(b.x+b.w-1, b.y+1, b.h-2);
ImgHLine(b.x, b.y+b.h-1, b.w-1);
break;
#endif // BUILD_W == 800
}
}
void drawImgNumber (unsigned n, uint8_t *img, SBox &b, const uint8_t txt_clr[LIVE_BYPPIX])
{
int n10 = n/10;
if (n10)
drawImgNumber (n10, img, b, txt_clr);
drawImgDigit (n%10, img, b, txt_clr);
b.x += 3*b.w/2;
}
void drawImgR (uint8_t *img, SBox b, const uint8_t txt_clr[LIVE_BYPPIX])
{
#if BUILD_W == 800
// square corners
ImgHLine(b.x, b.y, b.w);
ImgVLine(b.x, b.y, b.h);
ImgVLine(b.x+b.w-1, b.y, b.h/2);
ImgHLine(b.x, b.y+b.h/2, b.w);
ImgBackslash(b.x, b.y+b.h/2, b.h/2+1);
#else
// room for rounded corners
ImgBackslash(b.x, b.y+b.h/2, b.h/2);
ImgHLine(b.x, b.y, b.w-1);
ImgVLine(b.x, b.y+1, b.h-1);
ImgVLine(b.x+b.w-1, b.y+1, b.h/2-1);
ImgHLine(b.x+1, b.y+b.h/2, b.w-2);
ImgBackslash(b.x, b.y+b.h/2-1, b.h/2+1);
#endif
}
void drawImgO (uint8_t *img, SBox b, const uint8_t txt_clr[LIVE_BYPPIX])
{
#if BUILD_W == 800
// square corners
ImgHLine(b.x, b.y, b.w);
ImgVLine(b.x, b.y, b.h);
ImgVLine(b.x+b.w-1, b.y, b.h);
ImgHLine(b.x, b.y+b.h-1, b.w);
#else
// room for rounded corners
ImgHLine(b.x+1, b.y, b.w-2);
ImgVLine(b.x, b.y+1, b.h-2);
ImgVLine(b.x+b.w-1, b.y+1, b.h-2);
ImgHLine(b.x+1, b.y+b.h-1, b.w-2);
#endif
}
void drawImgW (uint8_t *img, SBox b, const uint8_t txt_clr[LIVE_BYPPIX])
{
#if BUILD_W == 800
// extra wide for center line
ImgVLine(b.x, b.y, b.h);
ImgVLine(b.x+b.w/2+1, b.y+b.h/2, b.h/2);
ImgVLine(b.x+b.w+1, b.y, b.h);
ImgHLine(b.x, b.y+b.h-1, b.w+2);
#else
// room for rounded corners
ImgVLine(b.x, b.y, b.h-1);
ImgVLine(b.x+b.w/2, b.y+b.h/2, b.h/2);
ImgVLine(b.x+b.w, b.y, b.h-1);
ImgHLine(b.x+1, b.y+b.h-1, b.w-1);
#endif
}
/* draw the given digit in the given bounding box with the given line thickness.
*/
void drawDigit (const SBox &b, int digit, uint16_t lt, uint16_t bg, uint16_t fg)
{
// insure all dimensions are even so two halves make a whole
uint16_t t = (lt+1) & ~1U;
uint16_t w = (b.w+1) & ~1U;
uint16_t h = (b.h+1) & ~1U;
uint16_t to2 = t/2;
uint16_t wo2 = w/2;
uint16_t ho2 = h/2;
// erase
tft.fillRect (b.x, b.y, w, h, bg);
// draw digit -- replace with drawRect to check boundaries
switch (digit) {
case 0:
tft.fillRect (b.x, b.y, w, t, fg);
tft.fillRect (b.x, b.y+t, t, h-2*t, fg);
tft.fillRect (b.x, b.y+h-t, w, t, fg);
tft.fillRect (b.x+w-t, b.y+t, t, h-2*t, fg);
break;
case 1:
tft.fillRect (b.x+wo2-to2, b.y, t, h, fg); // center column? a little right?
break;
case 2:
tft.fillRect (b.x, b.y, w, t, fg);
tft.fillRect (b.x+w-t, b.y+t, t, ho2-t-to2, fg);
tft.fillRect (b.x, b.y+ho2-to2, w, t, fg);
tft.fillRect (b.x, b.y+ho2+to2, t, ho2-t-to2, fg);
tft.fillRect (b.x, b.y+h-t, w, t, fg);
break;
case 3:
tft.fillRect (b.x, b.y, w, t, fg);
tft.fillRect (b.x+t, b.y+ho2-to2, w-t, t, fg);
tft.fillRect (b.x, b.y+h-t, w, t, fg);
tft.fillRect (b.x+w-t, b.y+t, t, h-2*t, fg);
break;
case 4:
tft.fillRect (b.x, b.y, t, ho2+to2, fg);
tft.fillRect (b.x+t, b.y+ho2-to2, w-2*t, t, fg);
tft.fillRect (b.x+w-t, b.y, t, h, fg);
break;
case 5:
tft.fillRect (b.x, b.y, w, t, fg);
tft.fillRect (b.x, b.y+t, t, ho2-t-to2, fg);
tft.fillRect (b.x, b.y+ho2-to2, w, t, fg);
tft.fillRect (b.x+w-t, b.y+ho2+to2, t, ho2-t-to2, fg);
tft.fillRect (b.x, b.y+h-t, w, t, fg);
break;
case 6:
tft.fillRect (b.x, b.y, t, h, fg);
tft.fillRect (b.x+t, b.y, w-t, t, fg);
tft.fillRect (b.x+t, b.y+ho2-to2, w-t, t, fg);
tft.fillRect (b.x+w-t, b.y+ho2+to2, t, ho2-to2-t, fg);
tft.fillRect (b.x+t, b.y+h-t, w-t, t, fg);
break;
case 7:
tft.fillRect (b.x, b.y, w, t, fg);
tft.fillRect (b.x+w-t, b.y+t, t, h-t, fg);
break;
case 8:
tft.fillRect (b.x, b.y, t, h, fg);
tft.fillRect (b.x+w-t, b.y, t, h, fg);
tft.fillRect (b.x+t, b.y, w-2*t, t, fg);
tft.fillRect (b.x+t, b.y+ho2-to2, w-2*t, t, fg);
tft.fillRect (b.x+t, b.y+h-t, w-2*t, t, fg);
break;
case 9:
tft.fillRect (b.x, b.y, t, ho2+to2, fg);
tft.fillRect (b.x+w-t, b.y, t, h, fg);
tft.fillRect (b.x+t, b.y, w-2*t, t, fg);
tft.fillRect (b.x+t, b.y+ho2-to2, w-2*t, t, fg);
break;
default:
fatalError("drawDigit %d", digit);
break;
}
}