1 | #include <stdlib.h> |
---|
2 | #include <stdio.h> |
---|
3 | #include <unistd.h> |
---|
4 | #include <termios.h> |
---|
5 | #include <fcntl.h> |
---|
6 | #include <string.h> |
---|
7 | #include <errno.h> |
---|
8 | #include "lcd.h" |
---|
9 | #include "MtxOrb.h" |
---|
10 | #include "drv_base.h" |
---|
11 | |
---|
12 | #include "../../shared/debug.h" |
---|
13 | #include "../../shared/str.h" |
---|
14 | |
---|
15 | static int custom=0; |
---|
16 | |
---|
17 | // TODO: Remove this custom_type if not in use anymore. |
---|
18 | typedef enum { |
---|
19 | hbar = 1, |
---|
20 | vbar = 2, |
---|
21 | bign = 4, |
---|
22 | beat = 8 } custom_type; |
---|
23 | |
---|
24 | // TODO: This is my ugglyest piece of code. |
---|
25 | typedef enum { |
---|
26 | baru1 = 0, |
---|
27 | baru2 = 1, |
---|
28 | baru3 = 2, |
---|
29 | baru4 = 3, |
---|
30 | baru5 = 4, |
---|
31 | baru6 = 5, |
---|
32 | baru7 = 6, |
---|
33 | bard1 = 7, |
---|
34 | bard2 = 8, |
---|
35 | bard3 = 9, |
---|
36 | bard4 = 10, |
---|
37 | bard5 = 11, |
---|
38 | bard6 = 12, |
---|
39 | bard7 = 13, |
---|
40 | barr1 = 14, |
---|
41 | barr2 = 15, |
---|
42 | barr3 = 16, |
---|
43 | barr4 = 17, |
---|
44 | barl1 = 18, |
---|
45 | barl2 = 19, |
---|
46 | barl3 = 20, |
---|
47 | barl4 = 21, |
---|
48 | barw = 32, |
---|
49 | barb = 255} bar_type; |
---|
50 | |
---|
51 | static int fd; |
---|
52 | static int clear=1; |
---|
53 | |
---|
54 | static int def[9]={-1,-1,-1,-1,-1,-1,-1,-1,-1}; |
---|
55 | static int use[9]={1,0,0,0,0,0,0,0,0}; |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | static void MtxOrb_linewrap(int on); |
---|
60 | static void MtxOrb_autoscroll(int on); |
---|
61 | static void MtxOrb_cursorblink(int on); |
---|
62 | |
---|
63 | // TODO: Get rid of this variable? |
---|
64 | lcd_logical_driver *MtxOrb; |
---|
65 | // TODO: Get the frame buffers working right |
---|
66 | |
---|
67 | ///////////////////////////////////////////////////////////////// |
---|
68 | // Opens com port and sets baud correctly... |
---|
69 | // |
---|
70 | int MtxOrb_init(lcd_logical_driver *driver, char *args) |
---|
71 | { |
---|
72 | char *argv[64]; |
---|
73 | int argc; |
---|
74 | struct termios portset; |
---|
75 | int i; |
---|
76 | int tmp; |
---|
77 | |
---|
78 | int contrast=140; |
---|
79 | char device[256] = "/dev/lcd"; |
---|
80 | int speed=B19200; |
---|
81 | |
---|
82 | |
---|
83 | MtxOrb = driver; |
---|
84 | |
---|
85 | |
---|
86 | //debug("MtxOrb_init: Args(all): %s\n", args); |
---|
87 | |
---|
88 | argc = get_args(argv, args, 64); |
---|
89 | |
---|
90 | /* |
---|
91 | for(i=0; i<argc; i++) |
---|
92 | { |
---|
93 | printf("Arg(%i): %s\n", i, argv[i]); |
---|
94 | } |
---|
95 | */ |
---|
96 | |
---|
97 | for(i=0; i<argc; i++) |
---|
98 | { |
---|
99 | //printf("Arg(%i): %s\n", i, argv[i]); |
---|
100 | if(0 == strcmp(argv[i], "-d") || |
---|
101 | 0 == strcmp(argv[i], "--device")) |
---|
102 | { |
---|
103 | if(i + 1 > argc) { |
---|
104 | fprintf(stderr, "MtxOrb_init: %s requires an argument\n", |
---|
105 | argv[i]); |
---|
106 | return -1; |
---|
107 | } |
---|
108 | strcpy(device, argv[++i]); |
---|
109 | } |
---|
110 | else if(0 == strcmp(argv[i], "-c") || |
---|
111 | 0 == strcmp(argv[i], "--contrast")) |
---|
112 | { |
---|
113 | if(i + 1 > argc) { |
---|
114 | fprintf(stderr, "MtxOrb_init: %s requires an argument\n", |
---|
115 | argv[i]); |
---|
116 | return -1; |
---|
117 | } |
---|
118 | tmp = atoi(argv[++i]); |
---|
119 | if((tmp < 0) || (tmp > 255)){ |
---|
120 | fprintf(stderr, "MtxOrb_init: %s argument must between 0 and 255. Ussing default value.\n", |
---|
121 | argv[i]); |
---|
122 | } else contrast = tmp; |
---|
123 | } |
---|
124 | else if(0 == strcmp(argv[i], "-s") || |
---|
125 | 0 == strcmp(argv[i], "--speed")) |
---|
126 | { |
---|
127 | if(i + 1 > argc) { |
---|
128 | fprintf(stderr, "MtxOrb_init: %s requires an argument\n", |
---|
129 | argv[i]); |
---|
130 | return -1; |
---|
131 | } |
---|
132 | tmp = atoi(argv[++i]); |
---|
133 | if(tmp==1200) speed=B1200; |
---|
134 | else if(tmp==2400) speed=B2400; |
---|
135 | else if(tmp==9600) speed=B9600; |
---|
136 | else if(tmp==19200) speed=B19200; |
---|
137 | else { |
---|
138 | fprintf(stderr, "MtxOrb_init: %s argument must be 1200, 2400, 9600 or 19200. Ussing default value.\n", |
---|
139 | argv[i]); |
---|
140 | } |
---|
141 | } |
---|
142 | else if(0 == strcmp(argv[i], "-h") || |
---|
143 | 0 == strcmp(argv[i], "--help")) |
---|
144 | { |
---|
145 | printf("LCDproc Matrix-Orbital LCD driver\n" |
---|
146 | "\t-d\t--device\tSelect the output device to use [/dev/lcd]\n" |
---|
147 | "\t-t\t--type\t\tSelect the LCD type (size) [20x4]\n" |
---|
148 | "\t-c\t--contrast\tSet the initial contrast [140]\n" |
---|
149 | "\t-s\t--speed\t\tSet the communication speed [19200]\n" |
---|
150 | "\t-h\t--help\t\tShow this help information\n"); |
---|
151 | return -1; |
---|
152 | } |
---|
153 | else |
---|
154 | { |
---|
155 | printf("Invalid parameter: %s\n", argv[i]); |
---|
156 | } |
---|
157 | |
---|
158 | } |
---|
159 | |
---|
160 | // Set up io port correctly, and open it... |
---|
161 | fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY); |
---|
162 | if (fd == -1) |
---|
163 | { |
---|
164 | fprintf(stderr, "MtxOrb_init: failed (%s)\n", strerror(errno)); |
---|
165 | return -1; |
---|
166 | } |
---|
167 | //else fprintf(stderr, "MtxOrb_init: opened device %s\n", device); |
---|
168 | tcgetattr(fd, &portset); |
---|
169 | // This is necessary in Linux, but does not exist in irix. |
---|
170 | #ifndef IRIX |
---|
171 | cfmakeraw(&portset); |
---|
172 | #endif |
---|
173 | cfsetospeed(&portset, speed); |
---|
174 | cfsetispeed(&portset, speed); |
---|
175 | tcsetattr(fd, TCSANOW, &portset); |
---|
176 | |
---|
177 | |
---|
178 | // Set display-specific stuff.. |
---|
179 | MtxOrb_linewrap(1); |
---|
180 | MtxOrb_autoscroll(1); |
---|
181 | MtxOrb_cursorblink(0); |
---|
182 | |
---|
183 | |
---|
184 | if(!driver->framebuf) |
---|
185 | { |
---|
186 | fprintf(stderr, "MtxOrb_init: No frame buffer.\n"); |
---|
187 | driver->close(); |
---|
188 | return -1; |
---|
189 | } |
---|
190 | |
---|
191 | |
---|
192 | // Set the functions the driver supports... |
---|
193 | |
---|
194 | // driver->clear = (void *)-1; |
---|
195 | driver->clear = MtxOrb_clear; |
---|
196 | driver->string = (void *)-1; |
---|
197 | // driver->chr = MtxOrb_chr; |
---|
198 | driver->chr = (void *)-1; |
---|
199 | driver->vbar = MtxOrb_vbar; |
---|
200 | driver->init_vbar = MtxOrb_init_vbar; |
---|
201 | // driver->init_vbar = (void *)-1; |
---|
202 | driver->hbar = MtxOrb_hbar; |
---|
203 | driver->init_hbar = MtxOrb_init_hbar; |
---|
204 | // driver->init_hbar = (void *)-1; |
---|
205 | driver->num = MtxOrb_num; |
---|
206 | driver->init_num = MtxOrb_init_num; |
---|
207 | |
---|
208 | driver->init = MtxOrb_init; |
---|
209 | driver->close = MtxOrb_close; |
---|
210 | driver->flush = MtxOrb_flush; |
---|
211 | driver->flush_box = MtxOrb_flush_box; |
---|
212 | driver->contrast = MtxOrb_contrast; |
---|
213 | driver->backlight = MtxOrb_backlight; |
---|
214 | driver->output = MtxOrb_output; |
---|
215 | driver->set_char = MtxOrb_set_char; |
---|
216 | driver->icon = MtxOrb_icon; |
---|
217 | driver->draw_frame = MtxOrb_draw_frame; |
---|
218 | |
---|
219 | driver->getkey = MtxOrb_getkey; |
---|
220 | |
---|
221 | MtxOrb_contrast(contrast); |
---|
222 | |
---|
223 | return fd; |
---|
224 | } |
---|
225 | |
---|
226 | |
---|
227 | // TODO: Check this quick hack to detect clear of the screen. |
---|
228 | ///////////////////////////////////////////////////////////////// |
---|
229 | // Clear: catch up when the screen get clear to be able to |
---|
230 | // forget bar caracter not in use anymore and reuse the |
---|
231 | // slot for another bar caracter. |
---|
232 | // |
---|
233 | void MtxOrb_clear() |
---|
234 | { |
---|
235 | // REMOVE: fprintf(stderr, "GLU: MtxOrb_clear.\n"); |
---|
236 | drv_base_clear(); |
---|
237 | clear=1; |
---|
238 | } |
---|
239 | |
---|
240 | |
---|
241 | ///////////////////////////////////////////////////////////////// |
---|
242 | // Clean-up |
---|
243 | // |
---|
244 | void MtxOrb_close() |
---|
245 | { |
---|
246 | close (fd); |
---|
247 | |
---|
248 | if(MtxOrb->framebuf) free(MtxOrb->framebuf); |
---|
249 | |
---|
250 | MtxOrb->framebuf = NULL; |
---|
251 | } |
---|
252 | |
---|
253 | |
---|
254 | void MtxOrb_flush() |
---|
255 | { |
---|
256 | MtxOrb_draw_frame(lcd.framebuf); |
---|
257 | } |
---|
258 | |
---|
259 | |
---|
260 | void MtxOrb_flush_box(int lft, int top, int rgt, int bot) |
---|
261 | { |
---|
262 | int y; |
---|
263 | char out[LCD_MAX_WIDTH]; |
---|
264 | |
---|
265 | |
---|
266 | // printf("Flush (%i,%i)-(%i,%i)\n", lft, top, rgt, bot); |
---|
267 | |
---|
268 | for(y=top; y<=bot; y++) |
---|
269 | { |
---|
270 | sprintf(out, "%cG%c%c", 254, lft, y); |
---|
271 | write(fd, out, 4); |
---|
272 | write(fd, lcd.framebuf+(y*lcd.wid)+lft, rgt-lft+1); |
---|
273 | |
---|
274 | } |
---|
275 | |
---|
276 | |
---|
277 | } |
---|
278 | |
---|
279 | |
---|
280 | ///////////////////////////////////////////////////////////////// |
---|
281 | // Prints a character on the lcd display, at position (x,y). The |
---|
282 | // upper-left is (1,1), and the lower right should be (20,4). |
---|
283 | // |
---|
284 | void MtxOrb_chr(int x, int y, char c) |
---|
285 | { |
---|
286 | y--; |
---|
287 | x--; |
---|
288 | |
---|
289 | lcd.framebuf[(y*lcd.wid) + x] = c; |
---|
290 | } |
---|
291 | |
---|
292 | |
---|
293 | ///////////////////////////////////////////////////////////////// |
---|
294 | // Changes screen contrast (0-255; 140 seems good) |
---|
295 | // |
---|
296 | int MtxOrb_contrast(int contrast) |
---|
297 | { |
---|
298 | char out[4]; |
---|
299 | static int status=140; |
---|
300 | |
---|
301 | if(contrast > 0) |
---|
302 | { |
---|
303 | status=contrast; |
---|
304 | sprintf(out, "%cP%c", 254, status); |
---|
305 | write(fd, out, 3); |
---|
306 | } |
---|
307 | |
---|
308 | return status; |
---|
309 | } |
---|
310 | |
---|
311 | |
---|
312 | ///////////////////////////////////////////////////////////////// |
---|
313 | // Sets the backlight on or off -- can be done quickly for |
---|
314 | // an intermediate brightness... |
---|
315 | // |
---|
316 | void MtxOrb_backlight(int on) |
---|
317 | { |
---|
318 | char out[4]; |
---|
319 | if(on) |
---|
320 | { |
---|
321 | sprintf(out, "%cB%c", 254, 0); |
---|
322 | write(fd, out, 3); |
---|
323 | } |
---|
324 | else |
---|
325 | { |
---|
326 | sprintf(out, "%cF", 254); |
---|
327 | write(fd, out, 2); |
---|
328 | } |
---|
329 | } |
---|
330 | |
---|
331 | |
---|
332 | ///////////////////////////////////////////////////////////////// |
---|
333 | // Sets output port on or off |
---|
334 | void MtxOrb_output(int on) |
---|
335 | { |
---|
336 | char out[4]; |
---|
337 | if(on) |
---|
338 | { |
---|
339 | sprintf(out, "%cW", 254); |
---|
340 | write(fd, out, 2); |
---|
341 | } |
---|
342 | else |
---|
343 | { |
---|
344 | sprintf(out, "%cV", 254); |
---|
345 | write(fd, out, 2); |
---|
346 | } |
---|
347 | } |
---|
348 | |
---|
349 | |
---|
350 | ///////////////////////////////////////////////////////////////// |
---|
351 | // Toggle the built-in linewrapping feature |
---|
352 | // |
---|
353 | static void MtxOrb_linewrap(int on) |
---|
354 | { |
---|
355 | char out[4]; |
---|
356 | if(on) |
---|
357 | sprintf(out, "%cC", 254); |
---|
358 | else |
---|
359 | sprintf(out, "%cD", 254); |
---|
360 | write(fd, out, 2); |
---|
361 | } |
---|
362 | |
---|
363 | |
---|
364 | ///////////////////////////////////////////////////////////////// |
---|
365 | // Toggle the built-in automatic scrolling feature |
---|
366 | // |
---|
367 | static void MtxOrb_autoscroll(int on) |
---|
368 | { |
---|
369 | char out[4]; |
---|
370 | if(on) |
---|
371 | sprintf(out, "%cQ", 254); |
---|
372 | else |
---|
373 | sprintf(out, "%cR", 254); |
---|
374 | write(fd, out, 2); |
---|
375 | } |
---|
376 | |
---|
377 | |
---|
378 | // TODO: make sure this doesn't mess up non-VFD displays |
---|
379 | ///////////////////////////////////////////////////////////////// |
---|
380 | // Toggle cursor blink on/off |
---|
381 | // |
---|
382 | static void MtxOrb_cursorblink(int on) |
---|
383 | { |
---|
384 | char out[4]; |
---|
385 | if (on) |
---|
386 | sprintf(out, "%cS", 254); |
---|
387 | else |
---|
388 | sprintf(out, "%cT", 254); |
---|
389 | write(fd, out, 2); |
---|
390 | } |
---|
391 | |
---|
392 | |
---|
393 | //// TODO: Might not be needed anymore... |
---|
394 | ///////////////////////////////////////////////////////////////// |
---|
395 | // Sets up for vertical bars. Call before lcd.vbar() |
---|
396 | // |
---|
397 | void MtxOrb_init_vbar() |
---|
398 | { |
---|
399 | MtxOrb_init_all(vbar); |
---|
400 | } |
---|
401 | |
---|
402 | // TODO: Might not be needed anymore... |
---|
403 | ///////////////////////////////////////////////////////////////// |
---|
404 | // Inits horizontal bars... |
---|
405 | // |
---|
406 | void MtxOrb_init_hbar() |
---|
407 | { |
---|
408 | MtxOrb_init_all(hbar); |
---|
409 | } |
---|
410 | |
---|
411 | // TODO: Finish the support for bar growing reverse way. |
---|
412 | // TODO: Need a "y" as input also !!! |
---|
413 | ///////////////////////////////////////////////////////////////// |
---|
414 | // Draws a vertical bar... |
---|
415 | // This is the new version ussing dynamic icon alocation |
---|
416 | // |
---|
417 | void MtxOrb_vbar(int x, int len) |
---|
418 | { |
---|
419 | unsigned char mapu[9]={barw,baru1,baru2,baru3,baru4,baru5,baru6,baru7,barb}; |
---|
420 | unsigned char mapd[9]={barw,bard1,bard2,bard3,bard4,bard5,bard6,bard7,barb}; |
---|
421 | |
---|
422 | int y; |
---|
423 | |
---|
424 | // TODO: REMOVE THE NEXT LINE FOR TESTING ONLY... |
---|
425 | // len=-len; |
---|
426 | // TODO: REMOVE THE PREVIOUS LINE FOR TESTING ONLY... |
---|
427 | |
---|
428 | if(len>0){ |
---|
429 | for(y=lcd.hgt; y > 0 && len>0; y--) |
---|
430 | { |
---|
431 | if(len >= lcd.cellhgt) MtxOrb_chr(x, y, 255); |
---|
432 | else MtxOrb_chr(x, y, MtxOrb_ask_bar(mapu[len])); |
---|
433 | |
---|
434 | len -= lcd.cellhgt; |
---|
435 | } |
---|
436 | }else{ |
---|
437 | len=-len; |
---|
438 | for(y=2; y <= lcd.hgt && len>0; y++) |
---|
439 | { |
---|
440 | if(len >= lcd.cellhgt) MtxOrb_chr(x, y, 255); |
---|
441 | else MtxOrb_chr(x, y, MtxOrb_ask_bar(mapd[len])); |
---|
442 | |
---|
443 | len -= lcd.cellhgt; |
---|
444 | } |
---|
445 | } |
---|
446 | |
---|
447 | } |
---|
448 | |
---|
449 | // TODO: Finish the support for bar growing reverse way. |
---|
450 | ///////////////////////////////////////////////////////////////// |
---|
451 | // Draws a horizontal bar to the right. |
---|
452 | // This is the new version ussing dynamic icon alocation |
---|
453 | // |
---|
454 | void MtxOrb_hbar(int x, int y, int len) |
---|
455 | { |
---|
456 | unsigned char mapr[6]={barw,barr1,barr2,barr3,barr4,barb}; |
---|
457 | unsigned char mapl[6]={barw,barl1,barl2,barl3,barl4,barb}; |
---|
458 | |
---|
459 | if(len>0) |
---|
460 | { |
---|
461 | for(; x<=lcd.wid && len>0; x++) |
---|
462 | { |
---|
463 | if(len >= lcd.cellwid) MtxOrb_chr(x,y,255); |
---|
464 | else MtxOrb_chr(x, y, MtxOrb_ask_bar(mapr[len])); |
---|
465 | |
---|
466 | len -= lcd.cellwid; |
---|
467 | |
---|
468 | } |
---|
469 | } |
---|
470 | else |
---|
471 | { |
---|
472 | len=-len; |
---|
473 | for(; x>0 && len>0; x--) |
---|
474 | { |
---|
475 | if(len >= lcd.cellwid) MtxOrb_chr(x,y,255); |
---|
476 | else MtxOrb_chr(x, y, MtxOrb_ask_bar(mapl[len])); |
---|
477 | |
---|
478 | len -= lcd.cellwid; |
---|
479 | |
---|
480 | } |
---|
481 | } |
---|
482 | |
---|
483 | } |
---|
484 | |
---|
485 | // TODO: Might not work, bignum is untested... an untested with dynamic bar. |
---|
486 | |
---|
487 | ///////////////////////////////////////////////////////////////// |
---|
488 | // Sets up for big numbers. |
---|
489 | // |
---|
490 | void MtxOrb_init_num() |
---|
491 | { |
---|
492 | char out[3]; |
---|
493 | if(custom!=bign) { |
---|
494 | sprintf(out, "%cn", 254); |
---|
495 | write(fd, out, 2); |
---|
496 | custom=bign; |
---|
497 | } |
---|
498 | } |
---|
499 | |
---|
500 | // TODO: Might not work, bignum is untested... an untested with dynamic bar. |
---|
501 | |
---|
502 | ///////////////////////////////////////////////////////////////// |
---|
503 | // Writes a big number. |
---|
504 | // |
---|
505 | void MtxOrb_num(int x, int num) |
---|
506 | { |
---|
507 | char out[5]; |
---|
508 | sprintf(out, "%c#%c%c", 254, x, num); |
---|
509 | write(fd, out, 4); |
---|
510 | } |
---|
511 | |
---|
512 | |
---|
513 | // TODO: This could be higly optimised if data where to be pre-computed. |
---|
514 | |
---|
515 | ///////////////////////////////////////////////////////////////// |
---|
516 | // Sets a custom character from 0-7... |
---|
517 | // |
---|
518 | // For input, values > 0 mean "on" and values <= 0 are "off". |
---|
519 | // |
---|
520 | // The input is just an array of characters... |
---|
521 | // |
---|
522 | void MtxOrb_set_char(int n, char *dat) |
---|
523 | { |
---|
524 | char out[4]; |
---|
525 | int row, col; |
---|
526 | int letter; |
---|
527 | |
---|
528 | if(n < 0 || n > 7) return; |
---|
529 | if(!dat) return; |
---|
530 | |
---|
531 | sprintf(out, "%cN%c", 254, n); |
---|
532 | write(fd, out, 3); |
---|
533 | |
---|
534 | for(row=0; row<lcd.cellhgt; row++) |
---|
535 | { |
---|
536 | letter = 0; |
---|
537 | for(col=0; col<lcd.cellwid; col++) |
---|
538 | { |
---|
539 | letter <<= 1; |
---|
540 | letter |= (dat[(row*lcd.cellwid) + col] > 0); |
---|
541 | } |
---|
542 | write(fd, &letter, 1); |
---|
543 | } |
---|
544 | } |
---|
545 | |
---|
546 | |
---|
547 | void MtxOrb_icon(int which, char dest) |
---|
548 | { |
---|
549 | char icons[3][5*8] = { |
---|
550 | { |
---|
551 | 1,1,1,1,1, // Empty Heart |
---|
552 | 1,0,1,0,1, |
---|
553 | 0,0,0,0,0, |
---|
554 | 0,0,0,0,0, |
---|
555 | 0,0,0,0,0, |
---|
556 | 1,0,0,0,1, |
---|
557 | 1,1,0,1,1, |
---|
558 | 1,1,1,1,1, |
---|
559 | }, |
---|
560 | |
---|
561 | { |
---|
562 | 1,1,1,1,1, // Filled Heart |
---|
563 | 1,0,1,0,1, |
---|
564 | 0,1,0,1,0, |
---|
565 | 0,1,1,1,0, |
---|
566 | 0,1,1,1,0, |
---|
567 | 1,0,1,0,1, |
---|
568 | 1,1,0,1,1, |
---|
569 | 1,1,1,1,1, |
---|
570 | }, |
---|
571 | |
---|
572 | { |
---|
573 | 0,0,0,0,0, // Ellipsis |
---|
574 | 0,0,0,0,0, |
---|
575 | 0,0,0,0,0, |
---|
576 | 0,0,0,0,0, |
---|
577 | 0,0,0,0,0, |
---|
578 | 0,0,0,0,0, |
---|
579 | 0,0,0,0,0, |
---|
580 | 1,0,1,0,1, |
---|
581 | }, |
---|
582 | |
---|
583 | }; |
---|
584 | |
---|
585 | if(custom==bign) custom=beat; |
---|
586 | MtxOrb_set_char(dest, &icons[which][0]); |
---|
587 | } |
---|
588 | |
---|
589 | ///////////////////////////////////////////////////////////// |
---|
590 | // Blasts a single frame onscreen, to the lcd... |
---|
591 | // |
---|
592 | // Input is a character array, sized lcd.wid*lcd.hgt |
---|
593 | // |
---|
594 | void MtxOrb_draw_frame(char *dat) |
---|
595 | { |
---|
596 | char out[LCD_MAX_WIDTH * LCD_MAX_HEIGHT]; |
---|
597 | int i; |
---|
598 | |
---|
599 | if(!dat) return; |
---|
600 | |
---|
601 | for(i=0; i<lcd.hgt; i++) |
---|
602 | { |
---|
603 | sprintf(out, "%cG%c%c", 254, 1, i+1); |
---|
604 | write(fd, out, 4); |
---|
605 | write(fd, dat+(lcd.wid*i), lcd.wid); |
---|
606 | } |
---|
607 | |
---|
608 | } |
---|
609 | |
---|
610 | |
---|
611 | |
---|
612 | ///////////////////////////////////////////////////////////// |
---|
613 | // returns one character from the keypad... |
---|
614 | // (A-Z) on success, 0 on failure... |
---|
615 | // |
---|
616 | char MtxOrb_getkey() |
---|
617 | { |
---|
618 | char in = 0; |
---|
619 | read(fd, &in, 1); |
---|
620 | return in; |
---|
621 | } |
---|
622 | |
---|
623 | void MtxOrb_led(int which, int on) |
---|
624 | { |
---|
625 | char out[4]; |
---|
626 | |
---|
627 | if(which < 0 || which > 7) return; |
---|
628 | |
---|
629 | if(!which){ |
---|
630 | if(on) |
---|
631 | sprintf(out, "%cV", 254); |
---|
632 | else |
---|
633 | sprintf(out, "%cW", 254); |
---|
634 | write(fd, out, 2); |
---|
635 | } |
---|
636 | else{ |
---|
637 | if(on) |
---|
638 | sprintf(out, "%cV%c", 254, which); |
---|
639 | else |
---|
640 | sprintf(out, "%cW%c", 254, which); |
---|
641 | write(fd, out, 3); |
---|
642 | } |
---|
643 | } |
---|
644 | |
---|
645 | |
---|
646 | ///////////////////////////////////////////////////////////////// |
---|
647 | // Ask for dynamic allocation of a custom caracter to be |
---|
648 | // a well none bar graphic. The function is suppose to |
---|
649 | // return a value between 0 and 7 but 0 is reserver for |
---|
650 | // heart beat. |
---|
651 | // This function manadge a cache of graphical caracter in use. |
---|
652 | // I really hope it is working and bug-less because it is not |
---|
653 | // completely tested, just a quick hack. |
---|
654 | // |
---|
655 | int MtxOrb_ask_bar(int type) |
---|
656 | { |
---|
657 | int i; |
---|
658 | int last_not_in_use; |
---|
659 | int pos; // 0 is icon, 1 to 7 are free, 8 is not found. |
---|
660 | // TODO: Reuse graphic caracter 0 if heartbeat is not in use. |
---|
661 | |
---|
662 | // REMOVE: fprintf(stderr, "GLU: MtxOrb_ask_bar(%d).\n", type); |
---|
663 | // Check if the screen was clear. |
---|
664 | if (clear){ // If the screen was clear then graphic caracter are not in use. |
---|
665 | //REMOVE: fprintf(stderr, "GLU: MtxOrb_ask_bar| clear was set.\n"); |
---|
666 | use[0]=1; // Heartbeat is always in use (not true but it help). |
---|
667 | for(pos=1; pos<8; pos++){ |
---|
668 | use[pos]=0; // Other are not in use. |
---|
669 | } |
---|
670 | clear=0; // We made the special treatement. |
---|
671 | }else{ |
---|
672 | // Nothing special if some caracter a curently in use (...) ? |
---|
673 | } |
---|
674 | |
---|
675 | // Search for a match with caracter already defined. |
---|
676 | pos=8; // Not found. |
---|
677 | last_not_in_use=8; // No empty slot to reuse. |
---|
678 | for(i=1; i<8; i++){ // For all but first (heartbeat). |
---|
679 | if(!use[i]) last_not_in_use=i; // New empty slot. |
---|
680 | if(def[i]==type) pos=i; // Founded (should break now). |
---|
681 | } |
---|
682 | |
---|
683 | if (pos==8){ |
---|
684 | // REMOVE: fprintf(stderr, "GLU: MtxOrb_ask_bar| not found.\n"); |
---|
685 | pos=last_not_in_use; |
---|
686 | // TODO: Best match/deep search is no more graphic caracter are available. |
---|
687 | } |
---|
688 | |
---|
689 | if (pos!=8){ // A caracter is found (Best match could solve our problem). |
---|
690 | // REMOVE: fprintf(stderr, "GLU: MtxOrb_ask_bar| found at %d.\n", pos); |
---|
691 | if(def[pos]!=type){ |
---|
692 | MtxOrb_set_known_char(pos, type); // Define a new graphic caracter. |
---|
693 | def[pos]=type; // Remember that now the caracter is available. |
---|
694 | } |
---|
695 | if (!use[pos]){ // If the caracter is no yet in use (but defined). |
---|
696 | use[pos]=1; // Remember it is in use (so protect it from re-use). |
---|
697 | } |
---|
698 | } |
---|
699 | |
---|
700 | if (pos==8) // TODO: Choose a character to approximate the graph |
---|
701 | { |
---|
702 | //pos=65; // ("A")? |
---|
703 | switch(type) |
---|
704 | { |
---|
705 | case baru1: pos='_'; break; |
---|
706 | case baru2: pos='.'; break; |
---|
707 | case baru3: pos=','; break; |
---|
708 | case baru4: pos='o'; break; |
---|
709 | case baru5: pos='o'; break; |
---|
710 | case baru6: pos='O'; break; |
---|
711 | case baru7: pos='8'; break; |
---|
712 | |
---|
713 | case bard1: pos='\''; break; |
---|
714 | case bard2: pos='"'; break; |
---|
715 | case bard3: pos='^'; break; |
---|
716 | case bard4: pos='^'; break; |
---|
717 | case bard5: pos='*'; break; |
---|
718 | case bard6: pos='O'; break; |
---|
719 | case bard7: pos='8'; break; |
---|
720 | |
---|
721 | case barr1: pos='-'; break; |
---|
722 | case barr2: pos='-'; break; |
---|
723 | case barr3: pos='='; break; |
---|
724 | case barr4: pos='='; break; |
---|
725 | |
---|
726 | case barl1: pos='-'; break; |
---|
727 | case barl2: pos='-'; break; |
---|
728 | case barl3: pos='='; break; |
---|
729 | case barl4: pos='='; break; |
---|
730 | |
---|
731 | case barw: pos=' '; break; |
---|
732 | |
---|
733 | case barb: pos=255; break; |
---|
734 | |
---|
735 | default: pos='?'; break; |
---|
736 | } |
---|
737 | } |
---|
738 | |
---|
739 | return(pos); |
---|
740 | } |
---|
741 | |
---|
742 | |
---|
743 | ///////////////////////////////////////////////////////////////// |
---|
744 | // Sets up a well known character for use. |
---|
745 | // |
---|
746 | void MtxOrb_set_known_char(int car, int type) |
---|
747 | { |
---|
748 | char all_bar[25][5*8] = { |
---|
749 | { |
---|
750 | 0,0,0,0,0, // char u1[] = |
---|
751 | 0,0,0,0,0, |
---|
752 | 0,0,0,0,0, |
---|
753 | 0,0,0,0,0, |
---|
754 | 0,0,0,0,0, |
---|
755 | 0,0,0,0,0, |
---|
756 | 0,0,0,0,0, |
---|
757 | 1,1,1,1,1, |
---|
758 | },{ |
---|
759 | 0,0,0,0,0, // char u2[] = |
---|
760 | 0,0,0,0,0, |
---|
761 | 0,0,0,0,0, |
---|
762 | 0,0,0,0,0, |
---|
763 | 0,0,0,0,0, |
---|
764 | 0,0,0,0,0, |
---|
765 | 1,1,1,1,1, |
---|
766 | 1,1,1,1,1, |
---|
767 | },{ |
---|
768 | 0,0,0,0,0, // char u3[] = |
---|
769 | 0,0,0,0,0, |
---|
770 | 0,0,0,0,0, |
---|
771 | 0,0,0,0,0, |
---|
772 | 0,0,0,0,0, |
---|
773 | 1,1,1,1,1, |
---|
774 | 1,1,1,1,1, |
---|
775 | 1,1,1,1,1, |
---|
776 | },{ |
---|
777 | 0,0,0,0,0, // char u4[] = |
---|
778 | 0,0,0,0,0, |
---|
779 | 0,0,0,0,0, |
---|
780 | 0,0,0,0,0, |
---|
781 | 1,1,1,1,1, |
---|
782 | 1,1,1,1,1, |
---|
783 | 1,1,1,1,1, |
---|
784 | 1,1,1,1,1, |
---|
785 | },{ |
---|
786 | 0,0,0,0,0, // char u5[] = |
---|
787 | 0,0,0,0,0, |
---|
788 | 0,0,0,0,0, |
---|
789 | 1,1,1,1,1, |
---|
790 | 1,1,1,1,1, |
---|
791 | 1,1,1,1,1, |
---|
792 | 1,1,1,1,1, |
---|
793 | 1,1,1,1,1, |
---|
794 | },{ |
---|
795 | 0,0,0,0,0, // char u6[] = |
---|
796 | 0,0,0,0,0, |
---|
797 | 1,1,1,1,1, |
---|
798 | 1,1,1,1,1, |
---|
799 | 1,1,1,1,1, |
---|
800 | 1,1,1,1,1, |
---|
801 | 1,1,1,1,1, |
---|
802 | 1,1,1,1,1, |
---|
803 | },{ |
---|
804 | 0,0,0,0,0, // char u7[] = |
---|
805 | 1,1,1,1,1, |
---|
806 | 1,1,1,1,1, |
---|
807 | 1,1,1,1,1, |
---|
808 | 1,1,1,1,1, |
---|
809 | 1,1,1,1,1, |
---|
810 | 1,1,1,1,1, |
---|
811 | 1,1,1,1,1, |
---|
812 | },{ |
---|
813 | 1,1,1,1,1, // char d1[] = |
---|
814 | 0,0,0,0,0, |
---|
815 | 0,0,0,0,0, |
---|
816 | 0,0,0,0,0, |
---|
817 | 0,0,0,0,0, |
---|
818 | 0,0,0,0,0, |
---|
819 | 0,0,0,0,0, |
---|
820 | 0,0,0,0,0, |
---|
821 | },{ |
---|
822 | 1,1,1,1,1, // char d2[] = |
---|
823 | 1,1,1,1,1, |
---|
824 | 0,0,0,0,0, |
---|
825 | 0,0,0,0,0, |
---|
826 | 0,0,0,0,0, |
---|
827 | 0,0,0,0,0, |
---|
828 | 0,0,0,0,0, |
---|
829 | 0,0,0,0,0, |
---|
830 | },{ |
---|
831 | 1,1,1,1,1, // char d3[] = |
---|
832 | 1,1,1,1,1, |
---|
833 | 1,1,1,1,1, |
---|
834 | 0,0,0,0,0, |
---|
835 | 0,0,0,0,0, |
---|
836 | 0,0,0,0,0, |
---|
837 | 0,0,0,0,0, |
---|
838 | 0,0,0,0,0, |
---|
839 | },{ |
---|
840 | 1,1,1,1,1, // char d4[] = |
---|
841 | 1,1,1,1,1, |
---|
842 | 1,1,1,1,1, |
---|
843 | 1,1,1,1,1, |
---|
844 | 0,0,0,0,0, |
---|
845 | 0,0,0,0,0, |
---|
846 | 0,0,0,0,0, |
---|
847 | 0,0,0,0,0, |
---|
848 | },{ |
---|
849 | 1,1,1,1,1, // char d5[] = |
---|
850 | 1,1,1,1,1, |
---|
851 | 1,1,1,1,1, |
---|
852 | 1,1,1,1,1, |
---|
853 | 1,1,1,1,1, |
---|
854 | 0,0,0,0,0, |
---|
855 | 0,0,0,0,0, |
---|
856 | 0,0,0,0,0, |
---|
857 | },{ |
---|
858 | 1,1,1,1,1, // char d6[] = |
---|
859 | 1,1,1,1,1, |
---|
860 | 1,1,1,1,1, |
---|
861 | 1,1,1,1,1, |
---|
862 | 1,1,1,1,1, |
---|
863 | 1,1,1,1,1, |
---|
864 | 0,0,0,0,0, |
---|
865 | 0,0,0,0,0, |
---|
866 | },{ |
---|
867 | 1,1,1,1,1, // char d7[] = |
---|
868 | 1,1,1,1,1, |
---|
869 | 1,1,1,1,1, |
---|
870 | 1,1,1,1,1, |
---|
871 | 1,1,1,1,1, |
---|
872 | 1,1,1,1,1, |
---|
873 | 1,1,1,1,1, |
---|
874 | 0,0,0,0,0, |
---|
875 | },{ |
---|
876 | 1,0,0,0,0, // char r1[] = |
---|
877 | 1,0,0,0,0, |
---|
878 | 1,0,0,0,0, |
---|
879 | 1,0,0,0,0, |
---|
880 | 1,0,0,0,0, |
---|
881 | 1,0,0,0,0, |
---|
882 | 1,0,0,0,0, |
---|
883 | 1,0,0,0,0, |
---|
884 | },{ |
---|
885 | 1,1,0,0,0, // char r2[] = |
---|
886 | 1,1,0,0,0, |
---|
887 | 1,1,0,0,0, |
---|
888 | 1,1,0,0,0, |
---|
889 | 1,1,0,0,0, |
---|
890 | 1,1,0,0,0, |
---|
891 | 1,1,0,0,0, |
---|
892 | 1,1,0,0,0, |
---|
893 | },{ |
---|
894 | 1,1,1,0,0, // char r3[] = |
---|
895 | 1,1,1,0,0, |
---|
896 | 1,1,1,0,0, |
---|
897 | 1,1,1,0,0, |
---|
898 | 1,1,1,0,0, |
---|
899 | 1,1,1,0,0, |
---|
900 | 1,1,1,0,0, |
---|
901 | 1,1,1,0,0, |
---|
902 | },{ |
---|
903 | 1,1,1,1,0, // char r4[] = |
---|
904 | 1,1,1,1,0, |
---|
905 | 1,1,1,1,0, |
---|
906 | 1,1,1,1,0, |
---|
907 | 1,1,1,1,0, |
---|
908 | 1,1,1,1,0, |
---|
909 | 1,1,1,1,0, |
---|
910 | 1,1,1,1,0, |
---|
911 | },{ |
---|
912 | 0,0,0,0,1, // char l1[] = |
---|
913 | 0,0,0,0,1, |
---|
914 | 0,0,0,0,1, |
---|
915 | 0,0,0,0,1, |
---|
916 | 0,0,0,0,1, |
---|
917 | 0,0,0,0,1, |
---|
918 | 0,0,0,0,1, |
---|
919 | 0,0,0,0,1, |
---|
920 | },{ |
---|
921 | 0,0,0,1,1, // char l2[] = |
---|
922 | 0,0,0,1,1, |
---|
923 | 0,0,0,1,1, |
---|
924 | 0,0,0,1,1, |
---|
925 | 0,0,0,1,1, |
---|
926 | 0,0,0,1,1, |
---|
927 | 0,0,0,1,1, |
---|
928 | 0,0,0,1,1, |
---|
929 | },{ |
---|
930 | 0,0,1,1,1, // char l3[] = |
---|
931 | 0,0,1,1,1, |
---|
932 | 0,0,1,1,1, |
---|
933 | 0,0,1,1,1, |
---|
934 | 0,0,1,1,1, |
---|
935 | 0,0,1,1,1, |
---|
936 | 0,0,1,1,1, |
---|
937 | 0,0,1,1,1, |
---|
938 | },{ |
---|
939 | 0,1,1,1,1, // char l4[] = |
---|
940 | 0,1,1,1,1, |
---|
941 | 0,1,1,1,1, |
---|
942 | 0,1,1,1,1, |
---|
943 | 0,1,1,1,1, |
---|
944 | 0,1,1,1,1, |
---|
945 | 0,1,1,1,1, |
---|
946 | 0,1,1,1,1, |
---|
947 | },{ |
---|
948 | 1,1,1,1,1, // Empty Heart |
---|
949 | 1,0,1,0,1, |
---|
950 | 0,0,0,0,0, |
---|
951 | 0,0,0,0,0, |
---|
952 | 0,0,0,0,0, |
---|
953 | 1,0,0,0,1, |
---|
954 | 1,1,0,1,1, |
---|
955 | 1,1,1,1,1, |
---|
956 | },{ |
---|
957 | 1,1,1,1,1, // Filled Heart |
---|
958 | 1,0,1,0,1, |
---|
959 | 0,1,0,1,0, |
---|
960 | 0,1,1,1,0, |
---|
961 | 0,1,1,1,0, |
---|
962 | 1,0,1,0,1, |
---|
963 | 1,1,0,1,1, |
---|
964 | 1,1,1,1,1, |
---|
965 | },{ |
---|
966 | 0,0,0,0,0, // Ellipsis |
---|
967 | 0,0,0,0,0, |
---|
968 | 0,0,0,0,0, |
---|
969 | 0,0,0,0,0, |
---|
970 | 0,0,0,0,0, |
---|
971 | 0,0,0,0,0, |
---|
972 | 0,0,0,0,0, |
---|
973 | 1,0,1,0,1, |
---|
974 | } |
---|
975 | }; |
---|
976 | |
---|
977 | MtxOrb_set_char(car, &all_bar[type][0]); |
---|
978 | } |
---|
979 | |
---|
980 | |
---|
981 | |
---|
982 | /////////////////STOP READING --- TRASH IS AT THE END//////////////// |
---|
983 | |
---|
984 | |
---|
985 | |
---|
986 | // TODO: Remove this code wich was use for developpement. |
---|
987 | // PS: There might be reference to this code left, so keep it for some time. |
---|
988 | void MtxOrb_init_all(int type) |
---|
989 | { |
---|
990 | } |
---|
991 | |
---|
992 | // TODO: Remove this code wich was use for developpement. |
---|
993 | // PS: That was the code to define unidirectionnal [h|v]bar. |
---|
994 | /* |
---|
995 | if(type==hbar){ |
---|
996 | if(custom!=hbar) { |
---|
997 | MtxOrb_set_known_char(1, barr1); |
---|
998 | MtxOrb_set_known_char(2, barr2); |
---|
999 | MtxOrb_set_known_char(3, barr3); |
---|
1000 | MtxOrb_set_known_char(4, barr4); |
---|
1001 | custom=hbar; |
---|
1002 | } |
---|
1003 | } |
---|
1004 | |
---|
1005 | if(type==vbar){ |
---|
1006 | if(custom!=vbar) { |
---|
1007 | MtxOrb_set_known_char(1, baru1); |
---|
1008 | MtxOrb_set_known_char(2, baru2); |
---|
1009 | MtxOrb_set_known_char(3, baru3); |
---|
1010 | MtxOrb_set_known_char(4, baru4); |
---|
1011 | MtxOrb_set_known_char(5, baru5); |
---|
1012 | MtxOrb_set_known_char(6, baru6); |
---|
1013 | MtxOrb_set_known_char(7, baru7); |
---|
1014 | custom=vbar; |
---|
1015 | } |
---|
1016 | } |
---|
1017 | */ |
---|
1018 | |
---|
1019 | |
---|
1020 | // TODO: Remove this code wich was use for developpement. |
---|
1021 | // PS: It was a good idea, but not working (fixing take to much time). |
---|
1022 | /* |
---|
1023 | void MtxOrb_icon(int which, char dest) |
---|
1024 | { |
---|
1025 | if(custom==bign) custom=beat; |
---|
1026 | MtxOrb_set_known_char(dest, which+21); |
---|
1027 | } |
---|
1028 | */ |
---|
1029 | |
---|
1030 | |
---|
1031 | // TODO: Remove this code wich was use for developpement. |
---|
1032 | // PS: Temporary code used durring developpement of dynamic bar. |
---|
1033 | /* |
---|
1034 | if(type==barr1)return(1); |
---|
1035 | if(type==barr2)return(2); |
---|
1036 | if(type==barr3)return(3); |
---|
1037 | if(type==barr4)return(4); |
---|
1038 | if(type==baru1)return(1); |
---|
1039 | if(type==baru2)return(2); |
---|
1040 | if(type==baru3)return(3); |
---|
1041 | if(type==baru4)return(4); |
---|
1042 | if(type==baru5)return(5); |
---|
1043 | if(type==baru6)return(6); |
---|
1044 | if(type==baru7)return(7); |
---|
1045 | */ |
---|
1046 | |
---|
1047 | |
---|