harmonize coding style and messages; add a few checks
This commit is contained in:
+50
-44
@@ -85,11 +85,13 @@ lcterm_init (Driver *drvthis)
|
||||
|
||||
// Alocate and store private data
|
||||
p = (PrivateData *) calloc(1, sizeof(PrivateData));
|
||||
if( ! p )
|
||||
if (p == NULL)
|
||||
return -1;
|
||||
if (drvthis->store_private_ptr(drvthis, p))
|
||||
return -1;
|
||||
|
||||
// initialize private data
|
||||
p->fd = -1;
|
||||
p->ccmode = p->last_ccmode = CCMODE_STANDARD;
|
||||
|
||||
// READ CONFIG FILE:
|
||||
@@ -97,55 +99,48 @@ lcterm_init (Driver *drvthis)
|
||||
strncpy(device, drvthis->config_get_string(drvthis->name , "Device" , 0 , DEFAULT_DEVICE),
|
||||
sizeof(device));
|
||||
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 */
|
||||
{
|
||||
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)
|
||||
|| (w <= 0) || (w > LCD_MAX_WIDTH)
|
||||
|| (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);
|
||||
}
|
||||
p->width = w;
|
||||
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->last_framebuf = malloc(p->width * p->height);
|
||||
if (!p->framebuf || !p->last_framebuf) {
|
||||
report(RPT_ERR, "Error: unable to create LCTERM framebuffer.\n");
|
||||
if ((p->framebuf == NULL) || (p->last_framebuf == NULL)) {
|
||||
report(RPT_ERR, "%s: unable to create framebuffer", drvthis->name);
|
||||
return -1;
|
||||
}
|
||||
memset(p->framebuf, ' ', p->width * p->height);
|
||||
memset(p->last_framebuf, ' ', p->width * p->height);
|
||||
|
||||
// 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);
|
||||
if (p->fd == -1)
|
||||
{
|
||||
switch (errno)
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (p->fd == -1) {
|
||||
report(RPT_ERR, "%s: open(%) failed (%s)", drvthis->name, device, strerror(errno));
|
||||
if (errno == EACCES)
|
||||
report(RPT_ERR, "%s: make sure you have rw access to %s!", drvthis->name, device);
|
||||
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);
|
||||
#ifdef HAVE_CFMAKERAW
|
||||
/* The easy way: */
|
||||
@@ -166,7 +161,10 @@ lcterm_init (Driver *drvthis)
|
||||
|
||||
// clear the display, disable cursor, disable key scanning
|
||||
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;
|
||||
|
||||
if(p->framebuf)
|
||||
if (p != NULL) {
|
||||
if (p->framebuf != NULL)
|
||||
free(p->framebuf);
|
||||
if(p->last_framebuf)
|
||||
if (p->last_framebuf != NULL)
|
||||
free(p->last_framebuf);
|
||||
|
||||
// clear the display, disable key scanning
|
||||
if (p->fd)
|
||||
{
|
||||
if (p->fd >= 0) {
|
||||
write(p->fd, "\x1a\x1bK", 3);
|
||||
close(p->fd);
|
||||
}
|
||||
|
||||
free(p);
|
||||
}
|
||||
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)
|
||||
{
|
||||
PrivateData *p = (PrivateData *) drvthis->private_data;
|
||||
|
||||
return p->width;
|
||||
}
|
||||
|
||||
@@ -209,6 +211,7 @@ MODULE_EXPORT int
|
||||
lcterm_height (Driver *drvthis)
|
||||
{
|
||||
PrivateData *p = (PrivateData *) drvthis->private_data;
|
||||
|
||||
return p->height;
|
||||
}
|
||||
|
||||
@@ -219,6 +222,7 @@ MODULE_EXPORT void
|
||||
lcterm_clear (Driver *drvthis)
|
||||
{
|
||||
PrivateData *p = (PrivateData *) drvthis->private_data;
|
||||
|
||||
memset(p->framebuf, ' ', p->width * p->height);
|
||||
p->ccmode = CCMODE_STANDARD;
|
||||
}
|
||||
@@ -269,7 +273,7 @@ lcterm_chr (Driver *drvthis, int x, int y, char ch)
|
||||
y--;
|
||||
x--;
|
||||
//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;
|
||||
}
|
||||
|
||||
@@ -284,7 +288,7 @@ lcterm_string (Driver *drvthis, int x, int y, char *s)
|
||||
x --; // Convert 1-based coords to 0-based
|
||||
y --;
|
||||
|
||||
for (; *s && x < p->width; x++)
|
||||
for ( ; (*s != '\0') && (x < p->width); x++)
|
||||
p->framebuf[y * p->width + x] = *s++;
|
||||
}
|
||||
|
||||
@@ -304,16 +308,14 @@ lcterm_set_char (Driver *drvthis, int n, char *dat)
|
||||
int data;
|
||||
unsigned char buf[11];
|
||||
|
||||
if (n < 0 || n > 7 || !dat)
|
||||
if ((n < 0) || (n > 7) || (!dat))
|
||||
return;
|
||||
|
||||
buf[0] = 0x1F;
|
||||
buf[1] = 8 * n; // CG RAM address */
|
||||
for (row = 0; row < 8; row++)
|
||||
{
|
||||
for (row = 0; row < 8; row++) {
|
||||
data = 0;
|
||||
for (col = 0; col < 5; col++)
|
||||
{
|
||||
for (col = 0; col < 5; col++) {
|
||||
data <<= 1;
|
||||
data |= (*dat++ != 0);
|
||||
}
|
||||
@@ -405,12 +407,13 @@ lcterm_init_vbar (Driver *drvthis)
|
||||
if (p->last_ccmode == CCMODE_VBAR) /* Work already done */
|
||||
return;
|
||||
|
||||
if( p->ccmode != CCMODE_STANDARD )
|
||||
{
|
||||
if (p->ccmode != CCMODE_STANDARD) {
|
||||
/* 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;
|
||||
}
|
||||
|
||||
p->ccmode = p->last_ccmode = CCMODE_VBAR;
|
||||
|
||||
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 */
|
||||
return;
|
||||
|
||||
if( p->ccmode != CCMODE_STANDARD )
|
||||
{
|
||||
if (p->ccmode != CCMODE_STANDARD) {
|
||||
/* 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;
|
||||
}
|
||||
|
||||
p->ccmode = p->last_ccmode = CCMODE_HBAR;
|
||||
|
||||
lcterm_set_char(drvthis, 1, hbar_1);
|
||||
@@ -612,13 +616,15 @@ lcterm_init_num (Driver *drvthis)
|
||||
|
||||
if (p->ccmode != CCMODE_STANDARD) {
|
||||
/* 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;
|
||||
}
|
||||
|
||||
p->ccmode = p->last_ccmode = CCMODE_BIGNUM;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
lcterm_set_char(drvthis, i, bignum_ccs[i]);
|
||||
p->ccmode = p->last_ccmode = CCMODE_BIGNUM;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user