harmonize coding style and messages; add more checksi; simplyfy slightly

This commit is contained in:
marschap
2006-04-08 14:59:21 +00:00
parent ef4f0c6f35
commit 79a827c169
+24 -22
View File
@@ -100,6 +100,7 @@ NoritakeVFD_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;
@@ -110,7 +111,7 @@ NoritakeVFD_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));
@@ -118,8 +119,8 @@ NoritakeVFD_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;
@@ -128,8 +129,8 @@ NoritakeVFD_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;
@@ -138,8 +139,8 @@ NoritakeVFD_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;
@@ -157,7 +158,7 @@ NoritakeVFD_init (Driver *drvthis)
p->fd = open (p->device, O_RDWR | O_NOCTTY | O_NDELAY); p->fd = open (p->device, O_RDWR | O_NOCTTY | O_NDELAY);
if (p->fd == -1) { if (p->fd == -1) {
report (RPT_ERR, "%s: open() of %s failed (%s)\n", __FUNCTION__, p->device, strerror (errno)); report(RPT_ERR, "%s: open() of %s failed (%s)", drvthis->name, p->device, strerror(errno));
return -1; return -1;
} }
@@ -187,7 +188,7 @@ NoritakeVFD_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);
@@ -195,7 +196,7 @@ NoritakeVFD_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);
@@ -205,13 +206,13 @@ NoritakeVFD_init (Driver *drvthis)
if (reboot) { if (reboot) {
NoritakeVFD_reboot(drvthis); NoritakeVFD_reboot(drvthis);
sleep(4); sleep(4);
reboot = 0;
} }
NoritakeVFD_hidecursor(drvthis); NoritakeVFD_hidecursor(drvthis);
NoritakeVFD_set_brightness(drvthis, 1, p->brightness); NoritakeVFD_set_brightness(drvthis, 1, p->brightness);
NoritakeVFD_autoscroll(drvthis, 0); NoritakeVFD_autoscroll(drvthis, 0);
report (RPT_DEBUG, "%s: done\n", __FUNCTION__); report(RPT_DEBUG, "%s: init() done", drvthis->name);
return 0; return 0;
} }
@@ -224,6 +225,7 @@ NoritakeVFD_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)
@@ -299,7 +301,7 @@ NoritakeVFD_flush_box (Driver *drvthis, int lft, int top, int rgt, int bot)
int y; int y;
char out[LCD_MAX_WIDTH]; char out[LCD_MAX_WIDTH];
debug (RPT_DEBUG, "%s: flush_box (%i,%i)-(%i,%i)\n", __FUNCTION__, lft, top, rgt, bot); debug(RPT_DEBUG, "%s: flush_box(%i,%i)-(%i,%i)", __FUNCTION__, lft, top, rgt, bot);
for (y = top; y <= bot; y++) { for (y = top; y <= bot; y++) {
int pos = y*p->width; int pos = y*p->width;
@@ -318,9 +320,9 @@ MODULE_EXPORT void
NoritakeVFD_chr (Driver *drvthis, int x, int y, char c) NoritakeVFD_chr (Driver *drvthis, int x, int y, char c)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
y--; y--;
x--; x--;
/*if (c < 32 && (int)c >= 0) /*if (c < 32 && (int)c >= 0)
c += 128;*/ c += 128;*/
p->framebuf[(y * p->width) + x ] = c; p->framebuf[(y * p->width) + x ] = c;
@@ -366,10 +368,8 @@ NoritakeVFD_autoscroll (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", 0x12); snprintf(out, sizeof(out), "%c", (on) ? 0x12 : 0x11);
else
snprintf (out, sizeof(out), "%c", 0x11);
write(p->fd, out, 1); write(p->fd, out, 1);
} }
@@ -381,6 +381,7 @@ NoritakeVFD_hidecursor (Driver *drvthis)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
char out[4]; char out[4];
snprintf(out, sizeof(out), "%c", 0x14); snprintf(out, sizeof(out), "%c", 0x14);
write(p->fd, out, 1); write(p->fd, out, 1);
} }
@@ -393,6 +394,7 @@ NoritakeVFD_reboot (Driver *drvthis)
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
char out[4]; char out[4];
snprintf(out, sizeof(out), "%c%c", 0x1B, 'I'); snprintf(out, sizeof(out), "%c%c", 0x1B, 'I');
write(p->fd, out, 2); write(p->fd, out, 2);
} }
@@ -567,7 +569,6 @@ NoritakeVFD_hbar (Driver *drvthis, int x, int y, int len, int promille, int opti
NoritakeVFD_init_hbar(drvthis); NoritakeVFD_init_hbar(drvthis);
//lib_hbar_static(drvthis, x, y, len, promille, options, p->cellheight, 0); //lib_hbar_static(drvthis, x, y, len, promille, options, p->cellheight, 0);
} }
@@ -669,7 +670,6 @@ NoritakeVFD_draw_frame (Driver *drvthis, unsigned char *dat)
return; return;
for (i = 0; i < p->height; i++) { for (i = 0; i < p->height; i++) {
row = dat + (p->width * i); row = dat + (p->width * i);
b_row = p->backingstore + (p->width * i); b_row = p->backingstore + (p->width * i);
@@ -696,6 +696,7 @@ MODULE_EXPORT void
NoritakeVFD_clear (Driver *drvthis) NoritakeVFD_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);
} }
@@ -708,10 +709,11 @@ MODULE_EXPORT void
NoritakeVFD_string (Driver *drvthis, int x, int y, char string[]) NoritakeVFD_string (Driver *drvthis, int x, int y, char string[])
{ {
PrivateData *p = drvthis->private_data; PrivateData *p = drvthis->private_data;
int i;
x--; x--;
y--; y--;
int i; for (i = 0; string[i] != '\0'; i++) {
for (i = 0; string[i]; i++) {
// Check for buffer overflows... // Check for buffer overflows...
if ((y * p->width) + x + i > (p->width * p->height)) if ((y * p->width) + x + i > (p->width * p->height))
break; break;