harmonize coding style and messagesi; add a few checks

This commit is contained in:
marschap
2006-04-08 19:36:55 +00:00
parent c7569db6ce
commit 8cdb3fef07
+88 -47
View File
@@ -251,11 +251,10 @@
typedef struct p {
int type;
int port;
char * keymap[KEYPAD_MAXX];
char * framebuf_text;
char * lcd_contents_text;
char * framebuf_graph;
char * lcd_contents_graph;
unsigned char * framebuf_text;
unsigned char * lcd_contents_text;
unsigned char * framebuf_graph;
unsigned char * lcd_contents_graph;
int width, height;
int cellwidth, cellheight;
int graph_width, graph_height;
@@ -321,41 +320,43 @@ sed1330_init( Driver * drvthis )
debug(RPT_DEBUG, "%s( %p )", __FUNCTION__, drvthis);
// Alocate and store private p
p = (PrivateData *) malloc( sizeof(PrivateData) );
if( ! p )
p = (PrivateData *) calloc(1, sizeof(PrivateData));
if (p == NULL)
return -1;
if (drvthis->store_private_ptr(drvthis, p))
return -1;
// Clear keymap
memset( p->keymap, 0, sizeof(p->keymap) );
// initialize PrivateData
p->framebuf_text = NULL;
p->lcd_contents_text = NULL;
p->framebuf_graph = NULL;
p->lcd_contents_graph = NULL;
// READ THE CONFIG FILE
// Port
p->port = drvthis->config_get_int( drvthis->name, "port", 0, 0x278 );
p->port = drvthis->config_get_int(drvthis->name, "Port", 0, 0x278);
// Char size
s = drvthis->config_get_string( drvthis->name, "cellsize", 0, NULL );
if( !s ) {
s = "6x10";
}
s = drvthis->config_get_string(drvthis->name, "CellSize", 0, "6x10");
if (sscanf(s, "%dx%d", &(p->cellwidth), &(p->cellheight)) != 2) {
report( RPT_ERR, "SED1330: cannot interpret cellsize value: %s", s );
report(RPT_ERR, "%s: cannot interpret CellSize %s",
drvthis->name, s);
return -1;
}
if( p->cellwidth < 6 || p->cellwidth > 8
|| p->cellheight < 7 || p->cellheight > 16 ) {
report( RPT_ERR, "SED1330: cellsize exceeds allowed range of 6x7 to 8x16" );
if ((p->cellwidth < 6) || (p->cellwidth > 8)
|| (p->cellheight < 7) || (p->cellheight > 16)) {
report(RPT_ERR, "%s: CellSize exceeds allowed range of 6x7 to 8x16",
drvthis->name);
return -1;
}
// Type
s = drvthis->config_get_string( drvthis->name, "type", 0, NULL );
if( !s ) {
report( RPT_ERR, "SED1330: you need to specify the display type" );
s = drvthis->config_get_string(drvthis->name, "Type", 0, NULL);
if (s == NULL) {
report(RPT_ERR, "%s: you need to specify the display type",
drvthis->name);
return -1;
} else if (strcmp(s, "G321D") == 0) {
p->type = TYPE_G321D;
@@ -379,10 +380,10 @@ sed1330_init( Driver * drvthis )
p->graph_height = 64;
} else {
report( RPT_ERR, "SED1330: Unknown display type: %s", s );
report(RPT_ERR, "%s: Unknown display type %s", drvthis->name, s);
return -1;
}
report( RPT_INFO, "SED1330: Using LCD type: %s", s );
report(RPT_INFO, "%s: Using LCD type %s", drvthis->name, s);
// Keypad ?
p->have_keypad = drvthis->config_get_bool(drvthis->name, "keypad", 0, 0);
@@ -403,9 +404,10 @@ sed1330_init( Driver * drvthis )
s = drvthis->config_get_string(drvthis->name, buf, 0, NULL);
// Was a key specified in the config file ?
if( s ) {
if (s != NULL) {
p->keyMapDirect[x] = strdup(s);
report( RPT_INFO, "SED1330: Direct key %d: \"%s\"", x, s );
report(RPT_INFO, "%s: Direct key %d: \"%s\"",
drvthis->name, x, s );
}
}
@@ -421,9 +423,10 @@ sed1330_init( Driver * drvthis )
s = drvthis->config_get_string(drvthis->name, buf, 0, NULL);
// Was a key specified in the config file ?
if( s ) {
if (s != NULL) {
p->keyMapMatrix[y][x] = strdup(s);
report( RPT_INFO, "SED1330: Matrix key %d,%d: \"%s\"", x, y, s );
report(RPT_INFO, "%s: Matrix key %d,%d: \"%s\"",
drvthis->name, x, y, s);
}
}
}
@@ -435,29 +438,37 @@ sed1330_init( Driver * drvthis )
p->bytesperline = (p->graph_width - 1) / p->cellwidth + 1;
p->textlines_in_memory = (p->graph_height - 1) / p->cellheight + 1;
report( RPT_INFO, "SED1330: Text size: %dx%d", p->width, p->height );
report( RPT_INFO, "SED1330: Cell size: %dx%d", p->cellwidth, p->cellheight );
report( RPT_INFO, "SED1330: Graphical size: %dx%d", p->graph_width, p->graph_height );
report(RPT_INFO, "%s: Text size: %dx%d", drvthis->name, p->width, p->height);
report(RPT_INFO, "%s: Cell size: %dx%d", drvthis->name, p->cellwidth, p->cellheight);
report(RPT_INFO, "%s: Graphical size: %dx%d", drvthis->name, p->graph_width, p->graph_height);
// Allocate framebuffer
p->framebuf_text = (unsigned char *) malloc(p->bytesperline * p->textlines_in_memory);
if( ! p->framebuf_text )
if (p->framebuf_text == NULL) {
report(RPT_ERR, "%s: error allocating text framebuffer", drvthis->name);
return -1;
}
memset(p->framebuf_text, ' ', p->bytesperline * p->textlines_in_memory);
p->lcd_contents_text = (unsigned char *) malloc(p->bytesperline * p->textlines_in_memory);
if( ! p->lcd_contents_text )
if (p->lcd_contents_text == NULL) {
report(RPT_ERR, "%s: error allocating lcd_contents_text", drvthis->name);
return -1;
}
memset(p->lcd_contents_text, 0, p->bytesperline * p->textlines_in_memory);
p->framebuf_graph = (unsigned char *) malloc(p->bytesperline * p->graph_height);
if( ! p->framebuf_graph )
if (p->framebuf_graph == NULL) {
report(RPT_ERR, "%s: error allocating graphical framebuffer", drvthis->name);
return -1;
}
memset(p->framebuf_graph, 0, p->bytesperline * p->graph_height);
p->lcd_contents_graph = (unsigned char *) malloc(p->bytesperline * p->graph_height);
if( ! p->lcd_contents_graph )
if (p->lcd_contents_graph == NULL) {
report(RPT_ERR, "%s: error allocating lcd_contents_graph", drvthis->name);
return -1;
}
memset(p->lcd_contents_graph, 0xFF, p->bytesperline * p->graph_height);
// Arrange for access to port
@@ -467,7 +478,8 @@ sed1330_init( Driver * drvthis )
port_access(p->port+2);
if (timing_init() == -1) {
report(RPT_ERR, "timing_init: failed (%s)\n", strerror(errno));
report(RPT_ERR, "%s: timing_init() failed (%s)",
drvthis->name, strerror(errno));
return -1;
}
@@ -528,6 +540,8 @@ sed1330_init( Driver * drvthis )
sed1330_flush(drvthis); // Clear the contents of the LCD
sed1330_command(p, CMD_DISP_EN, 0, NULL); // And display on
report(RPT_DEBUG, "%s: init() done", drvthis->name);
return 0;
}
@@ -566,8 +580,31 @@ sed1330_close( Driver * drvthis )
debug(RPT_DEBUG, "%s()", __FUNCTION__);
if (p != NULL) {
int i, j;
for (i = 0; i < KEYPAD_MAXX; i++) {
if (p->keyMapDirect[i] != NULL)
free(p->keyMapDirect[i]);
for (j = 0; j < KEYPAD_MAXY; j++) {
if (p->keyMapMatrix[i][j] != NULL)
free(p->keyMapMatrix[i][j]);
}
}
if (p->framebuf_text != NULL)
free(p->framebuf_text);
if (p->lcd_contents_text != NULL)
free(p->lcd_contents_text);
if (p->framebuf_graph != NULL)
free(p->framebuf_graph);
if (p->lcd_contents_graph != NULL)
free(p->lcd_contents_graph);
free(p);
}
drvthis->store_private_ptr(drvthis, NULL);
}
/////////////////////////////////////////////////////////////////
@@ -609,7 +646,7 @@ sed1330_clear( Driver * drvthis )
debug(RPT_DEBUG, "%s()", __FUNCTION__);
memset(p->framebuf_text, ' ', p->bytesperline * p->textlines_in_memory);
memset( p->framebuf_graph, 0, p->bytesperline * p->graph_height );
memset(p->framebuf_graph, '\0', p->bytesperline * p->graph_height);
}
@@ -620,12 +657,12 @@ MODULE_EXPORT void
sed1330_string( Driver * drvthis, int x, int y, char *str )
{
PrivateData * p = drvthis->private_data;
char * dest;
unsigned char * dest;
int offset, len;
debug(RPT_DEBUG, "%s( x=%d, y=%d, str=\"%s\" )", __FUNCTION__, x, y, str);
if( y < 1 || y > p->height ) {
if ((y < 1) || (y > p->height)) {
return; // outside framebuf
}
// Calculate offset and length to write
@@ -657,7 +694,7 @@ sed1330_chr( Driver * drvthis, int x, int y, char c )
debug(RPT_DEBUG, "%s( x=%d, y=%d, c='%c' )", __FUNCTION__, x, y, c);
if( y < 1 || y > p->height || x < 1 || x > p->width ) {
if ((y < 1) || (y > p->height) || (x < 1) || (x > p->width)) {
return; // outside framebuf
}
p->framebuf_text[(y-1)*p->bytesperline + (x-1)] = c;
@@ -720,7 +757,6 @@ sed1330_flush( Driver * drvthis )
memcpy(p->lcd_contents_graph + start_pos, p->framebuf_graph + start_pos, len);
}
}
}
@@ -791,8 +827,8 @@ sed1330_line ( PrivateData * p, int x1, int y1, int x2, int y2, char pattern )
/* Draw from left to right... */
more_x = 1;
for (x = x1, y = y1; x <= x2; x++) {
int more_y = 1; /* always draw one pixel */
while (more_y) {
/* set the pixel */
sed1330_set_pixel(p, x, y, pattern);
@@ -854,7 +890,8 @@ sed1330_vbar( Driver * drvthis, int x, int y, int len, int promille, int pattern
debug(RPT_DEBUG, "%s( x=%d, y=%d, len=%d, promille=%d, pattern=%d )", __FUNCTION__, x, y, len, promille, pattern);
sed1330_rect ( p, (x-1) * p->cellwidth, y * p->cellheight, x * p->cellwidth - 2, y * p->cellheight - (long) len * p->cellheight * promille / 1000 - 1, 1 );
sed1330_rect(p, (x-1) * p->cellwidth, y * p->cellheight,
x * p->cellwidth - 2, y * p->cellheight - (long) len * p->cellheight * promille / 1000 - 1, 1);
}
@@ -869,7 +906,8 @@ sed1330_hbar( Driver * drvthis, int x, int y, int len, int promille, int pattern
debug(RPT_DEBUG, "%s( x=%d, y=%d, len=%d, promille=%d, pattern=%d )", __FUNCTION__, x, y, len, promille, pattern);
sed1330_rect ( p, (x-1) * p->cellwidth, (y-1) * p->cellheight, (x-1) * p->cellwidth + (long) len * p->cellwidth * promille / 1000 - 1, y * p->cellheight - 3, 1 );
sed1330_rect(p, (x-1) * p->cellwidth, (y-1) * p->cellheight,
(x-1) * p->cellwidth + (long) len * p->cellwidth * promille / 1000 - 1, y * p->cellheight - 3, 1);
}
@@ -917,7 +955,8 @@ sed1330_heartbeat( Driver * drvthis, int type )
debug(RPT_DEBUG, "%s( type=%d )", __FUNCTION__, type);
if( type == HEARTBEAT_OFF ) return;
if (type == HEARTBEAT_OFF)
return;
p->framebuf_text[p->width-1] = ' ';
//whichIcon = (! ((timer + 4) & 5));
@@ -966,7 +1005,8 @@ sed1330_get_key(Driver *drvthis)
char * keystr = NULL;
struct timeval curr_time, time_diff;
if( ! p->have_keypad ) return NULL;
if (!p->have_keypad)
return NULL;
gettimeofday(&curr_time,NULL);
@@ -995,7 +1035,8 @@ sed1330_get_key(Driver *drvthis)
// It's a new keypress
p->pressed_key_time = curr_time;
p->pressed_key_repetitions = 0;
report( RPT_INFO, "sed1330_get_key: Key pressed: %s (%d,%d)\n", keystr, scancode&0x0F, (scancode&0xF0)>>4 );
report(RPT_INFO, "%s: Key pressed: %s (%d,%d)",
drvthis->name, keystr, scancode&0x0F, (scancode&0xF0)>>4);
}
}