convert to the use of PrivateData *, harmonize with CFontzPacket.c

This commit is contained in:
marschap
2005-05-29 19:06:20 +00:00
parent 9e7c90d1ef
commit 4b4e7fc88c
+265 -198
View File
@@ -69,24 +69,49 @@
#define CF633_KEY_ENTER 5 #define CF633_KEY_ENTER 5
#define CF633_KEY_ESCAPE 6 #define CF633_KEY_ESCAPE 6
static int custom = 0;
typedef enum {
hbar = 1,
vbar = 2,
cust = 3,
} custom_type;
static int fd; /* Constants for userdefchar_mode */
static unsigned char *framebuf = NULL; #define NUM_CCs 8 /* max. number of custom characters */
static unsigned char *old = NULL;
static int width = 0; typedef enum {
static int height = 0; standard, /* only char 0 is used for heartbeat */
static int cellwidth = DEFAULT_CELL_WIDTH; vbar, /* vertical bars */
static int cellheight = DEFAULT_CELL_HEIGHT; hbar, /* horizontaln bars */
static int contrast = DEFAULT_CONTRAST; bignum, /* big numbers */
static int brightness = DEFAULT_BRIGHTNESS; bigchar /* big characters */
static int offbrightness = DEFAULT_OFFBRIGHTNESS; } CGmode;
static int newfirmware = 0;
typedef struct cgram_cache {
char cache[DEFAULT_CELL_HEIGHT];
int clean;
} CGram;
typedef struct driver_private_data {
char device[200];
int fd;
//int model;
int newfirmware;
/* dimensions */
int width, height;
int cellwidth, cellheight;
/* framebuffer and buffer for old LCD contents */
unsigned char *framebuf;
unsigned char *backingstore;
/* defineable characters */
CGram cc[NUM_CCs];
CGmode ccmode;
int contrast;
int brightness;
int offbrightness;
} PrivateData;
/* Vars for the server core */ /* Vars for the server core */
MODULE_EXPORT char *api_version = API_VERSION; MODULE_EXPORT char *api_version = API_VERSION;
@@ -115,63 +140,72 @@ CFontz633_init (Driver *drvthis, char *args)
int tmp, w, h; int tmp, w, h;
int reboot = 0; int reboot = 0;
int usb = 0; int usb = 0;
int contrast = DEFAULT_CONTRAST;
char device[200] = DEFAULT_DEVICE;
int speed = DEFAULT_SPEED; int speed = DEFAULT_SPEED;
char size[200] = DEFAULT_SIZE; char size[200] = DEFAULT_SIZE;
PrivateData *p;
/* Allocate and store private data */
p = (PrivateData *) calloc(1, sizeof(PrivateData));
if (p == NULL)
return -1;
if (drvthis->store_private_ptr(drvthis, p))
return -1;
/* Initialize the PrivateData structure */
p->cellwidth = DEFAULT_CELL_WIDTH;
p->cellheight = DEFAULT_CELL_HEIGHT;
p->ccmode = standard;
debug(RPT_INFO, "CFontz633: init(%p,%s)", drvthis, args ); debug(RPT_INFO, "CFontz633: init(%p,%s)", drvthis, args );
EmptyKeyRing(); EmptyKeyRing();
EmptyReceiveBuffer(); EmptyReceiveBuffer();
/* Read config file */ /* Read config file */
/* Which serial device should be used */ /* Which device should be used */
strncpy(device, drvthis->config_get_string ( drvthis->name , "Device" , 0 , DEFAULT_DEVICE),sizeof(device)); strncpy(p->device, drvthis->config_get_string (drvthis->name, "Device", 0, DEFAULT_DEVICE), sizeof(p->device));
device[sizeof(device)-1] = '\0'; p->device[sizeof(p->device)-1] = '\0';
debug (RPT_INFO,"CFontz633: Using device: %s", device); debug (RPT_INFO,"CFontz633: Using device: %s", p->device);
/* Which size */ /* Which size */
strncpy(size, drvthis->config_get_string ( drvthis->name , "Size" , 0 , DEFAULT_SIZE),sizeof(size)); strncpy(size, drvthis->config_get_string (drvthis->name, "Size", 0, DEFAULT_SIZE), sizeof(size));
size[sizeof(size)-1] = '\0'; size[sizeof(size)-1] = '\0';
if( sscanf(size , "%dx%d", &w, &h ) != 2 if ((sscanf(size, "%dx%d", &w, &h ) != 2)
|| (w <= 0) || (w > LCD_MAX_WIDTH) || (w <= 0) || (w > LCD_MAX_WIDTH)
|| (h <= 0) || (h > LCD_MAX_HEIGHT)) { || (h <= 0) || (h > LCD_MAX_HEIGHT)) {
report (RPT_WARNING, "CFontz633_init: Cannot read size: %s. Using default value.\n", size); report (RPT_WARNING, "CFontz633_init: Cannot read size: %s. Using default value.\n", size);
sscanf( DEFAULT_SIZE , "%dx%d", &w, &h ); sscanf( DEFAULT_SIZE, "%dx%d", &w, &h );
} else {
width = w;
height = h;
} }
p->width = w;
p->height = h;
/* Which contrast */ /* Which contrast */
if (0<=drvthis->config_get_int ( drvthis->name , "Contrast" , 0 , DEFAULT_CONTRAST) && tmp = drvthis->config_get_int (drvthis->name, "Contrast", 0, DEFAULT_CONTRAST);
drvthis->config_get_int ( drvthis->name , "Contrast" , 0 , DEFAULT_CONTRAST) <= 1000) { if ((tmp < 0) || (tmp > 1000)) {
contrast = drvthis->config_get_int ( drvthis->name , "Contrast" , 0 , DEFAULT_CONTRAST);
} else {
report (RPT_WARNING, "CFontz633_init: Contrast must be between 0 and 1000. Using default value.\n"); report (RPT_WARNING, "CFontz633_init: Contrast must be between 0 and 1000. Using default value.\n");
tmp = DEFAULT_CONTRAST;
} }
p->contrast = tmp;
/* Which backlight brightness */ /* Which backlight brightness */
if (0<=drvthis->config_get_int ( drvthis->name , "Brightness" , 0 , DEFAULT_BRIGHTNESS) && tmp = drvthis->config_get_int (drvthis->name, "Brightness", 0, DEFAULT_BRIGHTNESS);
drvthis->config_get_int ( drvthis->name , "Brightness" , 0 , DEFAULT_BRIGHTNESS) <= 100) { if ((tmp < 0) || (tmp > 100)) {
brightness = drvthis->config_get_int ( drvthis->name , "Brightness" , 0 , DEFAULT_BRIGHTNESS);
} else {
report (RPT_WARNING, "CFontz633_init: Brightness must be between 0 and 100. Using default value.\n"); report (RPT_WARNING, "CFontz633_init: Brightness must be between 0 and 100. Using default value.\n");
tmp = DEFAULT_BRIGHTNESS;
} }
p->brightness = tmp;
/* Which backlight-off "brightness" */ /* Which backlight-off "brightness" */
if (0<=drvthis->config_get_int ( drvthis->name , "OffBrightness" , 0 , DEFAULT_OFFBRIGHTNESS) && tmp = drvthis->config_get_int (drvthis->name, "OffBrightness", 0, DEFAULT_OFFBRIGHTNESS);
drvthis->config_get_int ( drvthis->name , "OffBrightness" , 0 , DEFAULT_OFFBRIGHTNESS) <= 100) { if ((tmp < 0) || (tmp > 100)) {
offbrightness = drvthis->config_get_int ( drvthis->name , "OffBrightness" , 0 , DEFAULT_OFFBRIGHTNESS);
} else {
report (RPT_WARNING, "CFontz633_init: OffBrightness must be between 0 and 100. Using default value.\n"); report (RPT_WARNING, "CFontz633_init: OffBrightness must be between 0 and 100. Using default value.\n");
tmp = DEFAULT_OFFBRIGHTNESS;
} }
p->offbrightness = tmp;
/* Which speed */ /* Which speed */
tmp = drvthis->config_get_int ( drvthis->name , "Speed" , 0 , DEFAULT_SPEED); tmp = drvthis->config_get_int (drvthis->name, "Speed", 0, DEFAULT_SPEED);
if (tmp == 1200) speed = B1200; if (tmp == 1200) speed = B1200;
else if (tmp == 2400) speed = B2400; else if (tmp == 2400) speed = B2400;
else if (tmp == 9600) speed = B9600; else if (tmp == 9600) speed = B9600;
@@ -184,30 +218,23 @@ CFontz633_init (Driver *drvthis, char *args)
* I will try to behave differently for firmware 0.6 or above. * I will try to behave differently for firmware 0.6 or above.
* Currently this is not in use. * Currently this is not in use.
*/ */
if (drvthis->config_get_bool( drvthis->name , "NewFirmware" , 0 , 0)) { p->newfirmware = drvthis->config_get_bool(drvthis->name, "NewFirmware", 0, 0);
newfirmware = 1;
}
/* Reboot display? */ /* Reboot display? */
if (drvthis->config_get_bool( drvthis->name , "Reboot" , 0 , 0)) { reboot = drvthis->config_get_bool(drvthis->name, "Reboot", 0, 0);
report (RPT_INFO, "LCDd: rebooting CrystalFontz LCD...\n");
reboot = 1;
}
/*Am I USB or not?*/ /* Am I USB or not? */
if (drvthis->config_get_bool( drvthis->name , "USB" , 0 , 0)) { usb = drvthis->config_get_bool(drvthis->name, "USB", 0, 0);
usb = 1;
}
/* Set up io port correctly, and open it... */ /* Set up io port correctly, and open it... */
debug( RPT_DEBUG, "CFontz633: Opening serial device: %s", device); debug( RPT_DEBUG, "CFontz633: Opening device: %s", p->device);
fd = open (device, (usb) ? (O_RDWR | O_NOCTTY) : (O_RDWR | O_NOCTTY | O_NDELAY)); p->fd = open(p->device, (usb) ? (O_RDWR | O_NOCTTY) : (O_RDWR | O_NOCTTY | O_NDELAY));
if (fd == -1) { if (p->fd == -1) {
report (RPT_ERR, "CFontz633_init: failed (%s)\n", strerror (errno)); report (RPT_ERR, "CFontz633_init: failed (%s)\n", strerror (errno));
return -1; return -1;
} }
tcgetattr (fd, &portset); tcgetattr (p->fd, &portset);
/* We use RAW mode */ /* We use RAW mode */
if (usb) { if (usb) {
@@ -240,33 +267,32 @@ CFontz633_init (Driver *drvthis, char *args)
cfsetispeed (&portset, B0); cfsetispeed (&portset, B0);
/* Do it... */ /* Do it... */
tcsetattr (fd, TCSANOW, &portset); tcsetattr (p->fd, TCSANOW, &portset);
/* Make sure the frame buffer is there... */ /* make sure the frame buffer is there... */
framebuf = (unsigned char *) malloc (width * height); p->framebuf = (unsigned char *) malloc(p->width * p->height);
if (framebuf == NULL) { if (p->framebuf == NULL) {
report(RPT_ERR, "CFontz633_init: unable to create framebuffer.\n"); report(RPT_ERR, "CFontz633_init: unable to create framebuffer.\n");
return -1; return -1;
} }
memset (framebuf, ' ', width * height); memset(p->framebuf, ' ', p->width * p->height);
/* make sure the framebuffer backing store is there... */ /* make sure the framebuffer backing store is there... */
old = (unsigned char *) malloc (width * height); p->backingstore = (unsigned char *) malloc(p->width * p->height);
if (old == NULL) { if (p->backingstore == NULL) {
report(RPT_ERR, "CFontz633_init: unable to create framebuffer backing store.\n"); report(RPT_ERR, "CFontz633_init: unable to create framebuffer backing store.\n");
return -1; return -1;
} }
memset (old, ' ', width * height); memset(p->backingstore, ' ', p->width * p->height);
/* Set display-specific stuff.. */ /* Set display-specific stuff.. */
if (reboot) { if (reboot) {
CFontz633_reboot (drvthis); CFontz633_reboot (drvthis);
reboot = 0; reboot = 0;
} }
sleep (2);
CFontz633_hidecursor (drvthis); CFontz633_hidecursor (drvthis);
CFontz633_set_contrast (drvthis, contrast); CFontz633_set_contrast (drvthis, p->contrast);
CFontz633_no_live_report (drvthis); CFontz633_no_live_report (drvthis);
CFontz633_hardware_clear (drvthis); CFontz633_hardware_clear (drvthis);
@@ -282,13 +308,22 @@ CFontz633_init (Driver *drvthis, char *args)
MODULE_EXPORT void MODULE_EXPORT void
CFontz633_close (Driver *drvthis) CFontz633_close (Driver *drvthis)
{ {
close (fd); PrivateData *p = drvthis->private_data;
if(framebuf) free (framebuf); if (p != NULL) {
framebuf = NULL; close(p->fd);
if(old) free (old); if (p->framebuf)
old = NULL; free(p->framebuf);
p->framebuf = NULL;
if (p->backingstore)
free(p->backingstore);
p->backingstore = NULL;
free(p);
}
drvthis->store_private_ptr(drvthis, NULL);
} }
@@ -298,11 +333,9 @@ CFontz633_close (Driver *drvthis)
MODULE_EXPORT int MODULE_EXPORT int
CFontz633_width (Driver *drvthis) CFontz633_width (Driver *drvthis)
{ {
/* PrivateData *p = drvthis->private_data;
PrivateData *p = (PrivateData *) drvthis->private_data;
return p->width; return p->width;
*/
return width;
} }
@@ -312,7 +345,9 @@ CFontz633_width (Driver *drvthis)
MODULE_EXPORT int MODULE_EXPORT int
CFontz633_height (Driver *drvthis) CFontz633_height (Driver *drvthis)
{ {
return height; PrivateData *p = drvthis->private_data;
return p->height;
} }
@@ -322,6 +357,7 @@ CFontz633_height (Driver *drvthis)
MODULE_EXPORT void MODULE_EXPORT void
CFontz633_flush (Driver *drvthis) CFontz633_flush (Driver *drvthis)
{ {
PrivateData *p = drvthis->private_data;
int i; int i;
#if defined(CF635_FLUSH) #if defined(CF635_FLUSH)
@@ -329,13 +365,13 @@ CFontz633_flush (Driver *drvthis)
char out[4]; char out[4];
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
if (framebuf[i] != old[i]) { if (p->framebuf[i] != p->backingstore[i]) {
out[1] = i / width; // line out[1] = i / width; // line
out[0] = i - (out[1] * width); // column out[0] = i - (out[1] * width); // column
out[2] = framebuf[i]; // character out[2] = p->framebuf[i]; // character
out[2] = '\0'; out[2] = '\0';
send_bytes_message(fd, 3, CF633_Send_Data_to_LCD, out); send_bytes_message(fd, 3, CF633_Send_Data_to_LCD, out);
old[i] = framebuf[i]; p->backingstore[i] = p->framebuf[i];
} }
} }
#else #else
@@ -343,28 +379,26 @@ CFontz633_flush (Driver *drvthis)
* We don't use delta update yet. * We don't use delta update yet.
* It is possible but not easy, we can only update a line, full or begining. * It is possible but not easy, we can only update a line, full or begining.
*/ */
unsigned char *xp = framebuf; unsigned char *xp = p->framebuf;
unsigned char *xq = old; unsigned char *xq = p->backingstore;
for (i = 0; i < width; i++) { for (i = 0; i < p->width; i++) {
if (*xp != *xq) { if (*xp++ != *xq++) {
send_bytes_message(fd, 16, CF633_Set_LCD_Contents_Line_One, &framebuf[0]); send_bytes_message(p->fd, 16, CF633_Set_LCD_Contents_Line_One, &(p->framebuf[0]));
memcpy(old, framebuf, width); memcpy(p->backingstore, p->framebuf, p->width);
break; break;
} }
xp++; xq++;
} }
xp = &framebuf[width]; xp = &(p->framebuf[p->width]);
xq = &old[width]; xq = &(p->backingstore[p->width]);
for (i = 0; i < width; i++) { for (i = 0; i < p->width; i++) {
if (*xp != *xq) { if (*xp++ != *xq++) {
send_bytes_message(fd, 16, CF633_Set_LCD_Contents_Line_Two, &framebuf[width]); send_bytes_message(p->fd, 16, CF633_Set_LCD_Contents_Line_Two, &(p->framebuf[p->width]));
memcpy(&old[width], &framebuf[width], width); memcpy(&(p->backingstore[p->width]), &(p->framebuf[p->width]), p->width);
break; break;
} }
xp++; xq++;
} }
#endif /* defined(CF635_FLUSH) */ #endif /* defined(CF635_FLUSH) */
} }
@@ -376,34 +410,37 @@ CFontz633_flush (Driver *drvthis)
MODULE_EXPORT char * MODULE_EXPORT char *
CFontz633_get_key (Driver *drvthis) CFontz633_get_key (Driver *drvthis)
{ {
unsigned char akey; PrivateData *p = drvthis->private_data;
unsigned char key;
akey = GetKeyFromKeyRing(); key = GetKeyFromKeyRing(&p->keyring);
switch(akey) { switch (key) {
case CF633_KEY_LEFT: case CF633_KEY_LEFT:
return "Left"; return "Left";
break; break;
case CF633_KEY_UP: case CF633_KEY_UP:
return "Up"; return "Up";
break; break;
case CF633_KEY_DOWN: case CF633_KEY_DOWN:
return "Down"; return "Down";
break; break;
case CF633_KEY_RIGHT: case CF633_KEY_RIGHT:
return "Right"; return "Right";
break; break;
case CF633_KEY_ENTER: case CF633_KEY_ENTER:
return "Enter"; /* Is this correct ? */ return "Enter"; /* Is this correct ? */
break; break;
case CF633_KEY_ESCAPE: case CF633_KEY_ESCAPE:
return "Escape"; return "Escape";
break; break;
default: default:
report( RPT_INFO, "cfontz633: Untreated key 0x%2x", akey); if (key != '\0')
return NULL; report( RPT_INFO, "cfontz633: Untreated key 0x%2x", key);
break; return NULL;
} break;
}
return NULL;
} }
@@ -414,10 +451,12 @@ CFontz633_get_key (Driver *drvthis)
MODULE_EXPORT void MODULE_EXPORT void
CFontz633_chr (Driver *drvthis, int x, int y, char c) CFontz633_chr (Driver *drvthis, int x, int y, char c)
{ {
PrivateData *p = drvthis->private_data;
y--; y--;
x--; x--;
framebuf[(y * width) + x] = c; p->framebuf[(y * p->width) + x] = c;
} }
@@ -430,7 +469,9 @@ CFontz633_chr (Driver *drvthis, int x, int y, char c)
MODULE_EXPORT int MODULE_EXPORT int
CFontz633_get_contrast (Driver *drvthis) CFontz633_get_contrast (Driver *drvthis)
{ {
return contrast; PrivateData *p = drvthis->private_data;
return p->contrast;
} }
@@ -441,18 +482,19 @@ CFontz633_get_contrast (Driver *drvthis)
MODULE_EXPORT void MODULE_EXPORT void
CFontz633_set_contrast (Driver *drvthis, int promille) CFontz633_set_contrast (Driver *drvthis, int promille)
{ {
PrivateData *p = drvthis->private_data;
int hardware_contrast; int hardware_contrast;
/* Check it */ /* Check it */
if( promille < 0 || promille > 1000 ) if (promille < 0 || promille > 1000)
return; return;
/* Store the software value since there is not get. */ /* Store the software value since there is not get. */
contrast = promille; p->contrast = promille;
hardware_contrast = contrast/20; hardware_contrast = p->contrast/20;
/* Next line is to be checked $$$ */ /* Next line is to be checked $$$ */
send_onebyte_message(fd, CF633_Set_LCD_Contrast, hardware_contrast); send_onebyte_message(p->fd, CF633_Set_LCD_Contrast, hardware_contrast);
} }
@@ -464,9 +506,11 @@ CFontz633_set_contrast (Driver *drvthis, int promille)
MODULE_EXPORT void MODULE_EXPORT void
CFontz633_backlight (Driver *drvthis, int on) CFontz633_backlight (Driver *drvthis, int on)
{ {
PrivateData *p = drvthis->private_data;
/* Next line is to be checked $$$ */ /* Next line is to be checked $$$ */
send_onebyte_message(fd, CF633_Set_LCD_And_Keypad_Backlight, send_onebyte_message(p->fd, CF633_Set_LCD_And_Keypad_Backlight,
(on) ? brightness : offbrightness); (on) ? p->brightness : p->offbrightness);
} }
@@ -476,7 +520,9 @@ CFontz633_backlight (Driver *drvthis, int on)
static void static void
CFontz633_hidecursor (Driver *drvthis) CFontz633_hidecursor (Driver *drvthis)
{ {
send_onebyte_message(fd, CF633_Set_LCD_Cursor_Style, 0); PrivateData *p = drvthis->private_data;
send_onebyte_message(p->fd, CF633_Set_LCD_Cursor_Style, 0);
} }
@@ -486,10 +532,12 @@ CFontz633_hidecursor (Driver *drvthis)
static void static void
CFontz633_no_live_report (Driver *drvthis) CFontz633_no_live_report (Driver *drvthis)
{ {
PrivateData *p = drvthis->private_data;
char out[2] = { 0, 0 }; char out[2] = { 0, 0 };
for (out[0] = 0; out[0] < 8; out[0]++) for (out[0] = 0; out[0] < 8; out[0]++) {
send_bytes_message(fd, 2, CF633_Set_Up_Live_Fan_or_Temperature_Display, out); send_bytes_message(p->fd, 2, CF633_Set_Up_Live_Fan_or_Temperature_Display, out);
}
} }
@@ -499,7 +547,9 @@ CFontz633_no_live_report (Driver *drvthis)
static void static void
CFontz633_no_fan_report (Driver *drvthis) CFontz633_no_fan_report (Driver *drvthis)
{ {
send_onebyte_message(fd, CF633_Set_Up_Fan_Reporting, 0); PrivateData *p = drvthis->private_data;
send_onebyte_message(p->fd, CF633_Set_Up_Fan_Reporting, 0);
} }
@@ -509,9 +559,10 @@ CFontz633_no_fan_report (Driver *drvthis)
static void static void
CFontz633_no_temp_report (Driver *drvthis) CFontz633_no_temp_report (Driver *drvthis)
{ {
PrivateData *p = drvthis->private_data;
char out[4] = { 0, 0, 0, 0 }; char out[4] = { 0, 0, 0, 0 };
send_bytes_message(fd, 4, CF633_Set_Up_Temperature_Reporting, out); send_bytes_message(p->fd, 4, CF633_Set_Up_Temperature_Reporting, out);
} }
@@ -521,9 +572,11 @@ CFontz633_no_temp_report (Driver *drvthis)
static void static void
CFontz633_reboot (Driver *drvthis) CFontz633_reboot (Driver *drvthis)
{ {
PrivateData *p = drvthis->private_data;
char out[3] = { 8, 18, 99 }; char out[3] = { 8, 18, 99 };
send_bytes_message(fd, 3, CF633_Reboot, out); send_bytes_message(p->fd, 3, CF633_Reboot, out);
sleep(2);
} }
@@ -533,6 +586,7 @@ CFontz633_reboot (Driver *drvthis)
static void static void
CFontz633_init_vbar (Driver *drvthis) CFontz633_init_vbar (Driver *drvthis)
{ {
PrivateData *p = drvthis->private_data;
char a[] = { char a[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -604,8 +658,14 @@ CFontz633_init_vbar (Driver *drvthis)
0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
}; };
if (custom != vbar) { if (p->ccmode != vbar) {
// printf("+++ vbar +++\n"); //if (p->ccmode != standard) {
// /* Not supported(yet) */
// report(RPT_WARNING, "CFontz633_init_vbar: Cannot combine two modes using user defined characters");
// return;
//}
p->ccmode = vbar;
CFontz633_set_char (drvthis, 1, a); CFontz633_set_char (drvthis, 1, a);
CFontz633_set_char (drvthis, 2, b); CFontz633_set_char (drvthis, 2, b);
CFontz633_set_char (drvthis, 3, c); CFontz633_set_char (drvthis, 3, c);
@@ -613,7 +673,6 @@ CFontz633_init_vbar (Driver *drvthis)
CFontz633_set_char (drvthis, 5, e); CFontz633_set_char (drvthis, 5, e);
CFontz633_set_char (drvthis, 6, f); CFontz633_set_char (drvthis, 6, f);
CFontz633_set_char (drvthis, 7, g); CFontz633_set_char (drvthis, 7, g);
custom = vbar;
} }
} }
@@ -624,6 +683,7 @@ CFontz633_init_vbar (Driver *drvthis)
static void static void
CFontz633_init_hbar (Driver *drvthis) CFontz633_init_hbar (Driver *drvthis)
{ {
PrivateData *p = drvthis->private_data;
char a[] = { char a[] = {
1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
@@ -685,14 +745,20 @@ CFontz633_init_hbar (Driver *drvthis)
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
}; };
if (custom != hbar) { if (p->ccmode != hbar) {
//if (p->ccmode != standard) {
// /* Not supported(yet) */
// report(RPT_WARNING, "CFontz633_init_hbar: Cannot combine two modes using user defined characters");
// return;
//}
p->ccmode = hbar;
CFontz633_set_char (drvthis, 1, a); CFontz633_set_char (drvthis, 1, a);
CFontz633_set_char (drvthis, 2, b); CFontz633_set_char (drvthis, 2, b);
CFontz633_set_char (drvthis, 3, c); CFontz633_set_char (drvthis, 3, c);
CFontz633_set_char (drvthis, 4, d); CFontz633_set_char (drvthis, 4, d);
CFontz633_set_char (drvthis, 5, e); CFontz633_set_char (drvthis, 5, e);
CFontz633_set_char (drvthis, 6, f); CFontz633_set_char (drvthis, 6, f);
custom = hbar;
} }
} }
@@ -709,10 +775,10 @@ CFontz633_vbar (Driver *drvthis, int x, int y, int len, int promille, int option
* len is the number of characters that the bar is long at 100% * len is the number of characters that the bar is long at 100%
* promille is the number of promilles (0..1000) that the bar should be filled. * promille is the number of promilles (0..1000) that the bar should be filled.
*/ */
PrivateData *p = drvthis->private_data;
CFontz633_init_vbar(drvthis); CFontz633_init_vbar(drvthis);
lib_vbar_static(drvthis, x, y, len, promille, options, p->cellheight, 0);
lib_vbar_static(drvthis, x, y, len, promille, options, cellheight, 0);
} }
@@ -728,10 +794,10 @@ CFontz633_hbar (Driver *drvthis, int x, int y, int len, int promille, int option
* len is the number of characters that the bar is long at 100% * len is the number of characters that the bar is long at 100%
* promille is the number of promilles (0..1000) that the bar should be filled. * promille is the number of promilles (0..1000) that the bar should be filled.
*/ */
PrivateData *p = drvthis->private_data;
CFontz633_init_hbar(drvthis); CFontz633_init_hbar(drvthis);
lib_hbar_static(drvthis, x, y, len, promille, options, p->cellwidth, 0);
lib_hbar_static(drvthis, x, y, len, promille, options, cellwidth, 0);
} }
@@ -743,15 +809,17 @@ MODULE_EXPORT void
CFontz633_num (Driver *drvthis, int x, int num) CFontz633_num (Driver *drvthis, int x, int num)
{ {
/* /*
PrivateData *p = drvthis->private_data;
char out[5]; char out[5];
snprintf (out, sizeof(out), "%c%c%c", 28, x, num); snprintf (out, sizeof(out), "%c%c%c", 28, x, num);
write (fd, out, 3); write (p->fd, out, 3);
*/ */
} }
/* /*
* Sets a custom character from 0-7... * Sets a custom character from 0 - (NUM_CCs-1)
* *
* For input, values > 0 mean "on" and values <= 0 are "off". * For input, values > 0 mean "on" and values <= 0 are "off".
* *
@@ -760,34 +828,27 @@ CFontz633_num (Driver *drvthis, int x, int num)
MODULE_EXPORT void MODULE_EXPORT void
CFontz633_set_char (Driver *drvthis, int n, char *dat) CFontz633_set_char (Driver *drvthis, int n, char *dat)
{ {
PrivateData *p = drvthis->private_data;
char out[9]; char out[9];
int row, col; int row, col;
int letter;
if (n < 0 || n > 7) if ((n < 0) || (n >= NUM_CCs))
return; return;
if (!dat) if (!dat)
return; return;
out[0] = n; /* Custom char to define. xxx */ out[0] = n; /* Custom char to define. xxx */
for (row = 0; row < cellheight; row++) { for (row = 0; row < p->cellheight; row++) {
letter = 0; int letter = 0;
for (col = 0; col < cellwidth; col++) {
for (col = 0; col < p->cellwidth; col++) {
letter <<= 1; letter <<= 1;
letter |= (dat[(row * cellwidth) + col] > 0); letter |= (dat[(row * p->cellwidth) + col] > 0);
/* I should remove that debug code. */
// if (dat[(row * cellheight) + col] == 0) printf(".");
// if (dat[(row * cellheight) + col] == 1) printf("+");
// if (dat[(row * cellheight) + col] == 2) printf("x");
// if (dat[(row * cellheight) + col] == 3) printf("*");
// printf("'%1d'", dat[(row * cellwidth) + col]);
// printf("%3d ", letter);
} }
out[row+1]=letter; out[row+1] = letter;
// printf(": %d\n", letter);
} }
send_bytes_message(fd, 9, CF633_Set_LCD_Special_Character_Data , out); send_bytes_message(p->fd, 9, CF633_Set_LCD_Special_Character_Data, out);
} }
@@ -797,6 +858,7 @@ CFontz633_set_char (Driver *drvthis, int n, char *dat)
MODULE_EXPORT int MODULE_EXPORT int
CFontz633_icon (Driver *drvthis, int x, int y, int icon) CFontz633_icon (Driver *drvthis, int x, int y, int icon)
{ {
PrivateData *p = drvthis->private_data;
char icons[8][6 * 8] = { char icons[8][6 * 8] = {
/* Empty Heart */ /* Empty Heart */
{ {
@@ -889,50 +951,50 @@ CFontz633_icon (Driver *drvthis, int x, int y, int icon)
}; };
/* Yes we know, this is a VERY BAD implementation :-) */ /* Yes we know, this is a VERY BAD implementation :-) */
switch( icon ) { switch (icon) {
case ICON_BLOCK_FILLED: case ICON_BLOCK_FILLED:
CFontz633_chr( drvthis, x, y, 255 ); CFontz633_chr(drvthis, x, y, 255);
break; break;
case ICON_HEART_FILLED: case ICON_HEART_FILLED:
custom = cust; p->ccmode = custom;
CFontz633_set_char( drvthis, 0, icons[1] ); CFontz633_set_char(drvthis, 0, icons[1]);
CFontz633_chr( drvthis, x, y, 0 ); CFontz633_chr(drvthis, x, y, 0);
break; break;
case ICON_HEART_OPEN: case ICON_HEART_OPEN:
custom = cust; p->ccmode = custom;
CFontz633_set_char( drvthis, 0, icons[0] ); CFontz633_set_char(drvthis, 0, icons[0]);
CFontz633_chr( drvthis, x, y, 0 ); CFontz633_chr(drvthis, x, y, 0);
break; break;
case ICON_ARROW_UP: case ICON_ARROW_UP:
custom = cust; p->ccmode = custom;
CFontz633_set_char( drvthis, 1, icons[2] ); CFontz633_set_char(drvthis, 1, icons[2]);
CFontz633_chr( drvthis, x, y, 1 ); CFontz633_chr(drvthis, x, y, 1);
break; break;
case ICON_ARROW_DOWN: case ICON_ARROW_DOWN:
custom = cust; p->ccmode = custom;
CFontz633_set_char( drvthis, 2, icons[3] ); CFontz633_set_char(drvthis, 2, icons[3]);
CFontz633_chr( drvthis, x, y, 2 ); CFontz633_chr(drvthis, x, y, 2);
break; break;
case ICON_ARROW_LEFT: case ICON_ARROW_LEFT:
CFontz633_chr( drvthis, x, y, 0x7F ); CFontz633_chr(drvthis, x, y, 0x7F);
break; break;
case ICON_ARROW_RIGHT: case ICON_ARROW_RIGHT:
CFontz633_chr( drvthis, x, y, 0x7E ); CFontz633_chr(drvthis, x, y, 0x7E);
break; break;
case ICON_CHECKBOX_OFF: case ICON_CHECKBOX_OFF:
custom = cust; p->ccmode = custom;
CFontz633_set_char( drvthis, 3, icons[4] ); CFontz633_set_char(drvthis, 3, icons[4]);
CFontz633_chr( drvthis, x, y, 3 ); CFontz633_chr(drvthis, x, y, 3);
break; break;
case ICON_CHECKBOX_ON: case ICON_CHECKBOX_ON:
custom = cust; p->ccmode = custom;
CFontz633_set_char( drvthis, 4, icons[5] ); CFontz633_set_char(drvthis, 4, icons[5]);
CFontz633_chr( drvthis, x, y, 4 ); CFontz633_chr(drvthis, x, y, 4);
break; break;
case ICON_CHECKBOX_GRAY: case ICON_CHECKBOX_GRAY:
custom = cust; p->ccmode = custom;
CFontz633_set_char( drvthis, 5, icons[6] ); CFontz633_set_char(drvthis, 5, icons[6]);
CFontz633_chr( drvthis, x, y, 5 ); CFontz633_chr(drvthis, x, y, 5);
break; break;
default: default:
return -1; /* Let the core do other icons */ return -1; /* Let the core do other icons */
@@ -947,7 +1009,10 @@ CFontz633_icon (Driver *drvthis, int x, int y, int icon)
MODULE_EXPORT void MODULE_EXPORT void
CFontz633_clear (Driver *drvthis) CFontz633_clear (Driver *drvthis)
{ {
memset(framebuf, ' ', width * height); PrivateData *p = drvthis->private_data;
memset(p->framebuf, ' ', p->width * p->height);
p->ccmode = standard;
} }
@@ -957,7 +1022,9 @@ CFontz633_clear (Driver *drvthis)
static void static void
CFontz633_hardware_clear (Driver *drvthis) CFontz633_hardware_clear (Driver *drvthis)
{ {
send_zerobyte_message(fd, CF633_Clear_LCD_Screen); PrivateData *p = drvthis->private_data;
send_zerobyte_message(p->fd, CF633_Clear_LCD_Screen);
} }
@@ -968,18 +1035,18 @@ CFontz633_hardware_clear (Driver *drvthis)
MODULE_EXPORT void MODULE_EXPORT void
CFontz633_string (Driver *drvthis, int x, int y, char string[]) CFontz633_string (Driver *drvthis, int x, int y, char string[])
{ {
PrivateData *p = drvthis->private_data;
int i; int i;
/* Convert 1-based coords to 0-based... */ /* Convert 1-based coords to 0-based... */
x -= 1; x--;
y -= 1; y--;
for (i = 0; string[i]; i++) {
for (i = 0; string[i] != '\0'; i++) {
/* Check for buffer overflows... */ /* Check for buffer overflows... */
if ((y * width) + x + i > (width * height)) if ((y * p->width) + x + i > (p->width * p->height))
break; break;
framebuf[(y * width) + x + i] = string[i]; p->framebuf[(y * p->width) + x + i] = string[i];
} }
} }