harmonize coding style and messages; add more checks
This commit is contained in:
+62
-96
@@ -163,7 +163,7 @@ static char CwLnx_parse_keypad_setting (Driver *drvthis, char * keyname, char de
|
|||||||
s = drvthis->config_get_string(drvthis->name, keyname, 0, NULL);
|
s = drvthis->config_get_string(drvthis->name, keyname, 0, NULL);
|
||||||
if (s != NULL) {
|
if (s != NULL) {
|
||||||
strncpy(buf, s, sizeof(buf));
|
strncpy(buf, s, sizeof(buf));
|
||||||
buf[sizeof(buf)-1]=0;
|
buf[sizeof(buf)-1] = '\0';
|
||||||
return_val = buf[0];
|
return_val = buf[0];
|
||||||
} else {
|
} else {
|
||||||
return_val = default_value;
|
return_val = default_value;
|
||||||
@@ -174,6 +174,7 @@ static char CwLnx_parse_keypad_setting (Driver *drvthis, char * keyname, char de
|
|||||||
int Read_LCD(int fd, char *c, int size)
|
int Read_LCD(int fd, char *c, int size)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = read(fd, c, size);
|
rc = read(fd, c, size);
|
||||||
/* usleep(DELAY); */
|
/* usleep(DELAY); */
|
||||||
return rc;
|
return rc;
|
||||||
@@ -182,18 +183,18 @@ int Read_LCD(int fd, char *c, int size)
|
|||||||
int Write_LCD(int fd, char *c, int size)
|
int Write_LCD(int fd, char *c, int size)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = write(fd, c, size);
|
rc = write(fd, c, size);
|
||||||
/* Debuging code to be cleaned when very stable */
|
/* Debuging code to be cleaned when very stable */
|
||||||
/*
|
/*
|
||||||
if (size == 1) {
|
if (size == 1) {
|
||||||
if (*c >= 0)
|
if (*c >= 0)
|
||||||
printf("%3d ", *c);
|
printf("%3d ", *c);
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
if (*c+256==254)
|
if (*c+256==254)
|
||||||
|
|
||||||
printf("\n%3d ", *c+256);
|
printf("\n%3d ", *c+256);
|
||||||
else printf("%3d ", *c+256);
|
else
|
||||||
|
printf("%3d ", *c+256);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
@@ -497,7 +498,6 @@ int CwLnx_init(Driver * drvthis)
|
|||||||
int speed = DEFAULT_SPEED;
|
int speed = DEFAULT_SPEED;
|
||||||
char size[200] = DEFAULT_SIZE;
|
char size[200] = DEFAULT_SIZE;
|
||||||
|
|
||||||
char buf[256] = "";
|
|
||||||
int tmp;
|
int tmp;
|
||||||
int w;
|
int w;
|
||||||
int h;
|
int h;
|
||||||
@@ -507,14 +507,14 @@ int CwLnx_init(Driver * drvthis)
|
|||||||
|
|
||||||
/* Alocate and store private data */
|
/* Alocate and store private data */
|
||||||
p = (PrivateData *) malloc(sizeof(PrivateData));
|
p = (PrivateData *) malloc(sizeof(PrivateData));
|
||||||
if( ! p )
|
if (p == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
if (drvthis->store_private_ptr(drvthis, p))
|
if (drvthis->store_private_ptr(drvthis, p))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Initialise the PrivateData structure */
|
/* Initialise the PrivateData structure */
|
||||||
|
|
||||||
p->framebuf = NULL;
|
p->framebuf = NULL;
|
||||||
|
p->backingstore = NULL;
|
||||||
|
|
||||||
/* height and width are computed from DEFAULT_SIZE */
|
/* height and width are computed from DEFAULT_SIZE */
|
||||||
/* p->width = DEFAULT_WIDTH; */
|
/* p->width = DEFAULT_WIDTH; */
|
||||||
@@ -532,23 +532,23 @@ int CwLnx_init(Driver * drvthis)
|
|||||||
p->saved_heartbeat = -1;
|
p->saved_heartbeat = -1;
|
||||||
p->heartbeat = 0;
|
p->heartbeat = 0;
|
||||||
|
|
||||||
debug(RPT_INFO, "CwLnx: init(%p)", drvthis);
|
debug(RPT_INFO, "%s: init(%p)", drvthis->name, drvthis);
|
||||||
|
|
||||||
/* Read config file */
|
/* Read config file */
|
||||||
|
|
||||||
|
|
||||||
/* Which serial device should be used */
|
/* Which serial device should be used */
|
||||||
strncpy(device, drvthis->config_get_string(drvthis->name, "Device", 0, DEFAULT_DEVICE), sizeof(device));
|
strncpy(device, drvthis->config_get_string(drvthis->name, "Device", 0, DEFAULT_DEVICE), sizeof(device));
|
||||||
device[sizeof(device) - 1] = 0;
|
device[sizeof(device) - 1] = '\0';
|
||||||
report(RPT_INFO, "CwLnx: 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, DEFAULT_SIZE), sizeof(size));
|
strncpy(size, drvthis->config_get_string(drvthis->name, "Size", 0, DEFAULT_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, "CwLnx: Cannot read size: %s. Using default value.\n", size);
|
report(RPT_WARNING, "%s: cannot read Size: %s; using default %s",
|
||||||
|
drvthis->name, size, DEFAULT_SIZE);
|
||||||
sscanf(DEFAULT_SIZE, "%dx%d", &w, &h);
|
sscanf(DEFAULT_SIZE, "%dx%d", &w, &h);
|
||||||
}
|
}
|
||||||
p->width = w;
|
p->width = w;
|
||||||
@@ -567,45 +567,30 @@ int CwLnx_init(Driver * drvthis)
|
|||||||
speed = B19200;
|
speed = B19200;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
speed = DEFAULT_SPEED;
|
speed = B19200;
|
||||||
|
report(RPT_WARNING, "%s: Speed must be 9600 or 19200. Using default %d",
|
||||||
switch (speed) {
|
drvthis->name, DEFAULT_SPEED);
|
||||||
case B9600:
|
|
||||||
strncpy(buf, "9600", sizeof(buf));
|
|
||||||
break;
|
|
||||||
case B19200:
|
|
||||||
strncpy(buf, "19200", sizeof(buf));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
report(RPT_WARNING,
|
|
||||||
"CwLnx: Speed must be 9600 or 19200. Using default value of %s baud!",
|
|
||||||
buf);
|
|
||||||
strncpy(buf, "", sizeof(buf));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* do we have a keypad? */
|
/* do we have a keypad? */
|
||||||
if (drvthis->config_get_bool(drvthis->name , "Keypad", 0, 0)) {
|
if (drvthis->config_get_bool(drvthis->name , "Keypad", 0, 0)) {
|
||||||
report (RPT_INFO, "CwLnx: Config file tell us we have a keypad...\n");
|
report(RPT_INFO, "%s: Config tells us we have a keypad", drvthis->name);
|
||||||
p->have_keypad = 1;
|
p->have_keypad = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* keypad test mode? */
|
/* keypad test mode? */
|
||||||
if (drvthis->config_get_bool(drvthis->name , "keypad_test_mode", 0, 0)) {
|
if (drvthis->config_get_bool(drvthis->name , "keypad_test_mode", 0, 0)) {
|
||||||
report (RPT_INFO, "CwLnx: Config tell us to test the keypad mapping...\n");
|
report(RPT_INFO, "%s: Config tells us to test the keypad mapping", drvthis->name);
|
||||||
p->keypad_test_mode = 1;
|
p->keypad_test_mode = 1;
|
||||||
stay_in_foreground = 1;
|
stay_in_foreground = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read the keypad mapping only if we have a keypad. */
|
/* read the keypad mapping only if we have a keypad. */
|
||||||
if (p->have_keypad)
|
if (p->have_keypad) {
|
||||||
{
|
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
/* Read keymap */
|
/* Read keymap */
|
||||||
for(x=0; x<MaxKeyMap; x++ )
|
for (x = 0; x < MaxKeyMap; x++) {
|
||||||
{
|
|
||||||
char buf[40];
|
char buf[40];
|
||||||
|
|
||||||
/* First fill with default value */
|
/* First fill with default value */
|
||||||
@@ -620,38 +605,38 @@ int CwLnx_init(Driver * drvthis)
|
|||||||
s = drvthis->config_get_string(drvthis->name, buf, 0, NULL);
|
s = drvthis->config_get_string(drvthis->name, buf, 0, NULL);
|
||||||
|
|
||||||
/* Was a key specified in the config file ? */
|
/* Was a key specified in the config file ? */
|
||||||
if( s ) {
|
if (s != NULL) {
|
||||||
p->KeyMap[x] = strdup(s);
|
p->KeyMap[x] = strdup(s);
|
||||||
/* printf("CwLnx: Key '%c' to \"%s\"\n", x+'A', s ); */
|
report(RPT_INFO, "%s: Key '%c' to \"%s\"", drvthis->name, x+'A', s);
|
||||||
report( RPT_INFO, "CwLnx: Key '%c' to \"%s\"", x+'A', s );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End of config file parsing */
|
/* End of config file parsing */
|
||||||
|
|
||||||
/* Allocate framebuffer memory */
|
/* Allocate framebuffer memory */
|
||||||
if (!p->framebuf) {
|
|
||||||
p->framebuf = malloc(p->width * p->height);
|
p->framebuf = malloc(p->width * p->height);
|
||||||
p->backingstore = calloc(p->width * p->height, 1);
|
if (p->framebuf == NULL) {
|
||||||
memset(p->backingstore, ' ', p->width * p->height);
|
report(RPT_ERR, "%s: unable to create framebuffer", drvthis->name);
|
||||||
}
|
|
||||||
|
|
||||||
if (!p->framebuf) {
|
|
||||||
report(RPT_ERR, "CwLnx: Error: unable to create framebuffer.\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p->backingstore = malloc(p->width * p->height);
|
||||||
|
if (p->backingstore == NULL) {
|
||||||
|
report(RPT_ERR, "%s: unable to create backingstore", drvthis->name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memset(p->backingstore, ' ', p->width * p->height);
|
||||||
|
|
||||||
|
|
||||||
/* Set up io port correctly, and open it... */
|
/* Set up io port correctly, and open it... */
|
||||||
debug(RPT_DEBUG, "CwLnx: 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);
|
p->fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||||
if (p->fd == -1) {
|
if (p->fd == -1) {
|
||||||
report(RPT_ERR, "CwLnx: init() failed (%s)\n", strerror(errno));
|
report(RPT_ERR, "%s: open(%s) failed (%s)", drvthis->name, device, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
|
||||||
report(RPT_INFO, "CwLnx: Opened display on %s", device);
|
|
||||||
}
|
}
|
||||||
|
report(RPT_INFO, "%s: opened display on %s", drvthis->name, device);
|
||||||
|
|
||||||
Init_Port(p->fd);
|
Init_Port(p->fd);
|
||||||
tcgetattr(p->fd, &portset_save);
|
tcgetattr(p->fd, &portset_save);
|
||||||
@@ -662,11 +647,11 @@ int CwLnx_init(Driver * drvthis)
|
|||||||
|
|
||||||
p->fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
|
p->fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||||
if (p->fd == -1) {
|
if (p->fd == -1) {
|
||||||
report(RPT_ERR, "CwLnx: init() failed (%s)\n", strerror(errno));
|
report(RPT_ERR, "%s: open(%s) failed (%s)", drvthis->name, device, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
|
||||||
report(RPT_INFO, "CwLnx: Opened display on %s", device);
|
|
||||||
}
|
}
|
||||||
|
report(RPT_INFO, "%s: opened display on %s", drvthis->name, device);
|
||||||
|
|
||||||
Init_Port(p->fd);
|
Init_Port(p->fd);
|
||||||
speed = B9600;
|
speed = B9600;
|
||||||
Setup_Port(p->fd, speed);
|
Setup_Port(p->fd, speed);
|
||||||
@@ -676,19 +661,13 @@ int CwLnx_init(Driver * drvthis)
|
|||||||
CwLnx_backlight(drvthis, 1); /* WHY force the backlight to on ? */
|
CwLnx_backlight(drvthis, 1); /* WHY force the backlight to on ? */
|
||||||
/* What is the default brightness ? */
|
/* What is the default brightness ? */
|
||||||
|
|
||||||
/* Set the functions the driver supports... */
|
|
||||||
|
|
||||||
/* TODO: WHY this ??? $$$ */
|
|
||||||
/* drvthis->daemonize = 1; */ /* make the server daemonize after initialization */
|
|
||||||
/* no daemonize in Driver ??? */
|
|
||||||
|
|
||||||
report(RPT_DEBUG, "CwLnx_init: done\n");
|
|
||||||
|
|
||||||
Clear_Screen(p->fd);
|
Clear_Screen(p->fd);
|
||||||
CwLnx_clear(drvthis);
|
CwLnx_clear(drvthis);
|
||||||
usleep(SETUP_DELAY);
|
usleep(SETUP_DELAY);
|
||||||
|
|
||||||
return p->fd;
|
report(RPT_DEBUG, "%s: init() done", drvthis->name);
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************
|
/******************************************************
|
||||||
@@ -699,19 +678,19 @@ CwLnx_close(Driver *drvthis)
|
|||||||
{
|
{
|
||||||
PrivateData * p = drvthis->private_data;
|
PrivateData * p = drvthis->private_data;
|
||||||
|
|
||||||
|
if (p != NULL) {
|
||||||
close(p->fd);
|
close(p->fd);
|
||||||
|
|
||||||
if (p->framebuf)
|
if (p->framebuf != NULL)
|
||||||
free(p->framebuf);
|
free(p->framebuf);
|
||||||
|
|
||||||
if (p->backingstore)
|
|
||||||
free(p->backingstore);
|
|
||||||
|
|
||||||
p->framebuf = NULL;
|
p->framebuf = NULL;
|
||||||
|
|
||||||
|
if (p->backingstore != NULL)
|
||||||
|
free(p->backingstore);
|
||||||
p->backingstore = NULL;
|
p->backingstore = NULL;
|
||||||
|
|
||||||
free(p);
|
free(p);
|
||||||
|
}
|
||||||
debug(RPT_DEBUG, "CwLnx: closed");
|
debug(RPT_DEBUG, "CwLnx: closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -755,21 +734,17 @@ CwLnx_flushtime_backlight(Driver *drvthis)
|
|||||||
int bright;
|
int bright;
|
||||||
|
|
||||||
if (((p->saved_backlight) && (!p->backlight))
|
if (((p->saved_backlight) && (!p->backlight))
|
||||||
|| ( (p->backlight)&&(!p->saved_backlight) ) )
|
|| ((p->backlight) && (!p->saved_backlight))) {
|
||||||
{
|
|
||||||
p->backlight = p->saved_backlight;
|
p->backlight = p->saved_backlight;
|
||||||
if (p->backlight)
|
if (p->backlight) {
|
||||||
{
|
|
||||||
Enable_Backlight(p->fd);
|
Enable_Backlight(p->fd);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
Disable_Backlight(p->fd);
|
Disable_Backlight(p->fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( p->brightness != p->saved_brightness )
|
if (p->brightness != p->saved_brightness) {
|
||||||
{
|
|
||||||
p->brightness = p->saved_brightness;
|
p->brightness = p->saved_brightness;
|
||||||
Backlight_Brightness(p->fd, p->brightness)
|
Backlight_Brightness(p->fd, p->brightness)
|
||||||
}
|
}
|
||||||
@@ -822,13 +797,11 @@ void Set_Insert(int fd, int row, int col)
|
|||||||
|
|
||||||
c = LCD_CMD;
|
c = LCD_CMD;
|
||||||
rc = Write_LCD(fd, &c, 1);
|
rc = Write_LCD(fd, &c, 1);
|
||||||
if (row==0 && col==0)
|
if (row == 0 && col == 0) {
|
||||||
{
|
|
||||||
c = LCD_INIT_INSERT;
|
c = LCD_INIT_INSERT;
|
||||||
rc = Write_LCD(fd, &c, 1);
|
rc = Write_LCD(fd, &c, 1);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
c = LCD_SET_INSERT;
|
c = LCD_SET_INSERT;
|
||||||
rc = Write_LCD(fd, &c, 1);
|
rc = Write_LCD(fd, &c, 1);
|
||||||
c = col;
|
c = col;
|
||||||
@@ -848,7 +821,7 @@ void CwLnx_flush_box(int lft, int top, int rgt, int bot)
|
|||||||
{
|
{
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
debug(RPT_DEBUG, "CwLnx: flush_box (%i,%i)-(%i,%i)\n", lft, top, rgt,
|
debug(RPT_DEBUG, "CwLnx: flush_box (%i,%i)-(%i,%i)", lft, top, rgt,
|
||||||
bot);
|
bot);
|
||||||
for (y = top; y <= bot; y++) {
|
for (y = top; y <= bot; y++) {
|
||||||
Set_Insert(fd, top, lft);
|
Set_Insert(fd, top, lft);
|
||||||
@@ -1381,23 +1354,17 @@ void CwLnx_draw_frame(Driver *drvthis, char *dat)
|
|||||||
|
|
||||||
/* printf("\n_draw_frame: %d\n", count); */
|
/* printf("\n_draw_frame: %d\n", count); */
|
||||||
|
|
||||||
for (i = 0; i < p->height; i++)
|
for (i = 0; i < p->height; i++) {
|
||||||
{
|
for (j = 0; j < p->width; j++) {
|
||||||
for (j = 0; j < p->width; j++)
|
if ((*q == *r) && !((0 < *q) && (*q < 16))) {
|
||||||
{
|
|
||||||
if ( (*q == *r) && !( (0<*q) && (*q<16) ) )
|
|
||||||
{
|
|
||||||
mv = 1;
|
mv = 1;
|
||||||
/* count++; if (count==COUNT) exit(0); */
|
/* count++; if (count==COUNT) exit(0); */
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* Draw characters that have changed, as well
|
/* Draw characters that have changed, as well
|
||||||
* as custom characters. We know not if a custom
|
* as custom characters. We know not if a custom
|
||||||
* character has changed.
|
* character has changed. */
|
||||||
*/
|
if (mv == 1) {
|
||||||
if (mv == 1)
|
|
||||||
{
|
|
||||||
Set_Insert(p->fd, i, j);
|
Set_Insert(p->fd, i, j);
|
||||||
mv = 0;
|
mv = 0;
|
||||||
}
|
}
|
||||||
@@ -1408,7 +1375,6 @@ void CwLnx_draw_frame(Driver *drvthis, char *dat)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
strncpy(p->backingstore, dat, p->width * p->height);
|
strncpy(p->backingstore, dat, p->width * p->height);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************
|
/*********************************************************
|
||||||
@@ -1481,7 +1447,7 @@ CwLnx_get_key(Driver * drvthis)
|
|||||||
return p->KeyMap[key-'A'];
|
return p->KeyMap[key-'A'];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
report( RPT_INFO, "CwLnx: Untreated key 0x%2x", key);
|
report(RPT_INFO, "%s: Untreated key 0x%02X", drvthis->name, key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
#define DEFAULT_CELLWIDTH 6
|
#define DEFAULT_CELLWIDTH 6
|
||||||
#define DEFAULT_CELLHEIGHT 8
|
#define DEFAULT_CELLHEIGHT 8
|
||||||
#define DEFAULT_DEVICE "/dev/lcd"
|
#define DEFAULT_DEVICE "/dev/lcd"
|
||||||
#define DEFAULT_SPEED B19200
|
#define DEFAULT_SPEED 19200
|
||||||
#define DEFAULT_SIZE "20x4"
|
#define DEFAULT_SIZE "20x4"
|
||||||
#define DEFAULT_BACKLIGHT 1
|
#define DEFAULT_BACKLIGHT 1
|
||||||
#define DEFAULT_BRIGHTNESS 200
|
#define DEFAULT_BRIGHTNESS 200
|
||||||
|
|||||||
Reference in New Issue
Block a user