harmonize coding style and messages, add more checks

This commit is contained in:
marschap
2006-04-07 18:44:53 +00:00
parent ff050f9bf0
commit b9a3b9dc1f
3 changed files with 254 additions and 227 deletions
+39 -26
View File
@@ -126,6 +126,7 @@ CFontz_init (Driver *drvthis)
return -1; return -1;
/* Initialize the PrivateData structure */ /* Initialize the PrivateData structure */
p->fd = -1;
p->cellwidth = DEFAULT_CELL_WIDTH; p->cellwidth = DEFAULT_CELL_WIDTH;
p->cellheight = DEFAULT_CELL_HEIGHT; p->cellheight = DEFAULT_CELL_HEIGHT;
p->ccmode = standard; p->ccmode = standard;
@@ -136,7 +137,7 @@ CFontz_init (Driver *drvthis)
/* Which device should be used */ /* Which device should be used */
strncpy(p->device, drvthis->config_get_string(drvthis->name, "Device", 0, DEFAULT_DEVICE), sizeof(p->device)); strncpy(p->device, drvthis->config_get_string(drvthis->name, "Device", 0, DEFAULT_DEVICE), sizeof(p->device));
p->device[sizeof(p->device)-1] = '\0'; p->device[sizeof(p->device)-1] = '\0';
debug (RPT_INFO,"CFontz: Using device: %s", p->device); report(RPT_INFO, "%s: using Device %s", drvthis->name, 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));
@@ -144,7 +145,8 @@ CFontz_init (Driver *drvthis)
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, "CFontz_init: Cannot read size: %s. Using default value.\n", size); report(RPT_WARNING, "%s: cannot read Size: %s; using default %s",
drvthis->name, size, DEFAULT_SIZE);
sscanf(DEFAULT_SIZE, "%dx%d", &w, &h); sscanf(DEFAULT_SIZE, "%dx%d", &w, &h);
} }
p->width = w; p->width = w;
@@ -153,7 +155,8 @@ CFontz_init (Driver *drvthis)
/* Which contrast */ /* Which contrast */
tmp = drvthis->config_get_int(drvthis->name, "Contrast", 0, DEFAULT_CONTRAST); tmp = drvthis->config_get_int(drvthis->name, "Contrast", 0, DEFAULT_CONTRAST);
if ((tmp < 0) || (tmp > 1000)) { if ((tmp < 0) || (tmp > 1000)) {
report (RPT_WARNING, "CFontz_init: Contrast must be between 0 and 1000. Using default value.\n"); report(RPT_WARNING, "%s: Contrast must be between 0 and 1000; using default %d",
drvthis->name, DEFAULT_CONTRAST);
tmp = DEFAULT_CONTRAST; tmp = DEFAULT_CONTRAST;
} }
p->contrast = tmp; p->contrast = tmp;
@@ -161,7 +164,8 @@ CFontz_init (Driver *drvthis)
/* Which backlight brightness */ /* Which backlight brightness */
tmp = drvthis->config_get_int(drvthis->name, "Brightness", 0, DEFAULT_BRIGHTNESS); tmp = drvthis->config_get_int(drvthis->name, "Brightness", 0, DEFAULT_BRIGHTNESS);
if ((tmp < 0) || (tmp > 255)) { if ((tmp < 0) || (tmp > 255)) {
report (RPT_WARNING, "CFontz_init: Brightness must be between 0 and 255. Using default value.\n"); report(RPT_WARNING, "%s: Brightness must be between 0 and 255; using default %d",
drvthis->name, DEFAULT_BRIGHTNESS);
tmp = DEFAULT_BRIGHTNESS; tmp = DEFAULT_BRIGHTNESS;
} }
p->brightness = tmp; p->brightness = tmp;
@@ -169,7 +173,8 @@ CFontz_init (Driver *drvthis)
/* Which backlight-off "brightness" */ /* Which backlight-off "brightness" */
tmp = drvthis->config_get_int(drvthis->name, "OffBrightness", 0, DEFAULT_OFFBRIGHTNESS); tmp = drvthis->config_get_int(drvthis->name, "OffBrightness", 0, DEFAULT_OFFBRIGHTNESS);
if ((tmp < 0) || (tmp > 255)) { if ((tmp < 0) || (tmp > 255)) {
report (RPT_WARNING, "CFontz_init: OffBrightness must be between 0 and 255. Using default value.\n"); report(RPT_WARNING, "%s: OffBrightness must be between 0 and 255; using default %d",
drvthis->name, DEFAULT_OFFBRIGHTNESS);
tmp = DEFAULT_OFFBRIGHTNESS; tmp = DEFAULT_OFFBRIGHTNESS;
} }
p->offbrightness = tmp; p->offbrightness = tmp;
@@ -182,7 +187,8 @@ CFontz_init (Driver *drvthis)
else if (tmp == 19200) speed = B19200; else if (tmp == 19200) speed = B19200;
else if (tmp == 115200) speed = B115200; else if (tmp == 115200) speed = B115200;
else { else {
report (RPT_WARNING, "CFontz_init: Speed must be 1200, 2400, 9600, 19200 or 115200. Using default value.\n"); report(RPT_WARNING, "%s: Speed must be 1200, 2400, 9600, 19200 or 115200; using default %d",
drvthis->name, DEFAULT_SPEED);
speed = DEFAULT_SPEED; speed = DEFAULT_SPEED;
} }
@@ -199,7 +205,8 @@ CFontz_init (Driver *drvthis)
debug(RPT_DEBUG, "CFontz: Opening device: %s", p->device); debug(RPT_DEBUG, "CFontz: Opening device: %s", p->device);
p->fd = open(p->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 (p->fd == -1) { if (p->fd == -1) {
report (RPT_ERR, "CFontz_init: failed (%s)\n", strerror (errno)); report(RPT_ERR, "%s: open(%s) failed (%s)",
drvthis->name, p->device, strerror(errno));
return -1; return -1;
} }
@@ -241,14 +248,14 @@ CFontz_init (Driver *drvthis)
/* make sure the frame buffer is there... */ /* make sure the frame buffer is there... */
p->framebuf = (unsigned char *) malloc(p->width * p->height); p->framebuf = (unsigned char *) malloc(p->width * p->height);
if (p->framebuf == NULL) { if (p->framebuf == NULL) {
report(RPT_ERR, "CFontz_init: unable to create p->framebuffer.\n"); report(RPT_ERR, "%s: unable to create framebuffer", drvthis->name);
return -1; return -1;
} }
memset(p->framebuf, ' ', p->width * p->height); memset(p->framebuf, ' ', p->width * p->height);
// Set display-specific stuff.. // Set display-specific stuff..
if (reboot) { if (reboot) {
report (RPT_INFO, "LCDd: rebooting CrystalFontz LCD...\n"); report(RPT_INFO, "%s: rebooting LCD...", drvthis->name);
CFontz_reboot(drvthis); CFontz_reboot(drvthis);
} }
sleep (1); sleep (1);
@@ -259,9 +266,9 @@ CFontz_init (Driver *drvthis)
CFontz_set_contrast(drvthis, p->contrast); CFontz_set_contrast(drvthis, p->contrast);
report (RPT_DEBUG, "CFontz_init: done\n"); report(RPT_DEBUG, "%s: init() done", drvthis->name);
return 0; return 1;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -273,6 +280,7 @@ CFontz_close (Driver *drvthis)
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
if (p != NULL) { if (p != NULL) {
if (p->fd >= 0)
close(p->fd); close(p->fd);
if (p->framebuf) if (p->framebuf)
@@ -346,13 +354,15 @@ CFontz_chr (Driver *drvthis, int x, int y, unsigned char c)
y--; y--;
x--; x--;
if ((x < 0) || (y < 0) || (x >= p->width) || (y >= p->height))
return;
if (c < 32) if (c < 32)
c += 128; c += 128;
// For V2 of the firmware to get the block to display right // For V2 of the firmware to get the block to display right
if (p->newfirmware && c == 255) { if (p->newfirmware && (c == 255))
c = 214; c = 214;
}
p->framebuf[(y * p->width) + x] = c; p->framebuf[(y * p->width) + x] = c;
} }
@@ -382,7 +392,7 @@ CFontz_set_contrast (Driver *drvthis, int promille)
char out[4]; char out[4];
// Check it // Check it
if (promille < 0 || promille > 1000) if ((promille < 0) || (promille > 1000))
return; return;
// Store it // Store it
@@ -402,11 +412,8 @@ CFontz_backlight (Driver *drvthis, int on)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
char out[4]; char out[4];
if (on) {
snprintf (out, sizeof(out), "%c%c", 14, p->brightness); snprintf(out, sizeof(out), "%c%c", 14, (on) ? p->brightness : p->offbrightness);
} else {
snprintf (out, sizeof(out), "%c%c", 14, p->offbrightness);
}
write(p->fd, out, 3); write(p->fd, out, 3);
} }
@@ -431,6 +438,7 @@ CFontz_autoscroll (Driver *drvthis, int on)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
char out[4]; char out[4];
snprintf(out, sizeof(out), "%c", (on) ? 19 : 20); snprintf(out, sizeof(out), "%c", (on) ? 19 : 20);
write(p->fd, out, 1); write(p->fd, out, 1);
} }
@@ -443,6 +451,7 @@ CFontz_hidecursor (Driver *drvthis)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
char out[4]; char out[4];
snprintf(out, sizeof(out), "%c", 4); snprintf(out, sizeof(out), "%c", 4);
write(p->fd, out, 1); write(p->fd, out, 1);
} }
@@ -455,6 +464,7 @@ CFontz_reboot (Driver *drvthis)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
char out[4]; char out[4];
snprintf(out, sizeof(out), "%c", 26); snprintf(out, sizeof(out), "%c", 26);
write(p->fd, out, 1); write(p->fd, out, 1);
sleep(4); sleep(4);
@@ -772,6 +782,7 @@ MODULE_EXPORT void
CFontz_clear (Driver *drvthis) CFontz_clear (Driver *drvthis)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
memset(p->framebuf, ' ', p->width * p->height); memset(p->framebuf, ' ', p->width * p->height);
} }
@@ -789,17 +800,19 @@ CFontz_string (Driver *drvthis, int x, int y, unsigned char string[])
x--; x--;
y--; y--;
for (i = 0; string[i] != '\0'; i++) { if ((y < 0) || (y >= p->height))
return;
for (i = 0; (string[i] != '\0') && (x < p->width); i++, x++) {
unsigned char c = string[i];
// For V2 of the firmware to get the block to display right // For V2 of the firmware to get the block to display right
if (p->newfirmware && string[i] == 255) { if (p->newfirmware && (c == 255))
string[i] = 214; c = 214;
}
// Check for buffer overflows... // Check for buffer overflows...
if ((y * p->width) + x + i > (p->width * p->height)) if (x >= 0)
break; p->framebuf[(y * p->width) + x] = c;
p->framebuf[(y * p->width) + x + i] = string[i];
} }
} }
+31 -25
View File
@@ -154,6 +154,7 @@ CFontz633_init (Driver *drvthis)
return -1; return -1;
/* Initialize the PrivateData structure */ /* Initialize the PrivateData structure */
p->fd = -1;
p->cellwidth = DEFAULT_CELL_WIDTH; p->cellwidth = DEFAULT_CELL_WIDTH;
p->cellheight = DEFAULT_CELL_HEIGHT; p->cellheight = DEFAULT_CELL_HEIGHT;
p->ccmode = standard; p->ccmode = standard;
@@ -167,7 +168,7 @@ CFontz633_init (Driver *drvthis)
/* Which device should be used */ /* Which device should be used */
strncpy(p->device, drvthis->config_get_string(drvthis->name, "Device", 0, DEFAULT_DEVICE), sizeof(p->device)); strncpy(p->device, drvthis->config_get_string(drvthis->name, "Device", 0, DEFAULT_DEVICE), sizeof(p->device));
p->device[sizeof(p->device)-1] = '\0'; p->device[sizeof(p->device)-1] = '\0';
debug (RPT_INFO,"%s: Device (in config) is: '%s'", __FUNCTION__, p->device); report(RPT_INFO, "%s: using Device %s", drvthis->name, 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));
@@ -175,8 +176,8 @@ CFontz633_init (Driver *drvthis)
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, "%s: Cannot parse size: %s. Using default %s.\n", report(RPT_WARNING, "%s: cannot parse Size: %s; using default %s",
__FUNCTION__, size, DEFAULT_SIZE); drvthis->name, size, DEFAULT_SIZE);
sscanf(DEFAULT_SIZE, "%dx%d", &w, &h); sscanf(DEFAULT_SIZE, "%dx%d", &w, &h);
} }
p->width = w; p->width = w;
@@ -185,8 +186,8 @@ CFontz633_init (Driver *drvthis)
/* Which contrast */ /* Which contrast */
tmp = drvthis->config_get_int(drvthis->name, "Contrast", 0, DEFAULT_CONTRAST); tmp = drvthis->config_get_int(drvthis->name, "Contrast", 0, DEFAULT_CONTRAST);
if ((tmp < 0) || (tmp > 1000)) { if ((tmp < 0) || (tmp > 1000)) {
report (RPT_WARNING, "%s: Contrast must be between 0 and 1000. Using default %d.\n", report(RPT_WARNING, "%s: Contrast must be between 0 and 1000; using default %d",
__FUNCTION__, DEFAULT_CONTRAST); drvthis->name, DEFAULT_CONTRAST);
tmp = DEFAULT_CONTRAST; tmp = DEFAULT_CONTRAST;
} }
p->contrast = tmp; p->contrast = tmp;
@@ -194,8 +195,8 @@ CFontz633_init (Driver *drvthis)
/* Which backlight brightness */ /* Which backlight brightness */
tmp = drvthis->config_get_int(drvthis->name, "Brightness", 0, DEFAULT_BRIGHTNESS); tmp = drvthis->config_get_int(drvthis->name, "Brightness", 0, DEFAULT_BRIGHTNESS);
if ((tmp < 0) || (tmp > 1000)) { if ((tmp < 0) || (tmp > 1000)) {
report (RPT_WARNING, "%s: Brightness must be between 0 and 1000. Using default %d.\n", report(RPT_WARNING, "%s: Brightness must be between 0 and 1000; using default %d",
__FUNCTION__, DEFAULT_BRIGHTNESS); drvthis->name, DEFAULT_BRIGHTNESS);
tmp = DEFAULT_BRIGHTNESS; tmp = DEFAULT_BRIGHTNESS;
} }
p->brightness = tmp; p->brightness = tmp;
@@ -203,8 +204,8 @@ CFontz633_init (Driver *drvthis)
/* Which backlight-off "brightness" */ /* Which backlight-off "brightness" */
tmp = drvthis->config_get_int(drvthis->name, "OffBrightness", 0, DEFAULT_OFFBRIGHTNESS); tmp = drvthis->config_get_int(drvthis->name, "OffBrightness", 0, DEFAULT_OFFBRIGHTNESS);
if ((tmp < 0) || (tmp > 1000)) { if ((tmp < 0) || (tmp > 1000)) {
report (RPT_WARNING, "%s: OffBrightness must be between 0 and 1000. Using default %d.\n", report(RPT_WARNING, "%s: OffBrightness must be between 0 and 1000; using default %d",
__FUNCTION__, DEFAULT_OFFBRIGHTNESS); drvthis->name, DEFAULT_OFFBRIGHTNESS);
tmp = DEFAULT_OFFBRIGHTNESS; tmp = DEFAULT_OFFBRIGHTNESS;
} }
p->offbrightness = tmp; p->offbrightness = tmp;
@@ -212,8 +213,8 @@ CFontz633_init (Driver *drvthis)
/* 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) && (tmp != 2400) && (tmp != 9600) && (tmp != 19200) && (tmp != 115200)) { if ((tmp != 1200) && (tmp != 2400) && (tmp != 9600) && (tmp != 19200) && (tmp != 115200)) {
report (RPT_WARNING, "%s: Speed must be 1200, 2400, 9600, 19200 or 115200. Using default %d.\n", report(RPT_WARNING, "%s: Speed must be 1200, 2400, 9600, 19200 or 115200; using default %d",
__FUNCTION__, DEFAULT_SPEED); drvthis->name, DEFAULT_SPEED);
tmp = DEFAULT_SPEED; tmp = DEFAULT_SPEED;
} }
if (tmp == 1200) p->speed = B1200; if (tmp == 1200) p->speed = B1200;
@@ -238,7 +239,7 @@ CFontz633_init (Driver *drvthis)
debug(RPT_DEBUG, "%s: Opening device: %s", __FUNCTION__, p->device); debug(RPT_DEBUG, "%s: Opening device: %s", __FUNCTION__, p->device);
p->fd = open(p->device, (p->usb) ? (O_RDWR | O_NOCTTY) : (O_RDWR | O_NOCTTY | O_NDELAY)); p->fd = open(p->device, (p->usb) ? (O_RDWR | O_NOCTTY) : (O_RDWR | O_NOCTTY | O_NDELAY));
if (p->fd == -1) { if (p->fd == -1) {
report (RPT_ERR, "%s: open() failed (%s)\n", __FUNCTION__, strerror (errno)); report(RPT_ERR, "%s: open(%s) failed (%s)", drvthis->name, p->device, strerror(errno));
return -1; return -1;
} }
@@ -280,7 +281,7 @@ CFontz633_init (Driver *drvthis)
/* make sure the frame buffer is there... */ /* make sure the frame buffer is there... */
p->framebuf = (unsigned char *) malloc(p->width * p->height); p->framebuf = (unsigned char *) malloc(p->width * p->height);
if (p->framebuf == NULL) { if (p->framebuf == NULL) {
report(RPT_ERR, "%s: unable to create framebuffer.\n", __FUNCTION__); report(RPT_ERR, "%s: unable to create framebuffer", drvthis->name);
return -1; return -1;
} }
memset(p->framebuf, ' ', p->width * p->height); memset(p->framebuf, ' ', p->width * p->height);
@@ -288,13 +289,14 @@ CFontz633_init (Driver *drvthis)
/* make sure the framebuffer backing store is there... */ /* make sure the framebuffer backing store is there... */
p->backingstore = (unsigned char *) malloc(p->width * p->height); p->backingstore = (unsigned char *) malloc(p->width * p->height);
if (p->backingstore == NULL) { if (p->backingstore == NULL) {
report(RPT_ERR, "%s: unable to create framebuffer backing store.\n", __FUNCTION__); report(RPT_ERR, "%s: unable to create framebuffer backing store", drvthis->name);
return -1; return -1;
} }
memset(p->backingstore, ' ', p->width * p->height); memset(p->backingstore, ' ', p->width * p->height);
/* Set display-specific stuff.. */ /* Set display-specific stuff.. */
if (reboot) { if (reboot) {
report(RPT_INFO, "%s: rebooting LCD...", drvthis->name);
CFontz633_reboot(drvthis); CFontz633_reboot(drvthis);
reboot = 0; reboot = 0;
} }
@@ -305,7 +307,7 @@ CFontz633_init (Driver *drvthis)
CFontz633_no_live_report(drvthis); CFontz633_no_live_report(drvthis);
CFontz633_hardware_clear(drvthis); CFontz633_hardware_clear(drvthis);
report (RPT_DEBUG, "%s: done\n", __FUNCTION__); report(RPT_DEBUG, "%s: init() done", drvthis->name);
return 0; return 0;
} }
@@ -320,6 +322,7 @@ CFontz633_close (Driver *drvthis)
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
if (p != NULL) { if (p != NULL) {
if (p->fd >= 0)
close(p->fd); close(p->fd);
if (p->framebuf) if (p->framebuf)
@@ -443,9 +446,7 @@ MODULE_EXPORT const char *
CFontz633_get_key (Driver *drvthis) CFontz633_get_key (Driver *drvthis)
{ {
// PrivateData *p = drvthis->private_data; // PrivateData *p = drvthis->private_data;
unsigned char key; unsigned char key = GetKeyFromKeyRing(&keyring);
key = GetKeyFromKeyRing(&keyring);
switch (key) { switch (key) {
case CF633_KEY_LEFT: case CF633_KEY_LEFT:
@@ -468,7 +469,7 @@ CFontz633_get_key (Driver *drvthis)
break; break;
default: default:
if (key != '\0') if (key != '\0')
report( RPT_INFO, "cfontz633: Untreated key 0x%2x", key); report(RPT_INFO, "%s: Untreated key 0x%02X", drvthis->name, key);
return NULL; return NULL;
break; break;
} }
@@ -488,6 +489,7 @@ CFontz633_chr (Driver *drvthis, int x, int y, char c)
y--; y--;
x--; x--;
if ((x >= 0) && (y >= 0) && (x < p->width) && (y < p->height))
p->framebuf[(y * p->width) + x] = c; p->framebuf[(y * p->width) + x] = c;
} }
@@ -729,7 +731,8 @@ CFontz633_init_vbar (Driver *drvthis)
if (p->ccmode != vbar) { if (p->ccmode != vbar) {
//if (p->ccmode != standard) { //if (p->ccmode != standard) {
// /* Not supported(yet) */ // /* Not supported(yet) */
// report(RPT_WARNING, "CFontz633_init_vbar: Cannot combine two modes using user defined characters"); // report(RPT_WARNING, "%s: init_vbar: cannot combine two modes using user defined characters"
// drvthis->name);
// return; // return;
//} //}
p->ccmode = vbar; p->ccmode = vbar;
@@ -816,7 +819,8 @@ CFontz633_init_hbar (Driver *drvthis)
if (p->ccmode != hbar) { if (p->ccmode != hbar) {
//if (p->ccmode != standard) { //if (p->ccmode != standard) {
// /* Not supported(yet) */ // /* Not supported(yet) */
// report(RPT_WARNING, "CFontz633_init_hbar: Cannot combine two modes using user defined characters"); // report(RPT_WARNING, "%s: init_hbar: Cannot combine two modes using user defined characters",
// drvthis->name);
// return; // return;
//} //}
p->ccmode = hbar; p->ccmode = hbar;
@@ -1110,11 +1114,13 @@ CFontz633_string (Driver *drvthis, int x, int y, char string[])
x--; x--;
y--; y--;
for (i = 0; string[i] != '\0'; i++) { if ((y < 0) || (y >= p->height))
return;
for (i = 0; (string[i] != '\0') && (x < p->width); i++, x++) {
/* Check for buffer overflows... */ /* Check for buffer overflows... */
if ((y * p->width) + x + i > (p->width * p->height)) if (x >= 0)
break; p->framebuf[(y * p->width) + x] = string[i];
p->framebuf[(y * p->width) + x + i] = string[i];
} }
} }
+42 -34
View File
@@ -194,6 +194,7 @@ CFontzPacket_init (Driver *drvthis)
return -1; return -1;
/* Initialize the PrivateData structure */ /* Initialize the PrivateData structure */
p->fd = -1;
p->cellwidth = DEFAULT_CELL_WIDTH; p->cellwidth = DEFAULT_CELL_WIDTH;
p->cellheight = DEFAULT_CELL_HEIGHT; p->cellheight = DEFAULT_CELL_HEIGHT;
p->ccmode = standard; p->ccmode = standard;
@@ -210,15 +211,15 @@ CFontzPacket_init (Driver *drvthis)
debug(RPT_INFO, "%s: Model (in config) is '%d'", __FUNCTION__, tmp); debug(RPT_INFO, "%s: Model (in config) is '%d'", __FUNCTION__, tmp);
if ((tmp != 631) && (tmp != 633) && (tmp != 635)) { if ((tmp != 631) && (tmp != 633) && (tmp != 635)) {
tmp = 633; tmp = 633;
report (RPT_WARNING, "%s: Model must be 631, 633 or 635. Using default %d.\n", report(RPT_WARNING, "%s: Model must be 631, 633 or 635; using default %d",
__FUNCTION__, tmp); drvthis->name, tmp);
} }
p->model = tmp; p->model = tmp;
/* Which device should be used */ /* Which device should be used */
strncpy(p->device, drvthis->config_get_string(drvthis->name, "Device", 0, DEFAULT_DEVICE), sizeof(p->device)); strncpy(p->device, drvthis->config_get_string(drvthis->name, "Device", 0, DEFAULT_DEVICE), sizeof(p->device));
p->device[sizeof(p->device)-1] = '\0'; p->device[sizeof(p->device)-1] = '\0';
debug (RPT_INFO, "%s: Device (in config) is '%s'", __FUNCTION__, p->device); report(RPT_INFO, "%s: using Device %s", drvthis->name, p->device);
/* Which size */ /* Which size */
if (p->model == 631) { if (p->model == 631) {
@@ -238,8 +239,8 @@ CFontzPacket_init (Driver *drvthis)
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, "%s: Cannot parse size: %s. Using default %s.\n", report(RPT_WARNING, "%s: cannot parse Size: %s; using default %s",
__FUNCTION__, size, default_size); drvthis->name, size, default_size);
sscanf(default_size, "%dx%d", &w, &h); sscanf(default_size, "%dx%d", &w, &h);
} }
p->width = w; p->width = w;
@@ -251,8 +252,8 @@ CFontzPacket_init (Driver *drvthis)
tmp = drvthis->config_get_int(drvthis->name, "Contrast", 0, DEFAULT_CONTRAST); tmp = drvthis->config_get_int(drvthis->name, "Contrast", 0, DEFAULT_CONTRAST);
debug(RPT_INFO, "%s: Contrast (in config) is '%d'", __FUNCTION__, tmp); debug(RPT_INFO, "%s: Contrast (in config) is '%d'", __FUNCTION__, tmp);
if ((tmp < 0) || (tmp > 1000)) { if ((tmp < 0) || (tmp > 1000)) {
report (RPT_WARNING, "%s: Contrast must be between 0 and 1000. Using default %d.\n", report(RPT_WARNING, "%s: Contrast must be between 0 and 1000; using default %d",
__FUNCTION__, DEFAULT_CONTRAST); drvthis->name, DEFAULT_CONTRAST);
tmp = DEFAULT_CONTRAST; tmp = DEFAULT_CONTRAST;
} }
p->contrast = tmp; p->contrast = tmp;
@@ -261,8 +262,8 @@ CFontzPacket_init (Driver *drvthis)
tmp = drvthis->config_get_int(drvthis->name, "Brightness", 0, DEFAULT_BRIGHTNESS); tmp = drvthis->config_get_int(drvthis->name, "Brightness", 0, DEFAULT_BRIGHTNESS);
debug(RPT_INFO, "%s: Brightness (in config) is '%d'", __FUNCTION__, tmp); debug(RPT_INFO, "%s: Brightness (in config) is '%d'", __FUNCTION__, tmp);
if ((tmp < 0) || (tmp > 1000)) { if ((tmp < 0) || (tmp > 1000)) {
report (RPT_WARNING, "%s: Brightness must be between 0 and 1000. Using default %d.\n", report(RPT_WARNING, "%s: Brightness must be between 0 and 1000; using default %d",
__FUNCTION__, DEFAULT_BRIGHTNESS); drvthis->name, DEFAULT_BRIGHTNESS);
tmp = DEFAULT_BRIGHTNESS; tmp = DEFAULT_BRIGHTNESS;
} }
p->brightness = tmp; p->brightness = tmp;
@@ -271,8 +272,8 @@ CFontzPacket_init (Driver *drvthis)
tmp = drvthis->config_get_int(drvthis->name, "OffBrightness", 0, DEFAULT_OFFBRIGHTNESS); tmp = drvthis->config_get_int(drvthis->name, "OffBrightness", 0, DEFAULT_OFFBRIGHTNESS);
debug(RPT_INFO, "%s: OffBrightness (in config) is '%d'", __FUNCTION__, tmp); debug(RPT_INFO, "%s: OffBrightness (in config) is '%d'", __FUNCTION__, tmp);
if ((tmp < 0) || (tmp > 1000)) { if ((tmp < 0) || (tmp > 1000)) {
report (RPT_WARNING, "%s: OffBrightness must be between 0 and 1000. Using default %d.\n", report(RPT_WARNING, "%s: OffBrightness must be between 0 and 1000; using default %d",
__FUNCTION__, DEFAULT_OFFBRIGHTNESS); drvthis->name, DEFAULT_OFFBRIGHTNESS);
tmp = DEFAULT_OFFBRIGHTNESS; tmp = DEFAULT_OFFBRIGHTNESS;
} }
p->offbrightness = tmp; p->offbrightness = tmp;
@@ -281,8 +282,8 @@ CFontzPacket_init (Driver *drvthis)
tmp = drvthis->config_get_int(drvthis->name, "Speed", 0, default_speed); tmp = drvthis->config_get_int(drvthis->name, "Speed", 0, default_speed);
debug(RPT_INFO, "%s: Speed (in config) is '%d'", __FUNCTION__, tmp); debug(RPT_INFO, "%s: Speed (in config) is '%d'", __FUNCTION__, tmp);
if ((tmp != 19200) && (tmp != 115200)) { if ((tmp != 19200) && (tmp != 115200)) {
report (RPT_WARNING, "%s: Speed must be 19200 or 11500. Using default %d.\n", report(RPT_WARNING, "%s: Speed must be 19200 or 11500; using default %d",
__FUNCTION__, default_speed); drvthis->name, default_speed);
tmp = default_speed; tmp = default_speed;
} }
p->speed = (tmp == 19200) ? B19200 : B115200; p->speed = (tmp == 19200) ? B19200 : B115200;
@@ -299,13 +300,13 @@ CFontzPacket_init (Driver *drvthis)
/* Am I USB or not? */ /* Am I USB or not? */
p->usb = drvthis->config_get_bool(drvthis->name, "USB", 0, 0); p->usb = drvthis->config_get_bool(drvthis->name, "USB", 0, 0);
if (p->usb) if (p->usb)
report (RPT_INFO, "%s: USB is indicated (in config)", __FUNCTION__); report(RPT_INFO, "%s: USB is indicated (in config)", drvthis->name);
/* Set up io port correctly, and open it... */ /* Set up io port correctly, and open it... */
debug(RPT_DEBUG, "%s: Opening device: %s", __FUNCTION__, p->device); debug(RPT_DEBUG, "%s: Opening device: %s", __FUNCTION__, p->device);
p->fd = open(p->device, (p->usb) ? (O_RDWR | O_NOCTTY) : (O_RDWR | O_NOCTTY | O_NDELAY)); p->fd = open(p->device, (p->usb) ? (O_RDWR | O_NOCTTY) : (O_RDWR | O_NOCTTY | O_NDELAY));
if (p->fd == -1) { if (p->fd == -1) {
report (RPT_ERR, "%s: open() failed (%s)\n", __FUNCTION__, strerror (errno)); report(RPT_ERR, "%s: open(%s) failed (%s)", drvthis->name, p->device, strerror(errno));
return -1; return -1;
} }
@@ -347,7 +348,7 @@ CFontzPacket_init (Driver *drvthis)
/* make sure the frame buffer is there... */ /* make sure the frame buffer is there... */
p->framebuf = (unsigned char *) malloc(p->width * p->height); p->framebuf = (unsigned char *) malloc(p->width * p->height);
if (p->framebuf == NULL) { if (p->framebuf == NULL) {
report(RPT_ERR, "%s: unable to create framebuffer.\n", __FUNCTION__); report(RPT_ERR, "%s: unable to create framebuffer", drvthis->name);
return -1; return -1;
} }
memset(p->framebuf, ' ', p->width * p->height); memset(p->framebuf, ' ', p->width * p->height);
@@ -355,17 +356,17 @@ CFontzPacket_init (Driver *drvthis)
/* make sure the framebuffer backing store is there... */ /* make sure the framebuffer backing store is there... */
p->backingstore = (unsigned char *) malloc(p->width * p->height); p->backingstore = (unsigned char *) malloc(p->width * p->height);
if (p->backingstore == NULL) { if (p->backingstore == NULL) {
report(RPT_ERR, "%s: unable to create framebuffer backing store.\n", __FUNCTION__); report(RPT_ERR, "%s: unable to create framebuffer backing store", drvthis->name);
return -1; return -1;
} }
memset(p->backingstore, ' ', p->width * p->height); memset(p->backingstore, ' ', p->width * p->height);
/* Set display-specific stuff.. */ /* Set display-specific stuff.. */
if (reboot) { if (reboot) {
debug(RPT_INFO, "CFontzPacket: reboot requested (in config)\n" ); report(RPT_INFO, "%s: rebooting LCD...", drvthis->name);
CFontzPacket_reboot(drvthis); CFontzPacket_reboot(drvthis);
reboot = 0; reboot = 0;
debug(RPT_DEBUG, "CFontzPacket: reboot done" ); debug(RPT_DEBUG, "%s: reboot done", __FUNCTION__);
} }
CFontzPacket_hidecursor(drvthis); CFontzPacket_hidecursor(drvthis);
@@ -377,7 +378,7 @@ CFontzPacket_init (Driver *drvthis)
/* turn LEDs off on a CF635 */ /* turn LEDs off on a CF635 */
CFontzPacket_output(drvthis, 0); CFontzPacket_output(drvthis, 0);
report (RPT_DEBUG, "%s: done\n", __FUNCTION__); report(RPT_DEBUG, "%s: init() done", drvthis->name);
return 0; return 0;
} }
@@ -392,6 +393,7 @@ CFontzPacket_close (Driver *drvthis)
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
if (p != NULL) { if (p != NULL) {
if (p->fd >= 0)
close(p->fd); close(p->fd);
if (p->framebuf) if (p->framebuf)
@@ -503,7 +505,7 @@ CFontzPacket_flush (Driver *drvthis)
unsigned char *sq = p->backingstore + (i * p->width); unsigned char *sq = p->backingstore + (i * p->width);
debug(RPT_DEBUG, "Framebuf: '%.*s'", p->width, sp); debug(RPT_DEBUG, "Framebuf: '%.*s'", p->width, sp);
debug (RPT_DEBUG, " backingstore: '%.*s'", p->width, sq ); debug(RPT_DEBUG, "Backingstore: '%.*s'", p->width, sq);
#if defined(CFONTZPACKET_OLD_OPTIMATION) #if defined(CFONTZPACKET_OLD_OPTIMATION)
/* Strategy: /* Strategy:
@@ -584,10 +586,8 @@ CFontzPacket_flush (Driver *drvthis)
MODULE_EXPORT const char * MODULE_EXPORT const char *
CFontzPacket_get_key (Driver *drvthis) CFontzPacket_get_key (Driver *drvthis)
{ {
PrivateData *p = drvthis->private_data; //PrivateData *p = drvthis->private_data;
unsigned char key; unsigned char key = GetKeyFromKeyRing(&keyring);
key = GetKeyFromKeyRing(&keyring);
switch (key) { switch (key) {
case CFP_KEY_LEFT: case CFP_KEY_LEFT:
@@ -630,12 +630,12 @@ CFontzPacket_get_key (Driver *drvthis)
case CFP_KEY_UR_RELEASE: case CFP_KEY_UR_RELEASE:
case CFP_KEY_LL_RELEASE: case CFP_KEY_LL_RELEASE:
case CFP_KEY_LR_RELEASE: case CFP_KEY_LR_RELEASE:
// report( RPT_INFO, "CFontzPacket: Returning key release 0x%2x", key); // report(RPT_INFO, "%s: Ignoring key release 0x%02X", drvthis->name, key);
return NULL; return NULL;
break; break;
default: default:
if (key != '\0') if (key != '\0')
report( RPT_INFO, "CFontzPacket: Untreated unknown key 0x%2x", key); report(RPT_INFO, "%s: Untreated key 0x%02X", drvthis->name, key);
return NULL; return NULL;
break; break;
} }
@@ -655,6 +655,7 @@ CFontzPacket_chr (Driver *drvthis, int x, int y, char c)
y--; y--;
x--; x--;
if ((x >= 0) && (y >= 0) && (x < p->width) && (y < p->height))
p->framebuf[(y * p->width) + x] = (p->model == 633) p->framebuf[(y * p->width) + x] = (p->model == 633)
? c ? c
: CFontz_charmap[(unsigned) c]; : CFontz_charmap[(unsigned) c];
@@ -673,6 +674,7 @@ CFontzPacket_raw_chr (Driver *drvthis, int x, int y, unsigned char c)
y--; y--;
x--; x--;
if ((x >= 0) && (y >= 0) && (x < p->width) && (y < p->height))
p->framebuf[(y * p->width) + x] = c; p->framebuf[(y * p->width) + x] = c;
} }
@@ -921,7 +923,8 @@ CFontzPacket_init_vbar (Driver *drvthis)
if (p->ccmode != vbar) { if (p->ccmode != vbar) {
if (p->ccmode != standard) { if (p->ccmode != standard) {
/* Not supported(yet) */ /* Not supported(yet) */
report(RPT_WARNING, "CFontzPacket_init_vbar: Cannot combine two modes using user defined characters"); report(RPT_WARNING, "%s: init_vbar: cannot combine two modes using user defined characters",
drvthis->name);
return; return;
} }
p->ccmode = vbar; p->ccmode = vbar;
@@ -1008,7 +1011,8 @@ CFontzPacket_init_hbar (Driver *drvthis)
if (p->ccmode != hbar) { if (p->ccmode != hbar) {
if (p->ccmode != standard) { if (p->ccmode != standard) {
/* Not supported(yet) */ /* Not supported(yet) */
report(RPT_WARNING, "CFontzPacket_init_hbar: Cannot combine two modes using user defined characters"); report(RPT_WARNING, "%s: init_hbar: cannot combine two modes using user defined characters",
drvthis->name);
return; return;
} }
p->ccmode = hbar; p->ccmode = hbar;
@@ -1148,7 +1152,8 @@ char bignum_ccs[8][CELLWIDTH*CELLHEIGHT] = {
if (p->ccmode != standard) { if (p->ccmode != standard) {
/* Not supported (yet) */ /* Not supported (yet) */
report(RPT_WARNING, "CFontzPacket_init_num: Cannot combine two modes using user defined characters"); report(RPT_WARNING, "%s: init_num: cannot combine two modes using user defined characters",
drvthis->name);
return; return;
} }
@@ -1501,11 +1506,14 @@ CFontzPacket_string (Driver *drvthis, int x, int y, char string[])
x--; x--;
y--; y--;
for (i = 0; string[i] != '\0'; i++) { if ((y < 0) || (y >= p->height))
return;
for (i = 0; (string[i] != '\0') && (x < p->width); i++, x++) {
/* Check for buffer overflows... */ /* Check for buffer overflows... */
if ((y * p->width) + x + i > (p->width * p->height)) if (x >= 0)
break; p->framebuf[(y * p->width) + x] =
p->framebuf[(y * p->width) + x + i] = (p->model == 633) (p->model == 633)
? string[i] ? string[i]
: CFontz_charmap[(unsigned) string[i]]; : CFontz_charmap[(unsigned) string[i]];
} }