harmonize coding style and messages; add a few checks

This commit is contained in:
marschap
2006-04-08 20:51:52 +00:00
parent 2656f53743
commit bf47e2e0ed
+50 -44
View File
@@ -85,11 +85,13 @@ lcterm_init (Driver *drvthis)
// Alocate and store private data // Alocate and store private data
p = (PrivateData *) calloc(1, sizeof(PrivateData)); p = (PrivateData *) calloc(1, sizeof(PrivateData));
if( ! p ) if (p == NULL)
return -1; return -1;
if (drvthis->store_private_ptr(drvthis, p)) if (drvthis->store_private_ptr(drvthis, p))
return -1; return -1;
// initialize private data
p->fd = -1;
p->ccmode = p->last_ccmode = CCMODE_STANDARD; p->ccmode = p->last_ccmode = CCMODE_STANDARD;
// READ CONFIG FILE: // READ CONFIG FILE:
@@ -97,55 +99,48 @@ lcterm_init (Driver *drvthis)
strncpy(device, drvthis->config_get_string(drvthis->name , "Device" , 0 , DEFAULT_DEVICE), strncpy(device, drvthis->config_get_string(drvthis->name , "Device" , 0 , DEFAULT_DEVICE),
sizeof(device)); sizeof(device));
device[sizeof(device)-1] = '\0'; device[sizeof(device)-1] = '\0';
report (RPT_INFO,"LCTERM: Using device: %s", device); report(RPT_INFO, "%s: using Device %s", drvthis->name, device);
/* Get and parse size */ /* Get and parse size */
{ {
int w, h; int w, h;
char *s = drvthis->config_get_string( drvthis->name, "size", 0, "16x2" ); char *s = drvthis->config_get_string(drvthis->name, "Size", 0, "16x2");
debug(RPT_DEBUG, "lcterm_init: reading size: %s\n", s ); debug(RPT_DEBUG, "%s: reading size: %s", __FUNCTION__, s);
if ((sscanf(s, "%dx%d", &w, &h) != 2) if ((sscanf(s, "%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, "LCDTERM: Cannot read size: %s. Using default value.\n", s); report(RPT_WARNING, "%s: cannot read Size: %s; using default %s",
drvthis->name, s, "16x2");
sscanf("16x2", "%dx%d", &w, &h); sscanf("16x2", "%dx%d", &w, &h);
} }
p->width = w; p->width = w;
p->height = h; p->height = h;
} }
report (RPT_INFO,"LCTERM: Using size: %dx%d\n",p->width, p->height); report(RPT_INFO, "%s: using Size: %dx%d", drvthis->name, p->width, p->height);
p->framebuf = malloc(p->width * p->height); p->framebuf = malloc(p->width * p->height);
p->last_framebuf = malloc(p->width * p->height); p->last_framebuf = malloc(p->width * p->height);
if (!p->framebuf || !p->last_framebuf) { if ((p->framebuf == NULL) || (p->last_framebuf == NULL)) {
report(RPT_ERR, "Error: unable to create LCTERM 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);
memset(p->last_framebuf, ' ', p->width * p->height); memset(p->last_framebuf, ' ', p->width * p->height);
// Set up io port correctly, and open it... // Set up io port correctly, and open it...
debug( RPT_DEBUG, "LCTERM: Opening serial device: %s", device); debug(RPT_DEBUG, "%s: Opening serial device: %s", drvthis->name, device);
p->fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY); p->fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
if (p->fd == -1) if (p->fd == -1) {
{ report(RPT_ERR, "%s: open(%) failed (%s)", drvthis->name, device, strerror(errno));
switch (errno) if (errno == EACCES)
{ report(RPT_ERR, "%s: make sure you have rw access to %s!", drvthis->name, device);
case ENOENT: report( RPT_ERR, "LCTERM: lcterm_init() failed: Device file missing: %s\n", device);
break;
case EACCES: report( RPT_ERR, "LCTERM: lcterm_init() failed: Could not open device: %s\n", device);
report( RPT_ERR, "LCTERM: lcterm_init() failed: Make sure you have rw access to %s!\n", device);
break;
default: report( RPT_ERR, "LCTERM: lcterm_init() failed (%s)\n", strerror (errno));
break;
}
return -1; return -1;
} else {
report (RPT_INFO, "opened LCTERM display on %s\n", device);
} }
report(RPT_INFO, "%s: opened display on %s", drvthis->name, device);
tcgetattr(p->fd, &portset); tcgetattr(p->fd, &portset);
#ifdef HAVE_CFMAKERAW #ifdef HAVE_CFMAKERAW
/* The easy way: */ /* The easy way: */
@@ -166,7 +161,10 @@ lcterm_init (Driver *drvthis)
// clear the display, disable cursor, disable key scanning // clear the display, disable cursor, disable key scanning
write(p->fd, "\x1a\x16\x1bK", 4); write(p->fd, "\x1a\x16\x1bK", 4);
return 0;
report(RPT_DEBUG, "%s: init() done", drvthis->name);
return 1;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -177,19 +175,22 @@ lcterm_close (Driver *drvthis)
{ {
PrivateData *p = (PrivateData *) drvthis->private_data; PrivateData *p = (PrivateData *) drvthis->private_data;
if(p->framebuf) if (p != NULL) {
if (p->framebuf != NULL)
free(p->framebuf); free(p->framebuf);
if(p->last_framebuf) if (p->last_framebuf != NULL)
free(p->last_framebuf); free(p->last_framebuf);
// clear the display, disable key scanning // clear the display, disable key scanning
if (p->fd) if (p->fd >= 0) {
{
write(p->fd, "\x1a\x1bK", 3); write(p->fd, "\x1a\x1bK", 3);
close(p->fd); close(p->fd);
} }
free(p);
}
drvthis->store_private_ptr(drvthis, NULL); drvthis->store_private_ptr(drvthis, NULL);
report (RPT_INFO, "LCTERM: closed"); report(RPT_INFO, "%s: closed", drvthis->name);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -199,6 +200,7 @@ MODULE_EXPORT int
lcterm_width (Driver *drvthis) lcterm_width (Driver *drvthis)
{ {
PrivateData *p = (PrivateData *) drvthis->private_data; PrivateData *p = (PrivateData *) drvthis->private_data;
return p->width; return p->width;
} }
@@ -209,6 +211,7 @@ MODULE_EXPORT int
lcterm_height (Driver *drvthis) lcterm_height (Driver *drvthis)
{ {
PrivateData *p = (PrivateData *) drvthis->private_data; PrivateData *p = (PrivateData *) drvthis->private_data;
return p->height; return p->height;
} }
@@ -219,6 +222,7 @@ MODULE_EXPORT void
lcterm_clear (Driver *drvthis) lcterm_clear (Driver *drvthis)
{ {
PrivateData *p = (PrivateData *) drvthis->private_data; PrivateData *p = (PrivateData *) drvthis->private_data;
memset(p->framebuf, ' ', p->width * p->height); memset(p->framebuf, ' ', p->width * p->height);
p->ccmode = CCMODE_STANDARD; p->ccmode = CCMODE_STANDARD;
} }
@@ -269,7 +273,7 @@ lcterm_chr (Driver *drvthis, int x, int y, char ch)
y--; y--;
x--; x--;
//debug(RPT_DEBUG, "lcterm_chr: x=%d, y=%d, chr=%x", x,y,ch); //debug(RPT_DEBUG, "lcterm_chr: x=%d, y=%d, chr=%x", x,y,ch);
if (x >= 0 && x < p->width && y >= 0 && y < p->height) if ((x >= 0) && (x < p->width) && (y >= 0) && (y < p->height))
p->framebuf[y * p->width + x] = ch; p->framebuf[y * p->width + x] = ch;
} }
@@ -284,7 +288,7 @@ lcterm_string (Driver *drvthis, int x, int y, char *s)
x --; // Convert 1-based coords to 0-based x --; // Convert 1-based coords to 0-based
y --; y --;
for (; *s && x < p->width; x++) for ( ; (*s != '\0') && (x < p->width); x++)
p->framebuf[y * p->width + x] = *s++; p->framebuf[y * p->width + x] = *s++;
} }
@@ -304,16 +308,14 @@ lcterm_set_char (Driver *drvthis, int n, char *dat)
int data; int data;
unsigned char buf[11]; unsigned char buf[11];
if (n < 0 || n > 7 || !dat) if ((n < 0) || (n > 7) || (!dat))
return; return;
buf[0] = 0x1F; buf[0] = 0x1F;
buf[1] = 8 * n; // CG RAM address */ buf[1] = 8 * n; // CG RAM address */
for (row = 0; row < 8; row++) for (row = 0; row < 8; row++) {
{
data = 0; data = 0;
for (col = 0; col < 5; col++) for (col = 0; col < 5; col++) {
{
data <<= 1; data <<= 1;
data |= (*dat++ != 0); data |= (*dat++ != 0);
} }
@@ -405,12 +407,13 @@ lcterm_init_vbar (Driver *drvthis)
if (p->last_ccmode == CCMODE_VBAR) /* Work already done */ if (p->last_ccmode == CCMODE_VBAR) /* Work already done */
return; return;
if( p->ccmode != CCMODE_STANDARD ) if (p->ccmode != CCMODE_STANDARD) {
{
/* Not supported (yet) */ /* Not supported (yet) */
report( RPT_WARNING, "lcterm_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 = p->last_ccmode = CCMODE_VBAR; p->ccmode = p->last_ccmode = CCMODE_VBAR;
lcterm_set_char(drvthis, 1, vbar_1); lcterm_set_char(drvthis, 1, vbar_1);
@@ -484,12 +487,13 @@ lcterm_init_hbar (Driver *drvthis)
if (p->last_ccmode == CCMODE_HBAR) /* Work already done */ if (p->last_ccmode == CCMODE_HBAR) /* Work already done */
return; return;
if( p->ccmode != CCMODE_STANDARD ) if (p->ccmode != CCMODE_STANDARD) {
{
/* Not supported (yet) */ /* Not supported (yet) */
report( RPT_WARNING, "lcterm_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 = p->last_ccmode = CCMODE_HBAR; p->ccmode = p->last_ccmode = CCMODE_HBAR;
lcterm_set_char(drvthis, 1, hbar_1); lcterm_set_char(drvthis, 1, hbar_1);
@@ -612,13 +616,15 @@ lcterm_init_num (Driver *drvthis)
if (p->ccmode != CCMODE_STANDARD) { if (p->ccmode != CCMODE_STANDARD) {
/* Not supported (yet) */ /* Not supported (yet) */
report( RPT_WARNING, "lcterm_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;
} }
p->ccmode = p->last_ccmode = CCMODE_BIGNUM;
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
lcterm_set_char(drvthis, i, bignum_ccs[i]); lcterm_set_char(drvthis, i, bignum_ccs[i]);
p->ccmode = p->last_ccmode = CCMODE_BIGNUM;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////