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