harmonize coding style and messages; add a few checks

This commit is contained in:
marschap
2006-04-08 21:19:14 +00:00
parent 3c52181126
commit 2dcde3e4f2
2 changed files with 248 additions and 264 deletions
+135 -145
View File
@@ -50,7 +50,7 @@ typedef enum {
beat = 8 } custom_type; beat = 8 } custom_type;
static int fd; static int fd = -1;
static char *framebuf = NULL; static char *framebuf = NULL;
static int width = LCD_DEFAULT_WIDTH; static int width = LCD_DEFAULT_WIDTH;
static int height = LCD_DEFAULT_HEIGHT; static int height = LCD_DEFAULT_HEIGHT;
@@ -76,7 +76,7 @@ MODULE_EXPORT int
LB216_init(Driver * drvthis) LB216_init(Driver * drvthis)
{ {
struct termios portset; struct termios portset;
int reboot=0; int reboot = 0;
char device[256] = LB216_DEFAULT_DEVICE; char device[256] = LB216_DEFAULT_DEVICE;
int speed = LB216_DEFAULT_SPEED; int speed = LB216_DEFAULT_SPEED;
int backlight_brightness = LB216_DEFAULT_BRIGHTNESS; int backlight_brightness = LB216_DEFAULT_BRIGHTNESS;
@@ -88,6 +88,7 @@ LB216_init(Driver * drvthis)
strncpy(device, drvthis->config_get_string(drvthis->name, "Device", 0, strncpy(device, drvthis->config_get_string(drvthis->name, "Device", 0,
LB216_DEFAULT_DEVICE), sizeof(device)); LB216_DEFAULT_DEVICE), sizeof(device));
device[sizeof(device)-1] = '\0'; device[sizeof(device)-1] = '\0';
report(RPT_INFO, "%s: using Device %s", drvthis->name, device);
/* What speed to use */ /* What speed to use */
speed = drvthis->config_get_int(drvthis->name, "Speed", 0, LB216_DEFAULT_SPEED); speed = drvthis->config_get_int(drvthis->name, "Speed", 0, LB216_DEFAULT_SPEED);
@@ -95,76 +96,77 @@ LB216_init(Driver * drvthis)
if (speed == 2400) speed = B2400; if (speed == 2400) speed = B2400;
else if (speed == 9600) speed = B9600; else if (speed == 9600) speed = B9600;
else { else {
report(RPT_WARNING, "lb216_init: Illegal speed: %d. Must be 2400 or 9600. Using default.\n", speed); report(RPT_WARNING, "%s: illegal Speed: %d; must be 2400 or 9600; using default %d",
drvthis->name, speed, LB216_DEFAULT_SPEED);
speed = B9600; speed = B9600;
} }
/* Which backlight brightness */ /* Which backlight brightness */
backlight_brightness = drvthis->config_get_int ( drvthis->name , "Brightness" , 0 , LB216_DEFAULT_BRIGHTNESS); backlight_brightness = drvthis->config_get_int(drvthis->name, "Brightness", 0, LB216_DEFAULT_BRIGHTNESS);
if ((backlight_brightness < 0) || (backlight_brightness > 255)) { if ((backlight_brightness < 0) || (backlight_brightness > 255)) {
report (RPT_WARNING, "lb216_init: Brightness must be between 0 and 255. Using default value.\n"); report(RPT_WARNING, "%s: Brightness must be between 0 and 255; using default %d",
drvthis->name, backlight_brightness);
backlight_brightness = LB216_DEFAULT_BRIGHTNESS; backlight_brightness = LB216_DEFAULT_BRIGHTNESS;
} }
/* Reboot display? */ /* Reboot display? */
reboot = drvthis->config_get_bool( drvthis->name , "Reboot", 0, 0); reboot = drvthis->config_get_bool(drvthis->name , "Reboot", 0, 0);
if (reboot)
report (RPT_INFO, "LCDd: rebooting LB216 LCD...\n");
/* End of config file parsing */ /* End of config file parsing */
// Set up io port correctly, and open it... // Set up io port correctly, and open it...
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, "%s: open(%s) failed (%s)", drvthis->name, device, strerror(errno));
report(RPT_ERR, "lb216_init: open(%s) failed (%s)\n", device, strerror(errno)); return -1;
return -1; }
} report(RPT_DEBUG, "%s: opened device %s", drvthis->name, device);
report(RPT_DEBUG, "lb216_init: opened device %s\n", device);
tcgetattr(fd, &portset); tcgetattr(fd, &portset);
// We use RAW mode // We use RAW mode
#ifdef HAVE_CFMAKERAW #ifdef HAVE_CFMAKERAW
// The easy way // The easy way
cfmakeraw( &portset ); cfmakeraw(&portset);
#else #else
// The hard way // The hard way
portset.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP portset.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP
| INLCR | IGNCR | ICRNL | IXON ); | INLCR | IGNCR | ICRNL | IXON );
portset.c_oflag &= ~OPOST; portset.c_oflag &= ~OPOST;
portset.c_lflag &= ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN ); portset.c_lflag &= ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN );
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
// Set port speed // Set port speed
cfsetospeed (&portset, speed); cfsetospeed(&portset, speed);
cfsetispeed (&portset, B0); cfsetispeed(&portset, B0);
// Do it... // Do it...
tcsetattr(fd, TCSANOW, &portset); tcsetattr(fd, TCSANOW, &portset);
// Make sure the frame buffer is there... // Make sure the frame buffer is there...
framebuf = malloc (width * height); framebuf = malloc(width * height);
if (framebuf == NULL) { if (framebuf == NULL) {
report(RPT_ERR, "lb216_init: unable to create framebuffer.\n"); report(RPT_ERR, "%s: unable to create framebuffer", drvthis->name);
return -1; return -1;
} }
memset (framebuf, ' ', width * height); memset (framebuf, ' ', width * height);
// Set display-specific stuff.. // Set display-specific stuff..
if (reboot) if (reboot) {
{ report(RPT_INFO, "%s: rebooting LCD...", drvthis->name);
LB216_reboot(); LB216_reboot();
sleep(4); sleep(4);
reboot=0; reboot = 0;
} }
sleep(1); sleep(1);
LB216_hidecursor(); LB216_hidecursor();
LB216_backlight(drvthis, backlight_brightness); LB216_backlight(drvthis, backlight_brightness);
return 0; report(RPT_DEBUG, "%s: init() done", drvthis->name);
return 1;
} }
@@ -175,7 +177,8 @@ LB216_init(Driver * drvthis)
MODULE_EXPORT void MODULE_EXPORT void
LB216_close(Driver * drvthis) LB216_close(Driver * drvthis)
{ {
close (fd); if (fd >= 0)
close(fd);
if (framebuf) if (framebuf)
free(framebuf); free(framebuf);
@@ -188,7 +191,7 @@ LB216_close(Driver * drvthis)
MODULE_EXPORT int MODULE_EXPORT int
LB216_width (Driver *drvthis) LB216_width (Driver *drvthis)
{ {
return width; return width;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -197,7 +200,7 @@ LB216_width (Driver *drvthis)
MODULE_EXPORT int MODULE_EXPORT int
LB216_height (Driver *drvthis) LB216_height (Driver *drvthis)
{ {
return height; return height;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -206,7 +209,7 @@ LB216_height (Driver *drvthis)
MODULE_EXPORT void MODULE_EXPORT void
LB216_clear (Driver * drvthis) LB216_clear (Driver * drvthis)
{ {
memset (framebuf, ' ', width * height); memset(framebuf, ' ', width * height);
} }
@@ -217,21 +220,20 @@ MODULE_EXPORT void
LB216_flush(Driver * drvthis) LB216_flush(Driver * drvthis)
{ {
char out[LCD_MAX_WIDTH * LCD_MAX_HEIGHT]; char out[LCD_MAX_WIDTH * LCD_MAX_HEIGHT];
int i,j; int i, j;
snprintf (out, sizeof(out), "%c%c", 254,80); snprintf(out, sizeof(out), "%c%c", 254, 80);
write(fd, out, 2); write(fd, out, 2);
for(j=0; j<height; j++) { for (j = 0; j < height; j++) {
if (j>=2) { if (j >= 2)
snprintf (out, sizeof(out),"%c%c",254,148+(64*(j-2))); snprintf(out, sizeof(out), "%c%c", 254, 148 + (64 * (j - 2)));
} else { else
snprintf (out, sizeof(out),"%c%c",254,128+(64*(j))); snprintf(out, sizeof(out), "%c%c", 254, 128 + (64 * j));
}
write(fd, out, 2); write(fd, out, 2);
for(i=0; i<width; i++) {
write(fd, framebuf + i+(j*width), 1); for (i = 0; i < width; i++)
} write(fd, &framebuf[i + (j * width)], 1);
} }
} }
@@ -247,17 +249,17 @@ LB216_chr(Driver * drvthis, int x, int y, char c)
//y--; //y--;
// x--; // x--;
//if(c < 32 && c >= 0) c += 128; //if (c < 32 && c >= 0) c += 128;
// framebuf[(y*width) + x] = c; // framebuf[(y*width) + x] = c;
// char chr[1]; // char chr[1];
// snprintf (chr, sizeof(chr), "%c", c); // snprintf(chr, sizeof(chr), "%c", c);
// Above two lines are incorrect (Joris) // Above two lines are incorrect (Joris)
char chr[2]; char chr[2];
chr[0] = c; chr[0] = c;
chr[1] = 0; chr[1] = 0;
LB216_string (drvthis, x, y, chr); LB216_string(drvthis, x, y, chr);
} }
@@ -269,15 +271,9 @@ MODULE_EXPORT void
LB216_backlight(Driver * drvthis, int on) LB216_backlight(Driver * drvthis, int on)
{ {
char out[4]; char out[4];
if(on)
{ snprintf(out, sizeof(out), "%c%c", 254, (on) ? 253 : 252);
snprintf (out, sizeof(out), "%c%c", 254, 253); write(fd, out, 2);
}
else
{
snprintf (out, sizeof(out), "%c%c", 254, 252);
}
write(fd, out, 2);
} }
@@ -287,7 +283,8 @@ LB216_backlight(Driver * drvthis, int on)
static void LB216_hidecursor() static void LB216_hidecursor()
{ {
char out[4]; char out[4];
snprintf (out, sizeof(out), "%c%c", 254,12);
snprintf(out, sizeof(out), "%c%c", 254, 12);
write(fd, out, 2); write(fd, out, 2);
} }
@@ -297,7 +294,8 @@ static void LB216_hidecursor()
static void LB216_reboot() static void LB216_reboot()
{ {
char out[4]; char out[4];
snprintf (out, sizeof(out), "%c%c", 254,1);
snprintf(out, sizeof(out), "%c%c", 254, 1);
write(fd, out, 2); write(fd, out, 2);
} }
@@ -305,21 +303,17 @@ static void LB216_reboot()
MODULE_EXPORT void MODULE_EXPORT void
LB216_string (Driver * drvthis, int x, int y, char string[]) LB216_string (Driver * drvthis, int x, int y, char string[])
{ {
int i; int i;
char c;
//printf("%d,%d:%s\n",x,y,string); //printf("%d,%d:%s\n",x,y,string);
y--;x--; y--;x--;
for(i=0; string[i]; i++) for (i = 0; string[i] != '\0'; i++) {
{ char c = string[i];
c = string[i];
switch(c)
{
case '\254': c = '#'; break;
}
framebuf[(y*width) + x+i] = c;
}
if (c == '\254') /* is this correct ? */
c= '#';
framebuf[(y * width) + x + i] = c;
}
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -399,15 +393,15 @@ LB216_init_vbar(Driver * drvthis)
1,1,1,1,1, 1,1,1,1,1,
}; };
if(custom!=vbar) { if (custom != vbar) {
LB216_set_char(drvthis, 1,a); LB216_set_char(drvthis, 1, a);
LB216_set_char(drvthis, 2,b); LB216_set_char(drvthis, 2, b);
LB216_set_char(drvthis, 3,c); LB216_set_char(drvthis, 3, c);
LB216_set_char(drvthis, 4,d); LB216_set_char(drvthis, 4, d);
LB216_set_char(drvthis, 5,e); LB216_set_char(drvthis, 5, e);
LB216_set_char(drvthis, 6,f); LB216_set_char(drvthis, 6, f);
LB216_set_char(drvthis, 7,g); LB216_set_char(drvthis, 7, g);
custom=vbar; custom = vbar;
} }
} }
@@ -469,13 +463,13 @@ LB216_init_hbar(Driver * drvthis)
1,1,1,1,1, 1,1,1,1,1,
}; };
if(custom!=hbar) { if (custom != hbar) {
LB216_set_char(drvthis, 1,a); LB216_set_char(drvthis, 1, a);
LB216_set_char(drvthis, 2,b); LB216_set_char(drvthis, 2, b);
LB216_set_char(drvthis, 3,c); LB216_set_char(drvthis, 3, c);
LB216_set_char(drvthis, 4,d); LB216_set_char(drvthis, 4, d);
LB216_set_char(drvthis, 5,e); LB216_set_char(drvthis, 5, e);
custom=hbar; custom = hbar;
} }
} }
@@ -485,18 +479,17 @@ LB216_init_hbar(Driver * drvthis)
MODULE_EXPORT void MODULE_EXPORT void
LB216_vbar(Driver * drvthis, int x, int len) LB216_vbar(Driver * drvthis, int x, int len)
{ {
char map[9] = {32, 1, 2, 3, 4, 5, 6, 7, 255 }; char map[9] = { 32, 1, 2, 3, 4, 5, 6, 7, 255 };
int y; int y;
for(y=height; y > 0 && len>0; y--)
{
if(len >= cellheight) LB216_chr(drvthis, x, y, 255);
else LB216_chr(drvthis, x, y, map[len]);
len -= cellheight; for (y = height; y > 0 && len > 0; y--) {
} if (len >= cellheight)
LB216_chr(drvthis, x, y, map[8]);
else
LB216_chr(drvthis, x, y, map[len]);
len -= cellheight;
}
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -507,17 +500,14 @@ LB216_hbar(Driver * drvthis, int x, int y, int len)
{ {
char map[7] = { 32, 1, 2, 3, 4, 5 }; char map[7] = { 32, 1, 2, 3, 4, 5 };
for(; x<=width && len>0; x++) for ( ; x <= width && len > 0; x++) {
{ if (len >= cellwidth)
if(len >= cellwidth) LB216_chr(drvthis, x,y,map[5]); LB216_chr(drvthis, x, y, map[5]);
else LB216_chr(drvthis, x, y, map[len]); else
LB216_chr(drvthis, x, y, map[len]);
//printf ("%d,",len);
len -= cellwidth;
}
// printf ("\n");
len -= cellwidth;
}
} }
@@ -533,28 +523,28 @@ LB216_set_char(Driver * drvthis, int n, char *dat)
{ {
char out[4]; char out[4];
int row, col; int row, col;
int letter;
if(n < 0 || n > 7) return; if ((n < 0) || (n > 7))
n=64+(8*n); return;
if(!dat) return; if (!dat)
return;
snprintf (out, sizeof(out), "%c%c", 254, n); snprintf(out, sizeof(out), "%c%c", 254, 64 + (8 * n));
write(fd, out, 2); write(fd, out, 2);
for(row=0; row<cellheight; row++) for (row = 0; row < cellheight; row++) {
{ int letter = 1;
letter = 1;
for(col=0; col<cellwidth; col++) for (col = 0; col < cellwidth; col++) {
{
letter <<= 1; letter <<= 1;
letter |= (dat[(row*cellwidth) + col] > 0); letter |= (dat[(row * cellwidth) + col] > 0);
} }
snprintf (out, sizeof(out),"%c",letter); snprintf(out, sizeof(out), "%c", letter);
write(fd, out, 1); write(fd, out, 1);
} }
} }
MODULE_EXPORT int MODULE_EXPORT int
LB216_icon(Driver * drvthis, int x, int y, int icon) LB216_icon(Driver * drvthis, int x, int y, int icon)
{ {
@@ -578,21 +568,21 @@ LB216_icon(Driver * drvthis, int x, int y, int icon)
1, 1, 0, 1, 1, 1, 1, 0, 1, 1,
1, 1, 1, 1, 1 }; 1, 1, 1, 1, 1 };
switch( icon ) switch (icon) {
{
case ICON_BLOCK_FILLED: case ICON_BLOCK_FILLED:
LB216_chr( drvthis, x, y, 255 ); LB216_chr(drvthis, x, y, 255);
break; break;
case ICON_HEART_FILLED: case ICON_HEART_FILLED:
LB216_set_char( drvthis, 0, heart_filled ); LB216_set_char(drvthis, 0, heart_filled);
LB216_chr( drvthis, x, y, 0 ); LB216_chr(drvthis, x, y, 0);
break; break;
case ICON_HEART_OPEN: case ICON_HEART_OPEN:
LB216_set_char( drvthis, 0, heart_open ); LB216_set_char(drvthis, 0, heart_open);
LB216_chr( drvthis, x, y, 0 ); LB216_chr(drvthis, x, y, 0);
break; break;
default: default:
return -1; return -1;
} }
return 0; return 0;
} }
+112 -118
View File
@@ -64,7 +64,7 @@
//#include "configfile.h" //#include "configfile.h"
int fd; int fd = -1;
static int clear = 1; static int clear = 1;
static char icon_char = '@'; static char icon_char = '@';
static char pause_key = DOWN_KEY, back_key = LEFT_KEY, forward_key = RIGHT_KEY, main_menu_key = UP_KEY; static char pause_key = DOWN_KEY, back_key = LEFT_KEY, forward_key = RIGHT_KEY, main_menu_key = UP_KEY;
@@ -78,35 +78,36 @@ MODULE_EXPORT int stay_in_foreground = 0;
MODULE_EXPORT int supports_multiple = 0; MODULE_EXPORT int supports_multiple = 0;
MODULE_EXPORT char *symbol_prefix = "lcdm001_"; MODULE_EXPORT char *symbol_prefix = "lcdm001_";
static void lcdm001_cursorblink (Driver *drvthis, int on); static void lcdm001_cursorblink(Driver *drvthis, int on);
static char lcdm001_parse_keypad_setting ( Driver *drvthis, char * keyname, char * default_value ); static char lcdm001_parse_keypad_setting(Driver *drvthis, char * keyname, char * default_value);
#define ValidX(x) if ((x) > width) { (x) = width; } else (x) = (x) < 1 ? 1 : (x); #define ValidX(x) if ((x) > width) { (x) = width; } else (x) = (x) < 1 ? 1 : (x);
#define ValidY(y) if ((y) > height) { (y) = height; } else (y) = (y) < 1 ? 1 : (y); #define ValidY(y) if ((y) > height) { (y) = height; } else (y) = (y) < 1 ? 1 : (y);
// Parse one key from the configfile // Parse one key from the configfile
static char lcdm001_parse_keypad_setting (Driver *drvthis, char * keyname, char * default_value) static char lcdm001_parse_keypad_setting(Driver *drvthis, char * keyname, char * default_value)
{ {
char return_val = 0; char return_val = 0;
if (strcmp( drvthis->config_get_string ( drvthis->name, keyname, 0, default_value), "LeftKey")==0) { if (strcmp(drvthis->config_get_string(drvthis->name, keyname, 0, default_value), "LeftKey") == 0) {
return_val=LEFT_KEY; return_val = LEFT_KEY;
} else if (strcmp( drvthis->config_get_string ( drvthis->name, keyname, 0, default_value), "RightKey")==0) { } else if (strcmp(drvthis->config_get_string(drvthis->name, keyname, 0, default_value), "RightKey") == 0) {
return_val=RIGHT_KEY; return_val = RIGHT_KEY;
} else if (strcmp( drvthis->config_get_string ( drvthis->name, keyname, 0, default_value), "UpKey")==0) { } else if (strcmp(drvthis->config_get_string(drvthis->name, keyname, 0, default_value), "UpKey") == 0) {
return_val=UP_KEY; return_val = UP_KEY;
} else if (strcmp( drvthis->config_get_string ( drvthis->name, keyname, 0, default_value), "DownKey")==0) { } else if (strcmp(drvthis->config_get_string(drvthis->name, keyname, 0, default_value), "DownKey") == 0) {
return_val=DOWN_KEY; return_val = DOWN_KEY;
} else { } else {
report (RPT_WARNING, "LCDM001: Invalid config file setting for %s. Using default value %s.\n", keyname, default_value); report(RPT_WARNING, "%s: invalid config setting for %s; using default %s",
if (strcmp (default_value, "LeftKey")==0) { drvthis->name, keyname, default_value);
return_val=LEFT_KEY; if (strcmp(default_value, "LeftKey") == 0) {
} else if (strcmp (default_value, "RightKey")==0) { return_val = LEFT_KEY;
return_val=RIGHT_KEY; } else if (strcmp(default_value, "RightKey") == 0) {
} else if (strcmp (default_value, "UpKey")==0) { return_val = RIGHT_KEY;
return_val=UP_KEY; } else if (strcmp(default_value, "UpKey") == 0) {
} else if (strcmp (default_value, "DownKey")==0) { return_val = UP_KEY;
return_val=DOWN_KEY; } else if (strcmp(default_value, "DownKey") == 0) {
return_val = DOWN_KEY;
} }
} }
return return_val; return return_val;
@@ -114,14 +115,14 @@ static char lcdm001_parse_keypad_setting (Driver *drvthis, char * keyname, char
/* Set cursorblink on/off */ /* Set cursorblink on/off */
static void static void
lcdm001_cursorblink (Driver *drvthis, int on) lcdm001_cursorblink(Driver *drvthis, int on)
{ {
if (on) { if (on) {
write (fd, "~K1", 3); write(fd, "~K1", 3);
debug(RPT_INFO, "LCDM001: cursorblink turned on"); debug(RPT_INFO, "%s: cursorblink turned on", drvthis->name);
} else { } else {
write (fd, "~K0", 3); write(fd, "~K0", 3);
debug(RPT_INFO, "LCDM001: cursorblink turned off"); debug(RPT_INFO, "%s: cursorblink turned off", drvthis->name);
} }
} }
@@ -136,56 +137,50 @@ MODULE_EXPORT int
lcdm001_init (Driver *drvthis) lcdm001_init (Driver *drvthis)
{ {
char device[200]; char device[200];
int speed=B38400; int speed = B38400;
struct termios portset; struct termios portset;
char out[5]=""; char out[5] = "";
debug( RPT_INFO, "LCDM001: init(%p)", drvthis ); debug(RPT_INFO, "LCDM001: init(%p)", drvthis);
framebuf = malloc (width * height); framebuf = malloc(width * height);
if (framebuf == NULL) {
if (!framebuf) { report(RPT_ERR, "%s: unable to create framebuffer", drvthis->name);
report(RPT_ERR, "\nError: unable to create LCDM001 framebuffer.\n");
return -1; return -1;
} }
memset (framebuf, ' ', width * height); memset(framebuf, ' ', width * height);
// 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 , "/dev/lcd"),sizeof(device)); strncpy(device, drvthis->config_get_string(drvthis->name, "Device", 0, "/dev/lcd"), sizeof(device));
device[sizeof(device)-1]=0; device[sizeof(device)-1] = '\0';
report (RPT_INFO,"LCDM001: Using device: %s", device); report(RPT_INFO, "%s: using Device %s", drvthis->name, device);
// keypad settings // keypad settings
pause_key = lcdm001_parse_keypad_setting (drvthis, "PauseKey", "DownKey"); pause_key = lcdm001_parse_keypad_setting(drvthis, "PauseKey", "DownKey");
back_key = lcdm001_parse_keypad_setting (drvthis, "BackKey", "LeftKey"); back_key = lcdm001_parse_keypad_setting(drvthis, "BackKey", "LeftKey");
forward_key = lcdm001_parse_keypad_setting (drvthis, "ForwardKey", "RightKey"); forward_key = lcdm001_parse_keypad_setting(drvthis, "ForwardKey", "RightKey");
main_menu_key = lcdm001_parse_keypad_setting (drvthis, "MainMenuKey", "UpKey"); main_menu_key = lcdm001_parse_keypad_setting(drvthis, "MainMenuKey", "UpKey");
// Set up io port correctly, and open it... // Set up io port correctly, and open it...
debug( RPT_DEBUG, "LCDM001: Opening serial device: %s", device); debug(RPT_DEBUG, "%s: Opening serial device: %s", __FUNCTION__, 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, "%s: open(%d) failed (%s)",
switch (errno) { drvthis->name, device, strerror(errno));
case ENOENT: report( RPT_ERR, "LCDM001: lcdm001_init() failed: Device file missing: %s\n", device); if (errno == EACCES)
break; report(RPT_ERR, "%s: make sure you have rw access to %s!",
case EACCES: report( RPT_ERR, "LCDM001: lcdm001_init() failed: Could not open device: %s\n", device); drvthis->name, device);
report( RPT_ERR, "LCDM001: lcdm001_init() failed: Make sure you have rw access to %s!\n", device);
break;
default: report( RPT_ERR, "LCDM001: lcdm001_init() failed (%s)\n", strerror (errno));
break;
}
return -1; return -1;
} else {
report (RPT_INFO, "opened LCDM001 display on %s", device);
} }
report(RPT_INFO, "%s: opened display on %s", drvthis->name, device);
tcgetattr(fd, &portset); tcgetattr(fd, &portset);
#ifdef HAVE_CFMAKERAW #ifdef HAVE_CFMAKERAW
/* The easy way: */ /* The easy way: */
cfmakeraw( &portset ); cfmakeraw(&portset);
#else #else
/* The hard way: */ /* The hard way: */
portset.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP portset.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP
@@ -193,7 +188,7 @@ lcdm001_init (Driver *drvthis)
portset.c_oflag &= ~OPOST; portset.c_oflag &= ~OPOST;
portset.c_lflag &= ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN ); portset.c_lflag &= ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN );
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, speed); cfsetospeed(&portset, speed);
cfsetispeed(&portset, speed); cfsetispeed(&portset, speed);
@@ -201,14 +196,16 @@ lcdm001_init (Driver *drvthis)
tcflush(fd, TCIOFLUSH); tcflush(fd, TCIOFLUSH);
// Reset and clear the LCDM001 // Reset and clear the LCDM001
write (fd, "~C", 2); write(fd, "~C", 2);
//Set cursorblink default //Set cursorblink default
lcdm001_cursorblink (drvthis, DEFAULT_CURSORBLINK); lcdm001_cursorblink(drvthis, DEFAULT_CURSORBLINK);
// Turn all LEDs off // Turn all LEDs off
snprintf (out, sizeof(out), "\%cL%c%c", 126, 0, 0); snprintf(out, sizeof(out), "\%cL%c%c", 126, 0, 0);
write (fd, out, 4); write(fd, out, 4);
return 0; report(RPT_DEBUG, "%s: init() done", drvthis->name);
return 1;
} }
/* Below here, you may use either lcd.framebuf or driver->framebuf.. /* Below here, you may use either lcd.framebuf or driver->framebuf..
@@ -219,16 +216,21 @@ lcdm001_init (Driver *drvthis)
MODULE_EXPORT void MODULE_EXPORT void
lcdm001_close (Driver *drvthis) lcdm001_close (Driver *drvthis)
{ {
char out[5]; if (framebuf != NULL)
if(framebuf) free (framebuf); free(framebuf);
framebuf = NULL; framebuf = NULL;
//switch off all LEDs if (fd >= 0) {
snprintf (out, sizeof(out), "\%cL%c%c", 126, 0, 0); char out[5];
write (fd, out, 4);
close (fd);
report (RPT_INFO, "LCDM001: closed"); //switch off all LEDs
snprintf(out, sizeof(out), "\%cL%c%c", 126, 0, 0);
write(fd, out, 4);
close(fd);
}
fd = -1;
report(RPT_INFO, "%s: closed", drvthis->name);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -256,14 +258,14 @@ MODULE_EXPORT void
lcdm001_clear (Driver *drvthis) lcdm001_clear (Driver *drvthis)
{ {
if (framebuf != NULL) if (framebuf != NULL)
memset (framebuf, ' ', (width * height)); memset(framebuf, ' ', (width * height));
/* An instant clear is NOT neccessary, it only makes the display /* An instant clear is NOT neccessary, it only makes the display
* flicker * flicker
*/ */
/*write (fd, "~C", 2);*/ /* instant clear...*/ /*write(fd, "~C", 2);*/ /* instant clear...*/
clear = 1; clear = 1;
debug (RPT_DEBUG, "LCDM001: cleared screen"); debug(RPT_DEBUG, "LCDM001: cleared screen");
} }
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@@ -276,9 +278,9 @@ lcdm001_flush (Driver *drvthis)
//TODO: Check whether this is still correct //TODO: Check whether this is still correct
write(fd,framebuf,80); write(fd, framebuf, 80);
debug (RPT_DEBUG, "LCDM001: frame buffer flushed"); debug(RPT_DEBUG, "LCDM001: frame buffer flushed");
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -293,9 +295,8 @@ lcdm001_chr (Driver *drvthis, int x, int y, char c)
ValidX(x); ValidX(x);
ValidY(y); ValidY(y);
if (c==0) { if (c == '\0')
c = icon_char; //heartbeat workaround c = icon_char; //heartbeat workaround
}
// write to frame buffer // write to frame buffer
y--; x--; // translate to 0-coords y--; x--; // translate to 0-coords
@@ -303,7 +304,7 @@ lcdm001_chr (Driver *drvthis, int x, int y, char c)
offset = (y * width) + x; offset = (y * width) + x;
framebuf[offset] = c; framebuf[offset] = c;
debug (RPT_DEBUG, "LCDM001: writing character %02X to position (%d,%d)", c, x, y); debug(RPT_DEBUG, "LCDM001: writing character %02X to position (%d,%d)", c, x, y);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -321,11 +322,11 @@ lcdm001_string (Driver *drvthis, int x, int y, char *string)
x--; y--; // Convert 1-based coords to 0-based... x--; y--; // Convert 1-based coords to 0-based...
offset = (y * width) + x; offset = (y * width) + x;
siz = (width * height) - offset - 1; siz = (width * height) - offset - 1;
siz = siz > strlen(string) ? strlen(string) : siz; siz = (siz > strlen(string)) ? strlen(string) : siz;
memcpy(framebuf + offset, string, siz); memcpy(framebuf + offset, string, siz);
debug (RPT_DEBUG, "LCDM001: printed string at (%d,%d)", x, y); debug(RPT_DEBUG, "LCDM001: printed string at (%d,%d)", x, y);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -336,20 +337,18 @@ lcdm001_output (Driver *drvthis, int state)
char out[5]; char out[5];
int one = 0, two = 0; int one = 0, two = 0;
if (state<=255) if (state <= 255) {
{ one = state;
one=state; two = 0;
two=0;
} }
else else {
{
one = state & 0xff; one = state & 0xff;
two = (state >> 8) & 0xff; two = (state >> 8) & 0xff;
} }
snprintf (out, sizeof(out), "~L%c%c",one,two); snprintf(out, sizeof(out), "~L%c%c", one, two);
write(fd,out,4); write(fd, out, 4);
debug (RPT_DEBUG, "LCDM001: current LED state: %d", state); debug(RPT_DEBUG, "LCDM001: current LED state %d", state);
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -358,22 +357,20 @@ lcdm001_output (Driver *drvthis, int state)
MODULE_EXPORT void MODULE_EXPORT void
lcdm001_old_vbar(Driver *drvthis, int x, int len) lcdm001_old_vbar(Driver *drvthis, int x, int len)
{ {
int y = 4; int y = 4;
debug (RPT_DEBUG , "LCDM001: vertical bar at %d set to %d", x, len); debug(RPT_DEBUG , "LCDM001: vertical bar at %d set to %d", x, len);
while (len >= LCD_DEFAULT_CELLHEIGHT) while (len >= LCD_DEFAULT_CELLHEIGHT) {
{ lcdm001_chr(drvthis, x, y, 0xFF);
lcdm001_chr(drvthis, x, y, 0xFF); len -= LCD_DEFAULT_CELLHEIGHT;
len -= LCD_DEFAULT_CELLHEIGHT; y--;
y--; }
}
if(!len) if (!len)
return; return;
//TODO: Distinguish between len>=4 and len<4
//TODO: Distinguish between len>=4 and len<4
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -382,28 +379,25 @@ lcdm001_old_vbar(Driver *drvthis, int x, int len)
MODULE_EXPORT void MODULE_EXPORT void
lcdm001_old_hbar(Driver *drvthis, int x, int y, int len) lcdm001_old_hbar(Driver *drvthis, int x, int y, int len)
{ {
ValidX(x);
ValidY(y);
ValidX(x); debug(RPT_DEBUG, "LCDM001: horizontal bar at %d set to %d", x, len);
ValidY(y);
debug (RPT_DEBUG, "LCDM001: horizontal bar at %d set to %d", x, len); //TODO: Improve this function
//TODO: Improve this function while ((x <= width) && (len > 0)) {
if (len < LCD_DEFAULT_CELLWIDTH) {
//lcdm001_chr(x, y, 0x98 + len);
break;
}
while((x <= width) && (len > 0)) lcdm001_chr(drvthis, x, y, 0xFF);
{ len -= LCD_DEFAULT_CELLWIDTH;
if(len < LCD_DEFAULT_CELLWIDTH) x++;
{ }
//lcdm001_chr(x, y, 0x98 + len);
break;
}
lcdm001_chr(drvthis, x, y, 0xFF); return;
len -= LCD_DEFAULT_CELLWIDTH;
x++;
}
return;
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
@@ -444,7 +438,7 @@ lcdm001_get_key (Driver *drvthis)
char in = '\0'; char in = '\0';
const char *key = NULL; const char *key = NULL;
read (fd, &in, 1); read(fd, &in, 1);
if (in == pause_key) { if (in == pause_key) {
key = "Enter"; key = "Enter";
} else if (in == back_key) { } else if (in == back_key) {