Base: LCDproc 0.5.2
[lcdproc-de200c.git] / server / drivers / CFontz633.c
blob9b7e682c66fd03c7f7677ff5d9c7fb560496f407
1 /* This is the LCDproc driver for CrystalFontz 633 devices
2 (get yours from http://crystalfontz.com)
4 Copyright (C) 2002 David GLAUDE
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 */
22 * Driver status
23 * 04/04/2002: Working driver
24 * 05/06/2002: Reading of return value
25 * 02/09/2002: KeyPad handling and return string
26 * 03/09/2002: New icon incorporated
28 * THINGS NOT DONE:
29 * + No checking if right hardware is connected (firmware/hardware)
30 * + No BigNum (but screen is too small ???)
31 * + No support for multiple instance (require private structure)
32 * + No cache of custom char usage (like in MtxOrb)
34 * THINGS DONE:
35 * + Stopping the live reporting (of temperature)
36 * + Stopping the reporting of temp and fan (is it necessary after reboot)
37 * + Use of library for hbar and vbar (good but library could be better)
38 * + Support for keypad (Using a KeyRing)
40 * THINGS TO DO:
41 * + Make the caching at least for heartbeat icon
42 * + Create and use the library (for custom char handling)
46 #include <stdlib.h>
47 #include <stdio.h>
48 #include <unistd.h>
49 #include <termios.h>
50 #include <fcntl.h>
51 #include <string.h>
52 #include <errno.h>
53 #include <syslog.h>
55 #ifdef HAVE_CONFIG_H
56 # include "config.h"
57 #endif
59 #include "lcd.h"
60 #include "CFontz633.h"
61 #include "CFontz633io.h"
62 #include "report.h"
63 #include "lcd_lib.h"
64 #include "adv_bignum.h"
66 #define CF633_KEY_UP 1
67 #define CF633_KEY_DOWN 2
68 #define CF633_KEY_LEFT 3
69 #define CF633_KEY_RIGHT 4
70 #define CF633_KEY_ENTER 5
71 #define CF633_KEY_ESCAPE 6
74 /* Constants for userdefchar_mode */
75 #define NUM_CCs 8 /* max. number of custom characters */
77 typedef enum {
78 standard, /* only char 0 is used for heartbeat */
79 vbar, /* vertical bars */
80 hbar, /* horizontal bars */
81 custom, /* custom settings */
82 bignum, /* big numbers */
83 bigchar /* big characters */
84 } CGmode;
87 typedef struct driver_private_data {
88 char device[200];
90 int fd;
92 int model;
93 int newfirmware;
94 int usb;
95 int speed;
97 /* dimensions */
98 int width, height;
99 int cellwidth, cellheight;
101 /* framebuffer and buffer for old LCD contents */
102 unsigned char *framebuf;
103 unsigned char *backingstore;
105 /* defineable characters */
106 CGmode ccmode;
108 int contrast;
109 int brightness;
110 int offbrightness;
111 } PrivateData;
114 /* Vars for the server core */
115 MODULE_EXPORT char *api_version = API_VERSION;
116 MODULE_EXPORT int stay_in_foreground = 0;
117 MODULE_EXPORT int supports_multiple = 0;
118 MODULE_EXPORT char *symbol_prefix = "CFontz633_";
120 /* Internal functions */
121 /* static void CFontz633_linewrap (int on); */
122 /* static void CFontz633_autoscroll (int on); */
123 static void CFontz633_hidecursor (Driver *drvthis);
124 static void CFontz633_reboot (Driver *drvthis);
125 static void CFontz633_no_live_report (Driver *drvthis);
126 static void CFontz633_hardware_clear (Driver *drvthis);
130 * Initialize the driver.
131 * \param drvthis Pointer to driver structure.
132 * \retval 0 Success.
133 * \retval <0 Error.
135 MODULE_EXPORT int
136 CFontz633_init (Driver *drvthis)
138 struct termios portset;
139 int tmp, w, h;
140 int reboot = 0;
141 char size[200] = DEFAULT_SIZE;
143 PrivateData *p;
145 /* Allocate and store private data */
146 p = (PrivateData *) calloc(1, sizeof(PrivateData));
147 if (p == NULL)
148 return -1;
149 if (drvthis->store_private_ptr(drvthis, p))
150 return -1;
152 /* Initialize the PrivateData structure */
153 p->fd = -1;
154 p->cellwidth = DEFAULT_CELL_WIDTH;
155 p->cellheight = DEFAULT_CELL_HEIGHT;
156 p->ccmode = standard;
158 debug(RPT_INFO, "%s(%p)", __FUNCTION__, drvthis);
160 EmptyKeyRing(&keyring);
161 EmptyReceiveBuffer(&receivebuffer);
163 /* Read config file */
164 /* Which device should be used */
165 strncpy(p->device, drvthis->config_get_string(drvthis->name, "Device", 0, DEFAULT_DEVICE), sizeof(p->device));
166 p->device[sizeof(p->device)-1] = '\0';
167 report(RPT_INFO, "%s: using Device %s", drvthis->name, p->device);
169 /* Which size */
170 strncpy(size, drvthis->config_get_string(drvthis->name, "Size", 0, DEFAULT_SIZE), sizeof(size));
171 size[sizeof(size)-1] = '\0';
172 if ((sscanf(size, "%dx%d", &w, &h) != 2)
173 || (w <= 0) || (w > LCD_MAX_WIDTH)
174 || (h <= 0) || (h > LCD_MAX_HEIGHT)) {
175 report(RPT_WARNING, "%s: cannot parse Size: %s; using default %s",
176 drvthis->name, size, DEFAULT_SIZE);
177 sscanf(DEFAULT_SIZE, "%dx%d", &w, &h);
179 p->width = w;
180 p->height = h;
182 /* Which contrast */
183 tmp = drvthis->config_get_int(drvthis->name, "Contrast", 0, DEFAULT_CONTRAST);
184 if ((tmp < 0) || (tmp > 1000)) {
185 report(RPT_WARNING, "%s: Contrast must be between 0 and 1000; using default %d",
186 drvthis->name, DEFAULT_CONTRAST);
187 tmp = DEFAULT_CONTRAST;
189 p->contrast = tmp;
191 /* Which backlight brightness */
192 tmp = drvthis->config_get_int(drvthis->name, "Brightness", 0, DEFAULT_BRIGHTNESS);
193 if ((tmp < 0) || (tmp > 1000)) {
194 report(RPT_WARNING, "%s: Brightness must be between 0 and 1000; using default %d",
195 drvthis->name, DEFAULT_BRIGHTNESS);
196 tmp = DEFAULT_BRIGHTNESS;
198 p->brightness = tmp;
200 /* Which backlight-off "brightness" */
201 tmp = drvthis->config_get_int(drvthis->name, "OffBrightness", 0, DEFAULT_OFFBRIGHTNESS);
202 if ((tmp < 0) || (tmp > 1000)) {
203 report(RPT_WARNING, "%s: OffBrightness must be between 0 and 1000; using default %d",
204 drvthis->name, DEFAULT_OFFBRIGHTNESS);
205 tmp = DEFAULT_OFFBRIGHTNESS;
207 p->offbrightness = tmp;
209 /* Which speed */
210 tmp = drvthis->config_get_int(drvthis->name, "Speed", 0, DEFAULT_SPEED);
211 if ((tmp != 1200) && (tmp != 2400) && (tmp != 9600) && (tmp != 19200) && (tmp != 115200)) {
212 report(RPT_WARNING, "%s: Speed must be 1200, 2400, 9600, 19200 or 115200; using default %d",
213 drvthis->name, DEFAULT_SPEED);
214 tmp = DEFAULT_SPEED;
216 if (tmp == 1200) p->speed = B1200;
217 else if (tmp == 2400) p->speed = B2400;
218 else if (tmp == 9600) p->speed = B9600;
219 else if (tmp == 19200) p->speed = B19200;
220 else if (tmp == 115200) p->speed = B115200;
222 /* New firmware version?
223 * I will try to behave differently for firmware 0.6 or above.
224 * Currently this is not in use.
226 p->newfirmware = drvthis->config_get_bool(drvthis->name, "NewFirmware", 0, 0);
228 /* Reboot display? */
229 reboot = drvthis->config_get_bool(drvthis->name, "Reboot", 0, 0);
231 /* Am I USB or not? */
232 p->usb = drvthis->config_get_bool(drvthis->name, "USB", 0, 0);
234 /* Set up io port correctly, and open it... */
235 debug(RPT_DEBUG, "%s: Opening device: %s", __FUNCTION__, p->device);
236 p->fd = open(p->device, (p->usb) ? (O_RDWR | O_NOCTTY) : (O_RDWR | O_NOCTTY | O_NDELAY));
237 if (p->fd == -1) {
238 report(RPT_ERR, "%s: open(%s) failed (%s)", drvthis->name, p->device, strerror(errno));
239 return -1;
242 tcgetattr(p->fd, &portset);
244 /* We use RAW mode */
245 if (p->usb) {
246 // The USB way
247 portset.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP
248 | INLCR | IGNCR | ICRNL | IXON );
249 portset.c_oflag &= ~OPOST;
250 portset.c_lflag &= ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN );
251 portset.c_cflag &= ~( CSIZE | PARENB | CRTSCTS );
252 portset.c_cflag |= CS8 | CREAD | CLOCAL;
253 portset.c_cc[VMIN] = 0;
254 portset.c_cc[VTIME] = 0;
255 } else {
256 #ifdef HAVE_CFMAKERAW
257 /* The easy way */
258 cfmakeraw(&portset);
259 #else
260 /* The hard way */
261 portset.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP
262 | INLCR | IGNCR | ICRNL | IXON );
263 portset.c_oflag &= ~OPOST;
264 portset.c_lflag &= ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN );
265 portset.c_cflag &= ~( CSIZE | PARENB | CRTSCTS );
266 portset.c_cflag |= CS8 | CREAD | CLOCAL;
267 #endif
270 /* Set port speed */
271 cfsetospeed(&portset, p->speed);
272 cfsetispeed(&portset, B0);
274 /* Do it... */
275 tcsetattr(p->fd, TCSANOW, &portset);
277 /* make sure the frame buffer is there... */
278 p->framebuf = (unsigned char *) malloc(p->width * p->height);
279 if (p->framebuf == NULL) {
280 report(RPT_ERR, "%s: unable to create framebuffer", drvthis->name);
281 return -1;
283 memset(p->framebuf, ' ', p->width * p->height);
285 /* make sure the framebuffer backing store is there... */
286 p->backingstore = (unsigned char *) malloc(p->width * p->height);
287 if (p->backingstore == NULL) {
288 report(RPT_ERR, "%s: unable to create framebuffer backing store", drvthis->name);
289 return -1;
291 memset(p->backingstore, ' ', p->width * p->height);
293 /* Set display-specific stuff.. */
294 if (reboot) {
295 report(RPT_INFO, "%s: rebooting LCD...", drvthis->name);
296 CFontz633_reboot(drvthis);
297 reboot = 0;
300 CFontz633_hidecursor(drvthis);
302 CFontz633_set_contrast(drvthis, p->contrast);
303 CFontz633_no_live_report(drvthis);
304 CFontz633_hardware_clear(drvthis);
306 report(RPT_DEBUG, "%s: init() done", drvthis->name);
308 return 0;
313 * Close the driver (do necessary clean-up).
314 * \param drvthis Pointer to driver structure.
316 MODULE_EXPORT void
317 CFontz633_close (Driver *drvthis)
319 PrivateData *p = drvthis->private_data;
321 if (p != NULL) {
322 if (p->fd >= 0)
323 close(p->fd);
325 if (p->framebuf)
326 free(p->framebuf);
327 p->framebuf = NULL;
329 if (p->backingstore)
330 free(p->backingstore);
331 p->backingstore = NULL;
333 free(p);
335 drvthis->store_private_ptr(drvthis, NULL);
340 * Return the display width in characters.
341 * \param drvthis Pointer to driver structure.
342 * \return Number of characters the display is wide.
344 MODULE_EXPORT int
345 CFontz633_width (Driver *drvthis)
347 PrivateData *p = drvthis->private_data;
349 return p->width;
354 * Return the display height in characters.
355 * \param drvthis Pointer to driver structure.
356 * \return Number of characters the display is high.
358 MODULE_EXPORT int
359 CFontz633_height (Driver *drvthis)
361 PrivateData *p = drvthis->private_data;
363 return p->height;
368 * Return the width of a character in pixels.
369 * \param drvthis Pointer to driver structure.
370 * \return Number of pixel columns a character cell is wide.
372 MODULE_EXPORT int
373 CFontz633_cellwidth (Driver *drvthis)
375 PrivateData *p = drvthis->private_data;
377 return p->cellwidth;
382 * Return the height of a character in pixels.
383 * \param drvthis Pointer to driver structure.
384 * \return Number of pixel lines a character cell is high.
386 MODULE_EXPORT int
387 CFontz633_cellheight (Driver *drvthis)
389 PrivateData *p = drvthis->private_data;
391 return p->cellheight;
396 * Flush data on screen to the LCD.
397 * \param drvthis Pointer to driver structure.
399 MODULE_EXPORT void
400 CFontz633_flush (Driver *drvthis)
402 PrivateData *p = drvthis->private_data;
403 int i;
405 #if defined(CF635_FLUSH)
406 int len = p->width * p->height;
407 unsigned char out[3];
409 for (i = 0; i < len; i++) {
410 if (p->framebuf[i] != p->backingstore[i]) {
411 out[0] = (unsigned char) (i % p->width); // column
412 out[1] = (unsigned char) (i / p->width); // line
413 out[2] = p->framebuf[i]; // character
414 send_bytes_message(p->fd, CF633_Send_Data_to_LCD, 3, out);
415 p->backingstore[i] = p->framebuf[i];
418 #else
420 * We don't use delta update yet.
421 * It is possible but not easy, we can only update a line, full or begining.
423 unsigned char *xp = p->framebuf;
424 unsigned char *xq = p->backingstore;
426 for (i = 0; i < p->width; i++) {
427 if (*xp++ != *xq++) {
428 send_bytes_message(p->fd, CF633_Set_LCD_Contents_Line_One, 16, p->framebuf);
429 memcpy(p->backingstore, p->framebuf, p->width);
430 break;
434 xp = p->framebuf + p->width;
435 xq = p->backingstore + p->width;
437 for (i = 0; i < p->width; i++) {
438 if (*xp++ != *xq++) {
439 send_bytes_message(p->fd, CF633_Set_LCD_Contents_Line_Two, 16, p->framebuf + p->width);
440 memcpy(p->backingstore + p->width, p->framebuf + p->width, p->width);
441 break;
444 #endif /* defined(CF635_FLUSH) */
449 * Get next key from the KeyRing.
450 * \param drvthis Pointer to driver structure.
451 * \return String representation of the key.
453 MODULE_EXPORT const char *
454 CFontz633_get_key (Driver *drvthis)
456 // PrivateData *p = drvthis->private_data;
457 unsigned char key = GetKeyFromKeyRing(&keyring);
459 switch (key) {
460 case CF633_KEY_LEFT:
461 return "Left";
462 break;
463 case CF633_KEY_UP:
464 return "Up";
465 break;
466 case CF633_KEY_DOWN:
467 return "Down";
468 break;
469 case CF633_KEY_RIGHT:
470 return "Right";
471 break;
472 case CF633_KEY_ENTER:
473 return "Enter"; /* Is this correct ? */
474 break;
475 case CF633_KEY_ESCAPE:
476 return "Escape";
477 break;
478 default:
479 if (key != '\0')
480 report(RPT_INFO, "%s: Untreated key 0x%02X", drvthis->name, key);
481 return NULL;
482 break;
484 return NULL;
489 * Print a character on the screen at position (x,y).
490 * The upper-left corner is (1,1), the lower-right corner is (p->width, p->height).
491 * \param drvthis Pointer to driver structure.
492 * \param x Horizontal character position (column).
493 * \param y Vertical character position (row).
494 * \param c Character that gets written.
496 MODULE_EXPORT void
497 CFontz633_chr (Driver *drvthis, int x, int y, char c)
499 PrivateData *p = drvthis->private_data;
501 y--;
502 x--;
504 if ((x >= 0) && (y >= 0) && (x < p->width) && (y < p->height))
505 p->framebuf[(y * p->width) + x] = c;
510 * Get current LCD contrast.
511 * This is only the locally stored contrast, the contrast value
512 * cannot be retrieved from the LCD.
513 * \param drvthis Pointer to driver structure.
514 * \return Stored contrast in promille.
516 MODULE_EXPORT int
517 CFontz633_get_contrast (Driver *drvthis)
519 PrivateData *p = drvthis->private_data;
521 return p->contrast;
526 * Change LCD contrast.
527 * \param drvthis Pointer to driver structure.
528 * \param promille New contrast value in promille.
530 MODULE_EXPORT void
531 CFontz633_set_contrast (Driver *drvthis, int promille)
533 PrivateData *p = drvthis->private_data;
534 int hardware_contrast;
536 /* Check it */
537 if (promille < 0 || promille > 1000)
538 return;
540 /* store the software value since there is not get */
541 p->contrast = promille;
543 /* map range [0, 1000] -> [0, 50] that the hardware understands */
544 hardware_contrast = p->contrast / 20;
545 send_onebyte_message(p->fd, CF633_Set_LCD_Contrast, hardware_contrast);
550 * Retrieve brightness.
551 * \param drvthis Pointer to driver structure.
552 * \param state Brightness state (on/off) for which we want the value.
553 * \return Stored brightness in promille.
555 MODULE_EXPORT int
556 CFontz633_get_brightness(Driver *drvthis, int state)
558 PrivateData *p = drvthis->private_data;
560 return (state == BACKLIGHT_ON) ? p->brightness : p->offbrightness;
565 * Set on/off brightness.
566 * \param drvthis Pointer to driver structure.
567 * \param state Brightness state (on/off) for which we want to store the value.
568 * \param promille New brightness in promille.
570 MODULE_EXPORT void
571 CFontz633_set_brightness(Driver *drvthis, int state, int promille)
573 PrivateData *p = drvthis->private_data;
575 /* Check it */
576 if (promille < 0 || promille > 1000)
577 return;
579 /* store the software value since there is not get */
580 if (state == BACKLIGHT_ON) {
581 p->brightness = promille;
582 //CFontz633_backlight(drvthis, BACKLIGHT_ON);
584 else {
585 p->offbrightness = promille;
586 //CFontz633_backlight(drvthis, BACKLIGHT_OFF);
592 * Turn the LCD backlight on or off.
593 * \param drvthis Pointer to driver structure.
594 * \param on New backlight status.
596 MODULE_EXPORT void
597 CFontz633_backlight (Driver *drvthis, int on)
599 PrivateData *p = drvthis->private_data;
600 int hardware_value = (on == BACKLIGHT_ON)
601 ? p->brightness
602 : p->offbrightness;
604 /* map range [0, 1000] -> [0, 100] that the hardware understands */
605 hardware_value /= 10;
606 send_onebyte_message(p->fd, CF633_Set_LCD_And_Keypad_Backlight, hardware_value);
611 * Get rid of the blinking cursor.
612 * \param drvthis Pointer to driver structure.
614 static void
615 CFontz633_hidecursor (Driver *drvthis)
617 PrivateData *p = drvthis->private_data;
619 send_onebyte_message(p->fd, CF633_Set_LCD_Cursor_Style, 0);
624 * Stop live reporting of temperature.
625 * \param drvthis Pointer to driver structure.
627 static void
628 CFontz633_no_live_report (Driver *drvthis)
630 PrivateData *p = drvthis->private_data;
631 unsigned char out[2] = { 0, 0 };
633 for (out[0] = 0; out[0] < 8; out[0]++) {
634 send_bytes_message(p->fd, CF633_Set_Up_Live_Fan_or_Temperature_Display, 2, out);
640 * Stop the reporting of any fan.
641 * \param drvthis Pointer to driver structure.
643 static void
644 CFontz633_no_fan_report (Driver *drvthis)
646 PrivateData *p = drvthis->private_data;
648 send_onebyte_message(p->fd, CF633_Set_Up_Fan_Reporting, 0);
653 * Stop the reporting of any temperature.
654 * \param drvthis Pointer to driver structure.
656 static void
657 CFontz633_no_temp_report (Driver *drvthis)
659 PrivateData *p = drvthis->private_data;
660 unsigned char out[4] = { 0, 0, 0, 0 };
662 send_bytes_message(p->fd, CF633_Set_Up_Temperature_Reporting, 4, out);
667 * Reset the LCD display.
668 * \param drvthis Pointer to driver structure.
670 static void
671 CFontz633_reboot (Driver *drvthis)
673 PrivateData *p = drvthis->private_data;
674 unsigned char out[3] = { 8, 18, 99 };
676 send_bytes_message(p->fd, CF633_Reboot, 3, out);
677 sleep(2);
682 * Draw a vertical bar bottom-up.
683 * \param drvthis Pointer to driver structure.
684 * \param x Horizontal character position (column) of the starting point.
685 * \param y Vertical character position (row) of the starting point.
686 * \param len Number of characters that the bar is high at 100%
687 * \param promille Current height level of the bar in promille.
688 * \param options Options (currently unused).
690 MODULE_EXPORT void
691 CFontz633_vbar (Driver *drvthis, int x, int y, int len, int promille, int options)
693 PrivateData *p = drvthis->private_data;
695 if (p->ccmode != vbar) {
696 unsigned char vBar[p->cellheight];
697 int i;
699 if (p->ccmode != standard) {
700 /* Not supported(yet) */
701 report(RPT_WARNING, "%s: vbar: cannot combine two modes using user-defined characters",
702 drvthis->name);
703 return;
705 p->ccmode = vbar;
707 memset(vBar, 0x00, sizeof(vBar));
709 for (i = 1; i < p->cellheight; i++) {
710 // add pixel line per pixel line ...
711 vBar[p->cellheight - i] = 0xFF;
712 CFontz633_set_char(drvthis, i, vBar);
716 lib_vbar_static(drvthis, x, y, len, promille, options, p->cellheight, 0);
721 * Draw a horizontal bar to the right.
722 * \param drvthis Pointer to driver structure.
723 * \param x Horizontal character position (column) of the starting point.
724 * \param y Vertical character position (row) of the starting point.
725 * \param len Number of characters that the bar is long at 100%
726 * \param promille Current length level of the bar in promille.
727 * \param options Options (currently unused).
729 MODULE_EXPORT void
730 CFontz633_hbar (Driver *drvthis, int x, int y, int len, int promille, int options)
732 PrivateData *p = drvthis->private_data;
734 if (p->ccmode != hbar) {
735 unsigned char hBar[p->cellheight];
736 int i;
738 if (p->ccmode != standard) {
739 /* Not supported(yet) */
740 report(RPT_WARNING, "%s: hbar: cannot combine two modes using user-defined characters",
741 drvthis->name);
742 return;
744 p->ccmode = hbar;
746 memset(hBar, 0x00, sizeof(hBar));
748 for (i = 1; i <= p->cellwidth; i++) {
749 // fill pixel columns from left to right.
750 memset(hBar, 0xFF & ~((1 << (p->cellwidth - i)) - 1), sizeof(hBar)-1);
751 CFontz633_set_char(drvthis, i, hBar);
755 lib_hbar_static(drvthis, x, y, len, promille, options, p->cellwidth, 0);
760 * Write a big number to the screen.
761 * \param drvthis Pointer to driver structure.
762 * \param x Horizontal character position (column).
763 * \param num Character to write (0 - 10 with 10 representing ':')
765 MODULE_EXPORT void
766 CFontz633_num(Driver *drvthis, int x, int num)
768 PrivateData *p = drvthis->private_data;
769 int do_init = 0;
771 if ((num < 0) || (num > 10))
772 return;
774 if (p->ccmode != bignum) {
775 if (p->ccmode != standard) {
776 /* Not supported (yet) */
777 report(RPT_WARNING, "%s: num: cannot combine two modes using user-defined characters",
778 drvthis->name);
779 return;
782 p->ccmode = bignum;
784 do_init = 1;
787 // Lib_adv_bignum does everything needed to show the bignumbers.
788 lib_adv_bignum(drvthis, x, num, 0, do_init);
793 * Get total number of custom characters available.
794 * \param drvthis Pointer to driver structure.
795 * \return Number of custom characters (always NUM_CCs).
797 MODULE_EXPORT int
798 CFontz633_get_free_chars (Driver *drvthis)
800 //PrivateData *p = drvthis->private_data;
802 return NUM_CCs;
807 * Define a custom character and write it to the LCD.
808 * \param drvthis Pointer to driver structure.
809 * \param n Custom character to define [0 - (NUM_CCs-1)].
810 * \param dat Array of 8(=cellheight) bytes, each representing a pixel row
811 * starting from the top to bottom.
812 * The bits in each byte represent the pixels where the LSB
813 * (least significant bit) is the rightmost pixel in each pixel row.
815 MODULE_EXPORT void
816 CFontz633_set_char (Driver *drvthis, int n, unsigned char *dat)
818 PrivateData *p = drvthis->private_data;
819 unsigned char out[9];
820 unsigned char mask = (1 << p->cellwidth) - 1;
821 int row;
823 if ((n < 0) || (n >= NUM_CCs))
824 return;
825 if (!dat)
826 return;
828 out[0] = n; /* Custom char to define. xxx */
830 for (row = 0; row < p->cellheight; row++) {
831 out[row+1] = dat[row] & mask;
833 send_bytes_message(p->fd, CF633_Set_LCD_Special_Character_Data, 9, out);
838 * Place an icon on the screen.
839 * \param drvthis Pointer to driver structure.
840 * \param x Horizontal character position (column).
841 * \param y Vertical character position (row).
842 * \param icon synbolic value representing the icon.
843 * \return Information whether the icon is handled here or needs to be handled by the server core.
845 MODULE_EXPORT int
846 CFontz633_icon (Driver *drvthis, int x, int y, int icon)
848 PrivateData *p = drvthis->private_data;
850 static unsigned char heart_open[] =
851 { b__XXXXX,
852 b__X_X_X,
853 b_______,
854 b_______,
855 b_______,
856 b__X___X,
857 b__XX_XX,
858 b__XXXXX };
859 static unsigned char heart_filled[] =
860 { b__XXXXX,
861 b__X_X_X,
862 b___X_X_,
863 b___XXX_,
864 b___XXX_,
865 b__X_X_X,
866 b__XX_XX,
867 b__XXXXX };
868 static unsigned char arrow_up[] =
869 { b____X__,
870 b___XXX_,
871 b__X_X_X,
872 b____X__,
873 b____X__,
874 b____X__,
875 b____X__,
876 b_______ };
877 static unsigned char arrow_down[] =
878 { b____X__,
879 b____X__,
880 b____X__,
881 b____X__,
882 b__X_X_X,
883 b___XXX_,
884 b____X__,
885 b_______ };
887 static unsigned char arrow_left[] =
888 { b_______,
889 b____X__,
890 b___X___,
891 b__XXXXX,
892 b___X___,
893 b____X__,
894 b_______,
895 b_______ };
896 static unsigned char arrow_right[] =
897 { b_______,
898 b____X__,
899 b_____X_,
900 b__XXXXX,
901 b_____X_,
902 b____X__,
903 b_______,
904 b_______ };
906 static unsigned char checkbox_off[] =
907 { b_______,
908 b_______,
909 b__XXXXX,
910 b__X___X,
911 b__X___X,
912 b__X___X,
913 b__XXXXX,
914 b_______ };
915 static unsigned char checkbox_on[] =
916 { b____X__,
917 b____X__,
918 b__XXX_X,
919 b__X_XX_,
920 b__X_X_X,
921 b__X___X,
922 b__XXXXX,
923 b_______ };
924 static unsigned char checkbox_gray[] =
925 { b_______,
926 b_______,
927 b__XXXXX,
928 b__X_X_X,
929 b__XX_XX,
930 b__X_X_X,
931 b__XXXXX,
932 b_______ };
934 static unsigned char selector_left[] =
935 { b___X___,
936 b___XX__,
937 b___XXX_,
938 b___XXXX,
939 b___XXX_,
940 b___XX__,
941 b___X___,
942 b_______ };
943 static unsigned char selector_right[] =
944 { b_____X_,
945 b____XX_,
946 b___XXX_,
947 b__XXXX_,
948 b___XXX_,
949 b____XX_,
950 b_____X_,
951 b_______ };
952 static unsigned char ellipsis[] =
953 { b_______,
954 b_______,
955 b_______,
956 b_______,
957 b_______,
958 b_______,
959 b__X_X_X,
960 b_______ };
961 static unsigned char block_filled[] =
962 { b__XXXXX,
963 b__XXXXX,
964 b__XXXXX,
965 b__XXXXX,
966 b__XXXXX,
967 b__XXXXX,
968 b__XXXXX,
969 b__XXXXX };
972 /* Yes we know, this is a VERY BAD implementation :-) */
973 switch (icon) {
974 case ICON_BLOCK_FILLED:
975 CFontz633_chr(drvthis, x, y, 255);
976 break;
977 case ICON_HEART_FILLED:
978 p->ccmode = custom;
979 CFontz633_set_char(drvthis, 0, heart_filled);
980 CFontz633_chr(drvthis, x, y, 0);
981 break;
982 case ICON_HEART_OPEN:
983 p->ccmode = custom;
984 CFontz633_set_char(drvthis, 0, heart_open);
985 CFontz633_chr(drvthis, x, y, 0);
986 break;
987 case ICON_ARROW_UP:
988 p->ccmode = custom;
989 CFontz633_set_char(drvthis, 1, arrow_up);
990 CFontz633_chr(drvthis, x, y, 1);
991 break;
992 case ICON_ARROW_DOWN:
993 p->ccmode = custom;
994 CFontz633_set_char(drvthis, 2, arrow_down);
995 CFontz633_chr(drvthis, x, y, 2);
996 break;
997 case ICON_ARROW_LEFT:
998 CFontz633_chr(drvthis, x, y, 0x7F);
999 break;
1000 case ICON_ARROW_RIGHT:
1001 CFontz633_chr(drvthis, x, y, 0x7E);
1002 break;
1003 case ICON_CHECKBOX_OFF:
1004 p->ccmode = custom;
1005 CFontz633_set_char(drvthis, 3, checkbox_off);
1006 CFontz633_chr(drvthis, x, y, 3);
1007 break;
1008 case ICON_CHECKBOX_ON:
1009 p->ccmode = custom;
1010 CFontz633_set_char(drvthis, 4, checkbox_on);
1011 CFontz633_chr(drvthis, x, y, 4);
1012 break;
1013 case ICON_CHECKBOX_GRAY:
1014 p->ccmode = custom;
1015 CFontz633_set_char(drvthis, 5, checkbox_gray);
1016 CFontz633_chr(drvthis, x, y, 5);
1017 break;
1018 default:
1019 return -1; /* Let the core do other icons */
1021 return 0;
1026 * Clear the screen.
1027 * \param drvthis Pointer to driver structure.
1029 MODULE_EXPORT void
1030 CFontz633_clear (Driver *drvthis)
1032 PrivateData *p = drvthis->private_data;
1034 memset(p->framebuf, ' ', p->width * p->height);
1035 p->ccmode = standard;
1040 * Clear the LCD using hardware commands.
1041 * \param drvthis Pointer to driver structure.
1043 static void
1044 CFontz633_hardware_clear (Driver *drvthis)
1046 PrivateData *p = drvthis->private_data;
1048 send_zerobyte_message(p->fd, CF633_Clear_LCD_Screen);
1053 * Print a string on the screen at position (x,y).
1054 * The upper-left corner is (1,1), the lower-right corner is (p->width, p->height).
1055 * \param drvthis Pointer to driver structure.
1056 * \param x Horizontal character position (column).
1057 * \param y Vertical character position (row).
1058 * \param string String that gets written.
1060 MODULE_EXPORT void
1061 CFontz633_string (Driver *drvthis, int x, int y, const char string[])
1063 PrivateData *p = drvthis->private_data;
1064 int i;
1066 /* Convert 1-based coords to 0-based... */
1067 x--;
1068 y--;
1070 if ((y < 0) || (y >= p->height))
1071 return;
1073 for (i = 0; (string[i] != '\0') && (x < p->width); i++, x++) {
1074 /* Check for buffer overflows... */
1075 if (x >= 0)
1076 p->framebuf[(y * p->width) + x] = string[i];