harmonize coding style and messages; add a few checks and fixes

This commit is contained in:
marschap
2006-04-08 20:23:25 +00:00
parent 9be262139b
commit 2587d669db
+42 -32
View File
@@ -46,7 +46,7 @@
#include "server/configfile.h" #include "server/configfile.h"
*/ */
static int fd; static int fd = -1;
static char *framebuf = NULL; static char *framebuf = NULL;
static unsigned char heartbeatCharacter; static unsigned char heartbeatCharacter;
static fd_set fdset; static fd_set fdset;
@@ -152,16 +152,17 @@ ms6931_init (Driver *drvthis)
/*Which serial device should be used*/ /*Which serial device should be used*/
strncpy(device, drvthis->config_get_string(drvthis->name, "Device", 0, MS6931_DEF_DEVICE), sizeof(device)); strncpy(device, drvthis->config_get_string(drvthis->name, "Device", 0, MS6931_DEF_DEVICE), sizeof(device));
device[sizeof(device)-1]=0; device[sizeof(device)-1] = '\0';
report (RPT_INFO,"ms6931_init: Using device: %s", device); report(RPT_INFO,"%s: using Device %s", drvthis->name, device);
/*Which size*/ /*Which size*/
strncpy(size, drvthis->config_get_string(drvthis->name , "Size", 0, MS6931_DEF_SIZE), sizeof(size)); strncpy(size, drvthis->config_get_string(drvthis->name , "Size", 0, MS6931_DEF_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, "ms6931_init: Cannot read size: %s. Using default value.", size); report(RPT_WARNING, "%s: cannot read Size: %s; using default %s",
drvthis->name, size, MS6931_DEF_SIZE);
sscanf(MS6931_DEF_SIZE, "%dx%d", &w, &h); sscanf(MS6931_DEF_SIZE, "%dx%d", &w, &h);
} }
width = w; width = w;
@@ -169,22 +170,21 @@ ms6931_init (Driver *drvthis)
/* get the character to use for heartbeat */ /* get the character to use for heartbeat */
heartbeatCharacter = (unsigned char)(drvthis->config_get_int(drvthis->name, "HeartbeatCharacter", 0, (int)'*') & 0xff); heartbeatCharacter = (unsigned char)(drvthis->config_get_int(drvthis->name, "HeartbeatCharacter", 0, (int)'*') & 0xff);
if (!heartbeatCharacter if ((heartbeatCharacter == '\0')
|| heartbeatCharacter > 127 || (heartbeatCharacter > 127)
|| charTable[heartbeatCharacter] == ' ') || (charTable[heartbeatCharacter] == ' ')) {
{
heartbeatCharacter = '*'; heartbeatCharacter = '*';
} }
/* Set up io port correctly, and open it...*/ /* Set up io port correctly, and open it...*/
debug( RPT_DEBUG, "ms6931_init: Opening serial device: %s", device); debug(RPT_DEBUG, "%s: Opening serial device: %s", drvthis->name, device);
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY); fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1) { if (fd == -1) {
report (RPT_ERR, "ms6931_init: open() failed (%s)", strerror (errno)); report(RPT_ERR, "%s: open() failed (%s)", drvthis->name, strerror(errno));
return -1; return -1;
} else { } else {
fcntl(fd, F_SETOWN, getpid()); fcntl(fd, F_SETOWN, getpid());
report (RPT_INFO, "ms6931_init: opened display on %s", device); report(RPT_INFO, "%s: opened display on %s", drvthis->name, device);
} }
FD_ZERO(&fdset); FD_ZERO(&fdset);
@@ -212,14 +212,18 @@ ms6931_init (Driver *drvthis)
// create framebuffer and clear display // create framebuffer and clear display
framebuf = (unsigned char *) malloc(width * height); framebuf = (unsigned char *) malloc(width * height);
if (framebuf == NULL) {
report(RPT_ERR, "%s: unable to create framebuffer", drvthis->name);
return -1;
}
ms6931_clear(drvthis); ms6931_clear(drvthis);
selectTimeout.tv_sec = 0; selectTimeout.tv_sec = 0;
selectTimeout.tv_usec = 0; selectTimeout.tv_usec = 0;
report (RPT_DEBUG, "ms6931_init: done"); report(RPT_DEBUG, "%s: init() done", drvthis->name);
return fd; return 1;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -232,14 +236,14 @@ ms6931_close (Driver *drvthis)
ms6931_flush(drvthis); ms6931_flush(drvthis);
ms6931_backlight (drvthis, BACKLIGHT_OFF); ms6931_backlight (drvthis, BACKLIGHT_OFF);
if (fd >= 0)
close(fd); close(fd);
if (framebuf) { if (framebuf != NULL)
free(framebuf); free(framebuf);
framebuf = NULL; framebuf = NULL;
}
report (RPT_DEBUG, "ms6931_close: done"); report(RPT_DEBUG, "%s: close() done", drvthis->name);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -272,7 +276,7 @@ ms6931_height (Driver *drvthis)
MODULE_EXPORT void MODULE_EXPORT void
ms6931_chr (Driver *drvthis, int x, int y, char c) ms6931_chr (Driver *drvthis, int x, int y, char c)
{ {
if (x>width || y>height) if ((x > width) || (y > height))
return; return;
y--; y--;
x--; x--;
@@ -298,7 +302,7 @@ ms6931_backlight (Driver *drvthis, int on)
out[2] = 0x01; out[2] = 0x01;
} }
ms6931_write(out, 3); ms6931_write(out, 3);
report (RPT_DEBUG, "ms6931_backlight: switched to %d", on); report(RPT_DEBUG, "%s: backlight: switched to %d", drvthis->name, on);
} }
saved_state = on; saved_state = on;
} }
@@ -328,7 +332,7 @@ ms6931_cursor (Driver *drvthis, int x, int y, int state)
out[2] = 3; out[2] = 3;
} }
ms6931_write(out, 3); ms6931_write(out, 3);
report (RPT_DEBUG, "ms6931_cursor: switched to %d", state); report(RPT_DEBUG, "%s: cursor: switched to %d", drvthis->name, state);
} }
saved_state = state; saved_state = state;
} }
@@ -355,13 +359,15 @@ ms6931_string (Driver *drvthis, int x, int y, char string[])
x--; x--;
y--; y--;
for (i = 0; string[i]; i++) { for (i = 0; string[i] != '\0'; i++) {
if (string[i] == -1) { unsigned char c = (unsigned char) string[i];
string[i] = ' ';
} if (c == 255)
c = ' ';
if ((y * width) + x + i > (width * height)) if ((y * width) + x + i > (width * height))
break; break;
framebuf[(y * width) + x + i] = charTable[(unsigned char)string[i]]; framebuf[(y * width) + x + i] = charTable[c];
} }
} }
@@ -384,7 +390,8 @@ ms6931_hbar (Driver *drvthis, int x, int y, int len, int promille, int pattern)
if ((len * promille) % 1000 > 500) if ((len * promille) % 1000 > 500)
size++; size++;
report(RPT_DEBUG, "ms6931_hbar: len=%d, size=%d, promile=%d", len, size, promille); report(RPT_DEBUG, "%s: hbar: len=%d, size=%d, promile=%d",
drvthis->name, len, size, promille);
memset(bar, ' ', len); memset(bar, ' ', len);
memset(bar, '*', size); memset(bar, '*', size);
@@ -403,7 +410,7 @@ ms6931_heartbeat (Driver *drvthis, int state)
char whichChar; char whichChar;
static int saved_state = HEARTBEAT_ON; static int saved_state = HEARTBEAT_ON;
report (RPT_DEBUG, "ms6931_heartbeat: state=%d", state); report(RPT_DEBUG, "%s: heartbeat: state=%d", drvthis->name, state);
if (state) if (state)
saved_state = state; saved_state = state;
@@ -428,7 +435,8 @@ ms6931_get_key (Driver *drvthis)
const char *key = NULL; const char *key = NULL;
if ((ret = select(FD_SETSIZE, &fdset, NULL, NULL, &selectTimeout)) < 0) { if ((ret = select(FD_SETSIZE, &fdset, NULL, NULL, &selectTimeout)) < 0) {
report(RPT_DEBUG, "ms6931_get_key: select() failed (%s)", strerror(errno)); report(RPT_DEBUG, "%s: get_key: select() failed (%s)",
drvthis->name, strerror(errno));
return NULL; return NULL;
} }
if (!ret) { if (!ret) {
@@ -440,7 +448,8 @@ ms6931_get_key (Driver *drvthis)
return NULL; return NULL;
if ((ret = read(fd, &buf, 1)) < 0) { if ((ret = read(fd, &buf, 1)) < 0) {
report(RPT_DEBUG, "ms6931_get_key: read() failed (%s)", strerror(errno)); report(RPT_DEBUG, "%s: get_key: read() failed (%s)",
drvthis->name, strerror(errno));
return NULL; return NULL;
} }
if (ret == 1) { if (ret == 1) {
@@ -455,11 +464,12 @@ ms6931_get_key (Driver *drvthis)
key = "Down"; key = "Down";
break; break;
default: default:
report(RPT_DEBUG, "ms6931_get_key: illegal key 0x%02x", (int)buf); report(RPT_DEBUG, "%s get_key: illegal key 0x%02X",
drvthis->name, buf);
return NULL; return NULL;
} }
report(RPT_DEBUG, "ms6931_get_key: returning %s", key); report(RPT_DEBUG, "%s: get_key: returns %s", drvthis->name, key);
return key; return key;
} }