harmonize coding style and messages; add more checks

This commit is contained in:
marschap
2006-04-08 13:20:59 +00:00
parent fe53c43754
commit 3b23168977
+64 -90
View File
@@ -47,7 +47,7 @@
////////////////////// Base "class" to derive from ///////////////////////
//////////////////////////////////////////////////////////////////////////
static int fd;
static int fd = -1;
static int width = 0;
static int height = 0;
static int cellwidth = 5;
@@ -349,9 +349,7 @@ bayrad_init(Driver *drvthis)
height = 2;
framebuf = malloc(width * height);
if(!framebuf)
{
if (framebuf == NULL) {
bayrad_close(drvthis);
report(RPT_ERR, "bayrad_init: Error: unable to create BayRAD framebuffer.");
return -1;
@@ -368,6 +366,7 @@ bayrad_init(Driver *drvthis)
strncpy(device, drvthis->config_get_string(drvthis->name, "Device", 0,
BAYRAD_DEFAULT_DEVICE), sizeof(device));
device[sizeof(device)-1] = '\0';
report(RPT_INFO, "%s: using Device %s", drvthis->name, device);
/* What speed to use */
speed = drvthis->config_get_int(drvthis->name, "Speed", 0, 9600);
@@ -377,19 +376,19 @@ bayrad_init(Driver *drvthis)
else if (speed == 9600) speed = B9600;
else if (speed == 19200) speed = B19200;
else {
report(RPT_WARNING, "bayrad_init: Illegal speed: %d. Must be one of 1200, 2400, 9600 or 19200. Using default.\n", speed);
report(RPT_WARNING, "%s: illegal Speed %d; must be one of 1200, 2400, 9600 or 19200; using default %d",
drvthis->name, speed, 9600);
speed = B9600;
}
// Set up io port correctly, and open it...
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
report(RPT_ERR, "bayrad_init: failed (%s)", strerror(errno));
if (fd == -1) {
report(RPT_ERR, "%s: open(%s) failed (%s)", drvthis->name, device, strerror(errno));
return -1;
}
//else debug(RPT_DEBUG, "bayrad_init: opened device %s\n", device);
//else debug(RPT_DEBUG, "bayrad_init: opened device %s", device);
tcflush(fd, TCIOFLUSH);
@@ -422,10 +421,11 @@ bayrad_init(Driver *drvthis)
/*** Open the port write-only, then fork off a process that reads chars ?!!? ***/
/* Reset and clear the BayRAD */
write(fd, "\x80\x86\x00\x1a\x1e", 5); // sync,reset to type 0, clear screen, home
report(RPT_DEBUG, "%s: init() done", drvthis->name);
return 0;
}
@@ -437,15 +437,17 @@ bayrad_init(Driver *drvthis)
MODULE_EXPORT void
bayrad_close(Driver * drvthis)
{
//debug(RPT_DEBUG, "\nClosing BayRAD.\n");
//debug(RPT_DEBUG, "Closing BayRAD");
if (fd >= 0) {
write(fd, "\x8e\x00", 2); // Backlight OFF
if(framebuf) free(framebuf);
framebuf = NULL;
close(fd);
}
if (framebuf != NULL)
free(framebuf);
framebuf = NULL;
}
/////////////////////////////////////////////////////////////////
// Returns the display width
@@ -475,7 +477,6 @@ bayrad_clear(Driver * drvthis)
{
memset(framebuf, ' ', width * height);
ccmode = CCMODE_STANDARD;
}
@@ -485,15 +486,11 @@ bayrad_clear(Driver * drvthis)
MODULE_EXPORT void
bayrad_flush(Driver * drvthis)
{
//debug(RPT_DEBUG, "\nBayRAD flush");
//debug(RPT_DEBUG, "BayRAD flush");
write(fd, "\x80\x1e", 2); //sync, home
write(fd, framebuf, 20);
write(fd, "\x1e\x0a", 2); //home, LF
write(fd, framebuf+20, 20);
return;
}
/////////////////////////////////////////////////////////////////
@@ -504,33 +501,29 @@ MODULE_EXPORT void
bayrad_string(Driver * drvthis, int x, int y, char string[])
{
int i;
unsigned char c;
//debug(RPT_DEBUG, "\nPutting string %s at %i, %i", string, x, y);
//debug(RPT_DEBUG, "Putting string %s at %i, %i", string, x, y);
x -= 1; // Convert 1-based coords to 0-based...
y -= 1;
x--; // Convert 1-based coords to 0-based...
y--;
for (i = 0; string[i] != '\0'; i++) {
unsigned char c = (unsigned char) string[i];
for(i=0; string[i]; i++)
{
// Check for buffer overflows...
if ((y * width) + x + i > (width * height))
break;
c = (unsigned char) string[i];
if(c> 0x7F && c < 0x98)
{
if ((c > 0x7F) && (c < 0x98)) {
//c &= 0x7F;
report(RPT_WARNING, "bayrad_strign: Illegal char %#x requested in bayrad_string()!", c);
report(RPT_WARNING, "%s: illegal char 0x%02X requested in bayrad_string()",
drvthis->name, c);
c = ' ';
}
if (c < 8) /* The custom characters are mapped at 0x98 - 0x9F, */
c += 0x98; /* as 0x07 makes a beep instead of printing a character */
framebuf[(y * width) + x + i] = c;
}
}
@@ -542,17 +535,16 @@ bayrad_string(Driver * drvthis, int x, int y, char string[])
MODULE_EXPORT void
bayrad_chr(Driver * drvthis, int x, int y, char c)
{
unsigned char ch;
unsigned char ch = (unsigned char) c;
//debug(RPT_DEBUG, "\nPutting char %c (%#x) at %i, %i", c, c, x, y);
//debug(RPT_DEBUG, "Putting char %c (%#x) at %i, %i", c, c, x, y);
y--;
x--;
ch = (unsigned char) c;
if(ch > 0x7F && ch < 0x98)
{
report(RPT_WARNING, "Illegal char %#x requested in bayrad_chr()!", ch);
if ((ch > 0x7F) && (ch < 0x98)) {
report(RPT_WARNING, "%s: illegal char 0x%02X requested in bayrad_chr()",
drvthis->name, c);
ch = ' ';
}
@@ -567,23 +559,21 @@ bayrad_chr(Driver * drvthis, int x, int y, char c)
MODULE_EXPORT void
bayrad_backlight(Driver * drvthis, int on)
{
/* This violates the LCDd driver model, but it does leave the
* backlight control entirely in the hands of the user via
* BayRAd buttons, which is nice, since the backlights have
* a finite lifespan... */
if(on)
{;
if (on) {
;
//write(fd, "\x8e\x0f", 2);
//debug(RPT_DEBUG, "Backlight ON\n");
//debug(RPT_DEBUG, "Backlight ON");
}
else
{;
else {
;
//write(fd, "\x8e\x00", 2);
//debug(RPT_DEBUG, "Backlight OFF\n");
//debug(RPT_DEBUG, "Backlight OFF");
}
}
//////////////////////////////////////////////////////////////////////
@@ -592,7 +582,7 @@ bayrad_backlight(Driver * drvthis, int on)
void
bayrad_init_vbar(Driver * drvthis)
{
//debug(RPT_DEBUG,"Init Vertical bars.\n");
//debug(RPT_DEBUG,"Init Vertical bars.");
if (ccmode == CCMODE_VBAR) {
/* Work already done */
@@ -601,7 +591,8 @@ bayrad_init_vbar(Driver * drvthis)
if (ccmode != CCMODE_STANDARD) {
/* Not supported (yet) */
report( RPT_WARNING, "bayrad_init_vbar: Cannot combine two modes using user defined characters" );
report(RPT_WARNING, "%s: cannot combine two modes using user defined characters",
drvthis->name);
return;
}
ccmode = CCMODE_VBAR;
@@ -613,9 +604,6 @@ bayrad_init_vbar(Driver * drvthis)
bayrad_set_char(drvthis, 5, bar_up[4]);
bayrad_set_char(drvthis, 6, bar_up[5]);
bayrad_set_char(drvthis, 7, bar_up[6]);
return;
}
//////////////////////////////////////////////////////////////////////
@@ -624,7 +612,7 @@ bayrad_init_vbar(Driver * drvthis)
void
bayrad_init_hbar(Driver * drvthis)
{
//debug(RPT_DEBUG,"Init Horizontal bars.\n");
//debug(RPT_DEBUG,"Init Horizontal bars.");
if (ccmode == CCMODE_HBAR) {
/* Work already done */
@@ -633,7 +621,8 @@ bayrad_init_hbar(Driver * drvthis)
if (ccmode != CCMODE_STANDARD) {
/* Not supported (yet) */
report( RPT_WARNING, "bayrad_init_hbar: Cannot combine two modes using user defined characters" );
report(RPT_WARNING, "%s: cannot combine two modes using user defined characters",
drvthis->name);
return;
}
ccmode = CCMODE_HBAR;
@@ -643,8 +632,6 @@ bayrad_init_hbar(Driver * drvthis)
bayrad_set_char(drvthis, 3, bar_right[2]);
bayrad_set_char(drvthis, 4, bar_right[3]);
bayrad_set_char(drvthis, 5, bar_right[4]);
return;
}
//////////////////////////////////////////////////////////////////////
@@ -653,7 +640,7 @@ return;
void
bayrad_init_num(Driver * drvthis)
{
// debug(RPT_DEBUG,"Big Numbers.\n");
// debug(RPT_DEBUG,"Big Numbers.");
}
//////////////////////////////////////////////////////////////////////
@@ -662,7 +649,7 @@ bayrad_init_num(Driver * drvthis)
MODULE_EXPORT void
bayrad_num(Driver * drvthis, int x, int num)
{
// debug(RPT_DEBUG,"BigNum(%i, %i)\n", x, num);
// debug(RPT_DEBUG,"BigNum(%i, %i)", x, num);
}
//////////////////////////////////////////////////////////////////////
@@ -673,28 +660,23 @@ bayrad_set_char(Driver * drvthis, int n, char *dat)
{
char out[4];
int row, col;
char letter;
//debug(RPT_DEBUG, "\nSet char %i", n);
//debug(RPT_DEBUG, "Set char %i", n);
if(n < 0 || n > 7) /* Do we want to the aliased indexes as well (0x98 - 0x9F?) */
if ((n < 0) || (n > 7)) /* Do we want to the aliased indexes as well (0x98 - 0x9F?) */
return;
if (!dat)
return;
n = 0x40 + (n * 8); /* Set n to the proper location in CG RAM */
/* Set the LCD to accept data for rewrite-able char n */
snprintf(out, sizeof(out), "\x88%c", n);
snprintf(out, sizeof(out), "\x88%c", 0x40 + (n * 8));
write(fd, out, 2);
for(row=0; row<cellheight; row++)
{
letter = 0;
for(col=0; col<cellwidth; col++)
{
for (row = 0; row < cellheight; row++) {
char letter = 0;
for (col = 0; col < cellwidth; col++) {
letter <<= 1;
letter |= (dat[(row*cellwidth) + col] > 0);
}
@@ -703,8 +685,6 @@ bayrad_set_char(Driver * drvthis, int n, char *dat)
/* return the LCD to normal operation */
write(fd, "\x80", 1);
return;
}
/////////////////////////////////////////////////////////////////
@@ -713,7 +693,7 @@ return;
MODULE_EXPORT void
bayrad_vbar(Driver * drvthis, int x, int y, int len, int promille, int options)
{
//debug(RPT_DEBUG, "\nVbar at %i, length %i", x, len);
//debug(RPT_DEBUG, "Vbar at %i, length %i", x, len);
/* x and y are the start position of the bar.
* The bar by default grows in the 'up' direction
@@ -733,7 +713,7 @@ bayrad_vbar(Driver * drvthis, int x, int y, int len, int promille, int options)
MODULE_EXPORT void
bayrad_hbar(Driver * drvthis, int x, int y, int len, int promille, int options)
{
//debug(RPT_DEBUG, "\nHbar at %i,%i; length %i", x, y, len);
//debug(RPT_DEBUG, "Hbar at %i,%i; length %i", x, y, len);
/* x and y are the start position of the bar.
* The bar by default grows in the 'right' direction
@@ -779,7 +759,7 @@ bayrad_get_key(Driver * drvthis)
int retval;
static char ret_val[2] = { 0, 0 };
//debug(RPT_DEBUG, "\nBayRAD get_key...");
//debug(RPT_DEBUG, "BayRAD get_key...");
/* Check for incoming data. Turn backlight ON/OFF as needed */
@@ -791,30 +771,24 @@ bayrad_get_key(Driver * drvthis)
twait.tv_sec = 0;
twait.tv_usec = 0;
if(select(fd+1, &brfdset, NULL, NULL, &twait))
{
if (select(fd+1, &brfdset, NULL, NULL, &twait)) {
retval = read(fd, &readchar, 1);
if(retval > 0)
{
if (retval > 0) {
debug(RPT_INFO, "bayrad_get_key: Got key: %c", readchar);
if(readchar == 'Y')
{
if (readchar == 'Y') {
write(fd, "\x8e\x0f", 2);
}
else if(readchar == 'N')
{
else if (readchar == 'N') {
write(fd, "\x8e\x00", 2);
}
} /* if read returned data */
else
{ /* Read error */
report(RPT_ERR, "bayrad_get_key: Read error in BayRAD getchar.");
else {
/* Read error */
report(RPT_ERR, "%s: Read error in BayRAD getchar.", drvthis->name);
}
} /* if select */
else
{
else {
;//debug(RPT_DEBUG, "No BayRAD data present.");
}