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
+85 -75
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;
@@ -148,50 +148,50 @@ ms6931_init (Driver *drvthis)
char device[200] = MS6931_DEF_DEVICE; char device[200] = MS6931_DEF_DEVICE;
char size[200] = MS6931_DEF_SIZE; char size[200] = MS6931_DEF_SIZE;
debug(RPT_INFO, "ms6931_init: init(%p)", drvthis ); debug(RPT_INFO, "ms6931_init: init(%p)", 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",
sscanf( MS6931_DEF_SIZE , "%dx%d", &w, &h ); drvthis->name, size, MS6931_DEF_SIZE);
sscanf(MS6931_DEF_SIZE, "%dx%d", &w, &h);
} }
width = w; width = w;
height = h; height = h;
/* 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);
FD_SET (fd, &fdset); FD_SET(fd, &fdset);
// set terminal // set terminal
tcgetattr (fd, &portset); tcgetattr(fd, &portset);
#ifdef HAVE_CFMAKERAW #ifdef HAVE_CFMAKERAW
cfmakeraw( &portset ); cfmakeraw( &portset );
#else #else
@@ -201,25 +201,29 @@ ms6931_init (Driver *drvthis)
portset.c_cflag &= ~( CSIZE | PARENB | CRTSCTS ); portset.c_cflag &= ~( CSIZE | PARENB | CRTSCTS );
portset.c_cflag |= CS8 | CREAD | CLOCAL ; portset.c_cflag |= CS8 | CREAD | CLOCAL ;
#endif #endif
cfsetospeed (&portset, B9600); cfsetospeed(&portset, B9600);
// cfsetispeed (&portset, B0); // cfsetispeed(&portset, B0);
tcsetattr (fd, TCSANOW, &portset); tcsetattr(fd, TCSANOW, &portset);
// set display to comunications mode // set display to comunications mode
ms6931_write("~\040", 2); ms6931_write("~\040", 2);
sleep(1); sleep(1);
// 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);
close (fd); if (fd >= 0)
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);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -247,7 +251,7 @@ ms6931_close (Driver *drvthis)
MODULE_EXPORT void MODULE_EXPORT void
ms6931_flush (Driver *drvthis) ms6931_flush (Driver *drvthis)
{ {
ms6931_draw_frame (framebuf); ms6931_draw_frame(framebuf);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -272,11 +276,11 @@ 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--;
framebuf[(y * width) + x] = charTable[(unsigned char)c]; framebuf[(y * width) + x] = charTable[(unsigned char) c];
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -290,15 +294,15 @@ ms6931_backlight (Driver *drvthis, int on)
if (on != saved_state) { if (on != saved_state) {
switch (on) { switch (on) {
case BACKLIGHT_OFF: case BACKLIGHT_OFF:
out[2] = 0x00; out[2] = 0x00;
break; break;
case BACKLIGHT_ON: case BACKLIGHT_ON:
default: default:
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;
} }
@@ -316,19 +320,19 @@ ms6931_cursor (Driver *drvthis, int x, int y, int state)
if (state != saved_state) { if (state != saved_state) {
switch (state) { switch (state) {
case CURSOR_OFF: case CURSOR_OFF:
out[2] = 0; out[2] = 0;
break; break;
case CURSOR_UNDER: case CURSOR_UNDER:
out[2] = 2; out[2] = 2;
break; break;
case CURSOR_DEFAULT_ON: case CURSOR_DEFAULT_ON:
case CURSOR_BLOCK: case CURSOR_BLOCK:
default: default:
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;
} }
@@ -340,7 +344,7 @@ MODULE_EXPORT void
ms6931_clear (Driver *drvthis) ms6931_clear (Driver *drvthis)
{ {
// ms6931_write("~\042", 2); // ms6931_write("~\042", 2);
memset (framebuf, ' ', width * height); memset(framebuf, ' ', width * height);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -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,10 +390,11 @@ 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);
bar[len] = '\0'; bar[len] = '\0';
ms6931_string(drvthis, x, y, bar); ms6931_string(drvthis, x, y, bar);
@@ -403,14 +410,14 @@ 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;
if (state == HEARTBEAT_ON) { if (state == HEARTBEAT_ON) {
whichChar = ((timer + 4) & 5) ? heartbeatCharacter : ' '; whichChar = ((timer + 4) & 5) ? heartbeatCharacter : ' ';
ms6931_chr (drvthis, width, 1, whichChar); ms6931_chr(drvthis, width, 1, whichChar);
ms6931_flush (drvthis); ms6931_flush(drvthis);
} }
timer++; timer++;
timer &= 0x0f; timer &= 0x0f;
@@ -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;
} }