harmonize coding style and messages; add more checks; silence warnings
This commit is contained in:
+57
-40
@@ -65,8 +65,8 @@ typedef enum {
|
|||||||
} custom_type;
|
} custom_type;
|
||||||
|
|
||||||
static int fd;
|
static int fd;
|
||||||
static char *framebuf = NULL;
|
static unsigned char *framebuf = NULL;
|
||||||
static char *old = NULL;
|
static unsigned char *old = NULL;
|
||||||
static int width = 0;
|
static int width = 0;
|
||||||
static int height = 0;
|
static int height = 0;
|
||||||
static int cellwidth = DEFAULT_CELL_WIDTH;
|
static int cellwidth = DEFAULT_CELL_WIDTH;
|
||||||
@@ -85,7 +85,7 @@ static void tyan_lcdm_switch_mode ();
|
|||||||
static void tyan_lcdm_hardware_clear (Driver * drvthis);
|
static void tyan_lcdm_hardware_clear (Driver * drvthis);
|
||||||
|
|
||||||
static void tyan_lcdm_set_rampos(unsigned char pos);
|
static void tyan_lcdm_set_rampos(unsigned char pos);
|
||||||
static void tyan_lcdm_write_str(char *str,unsigned char start_addr, int length);
|
static void tyan_lcdm_write_str(unsigned char *str, unsigned char start_addr, int length);
|
||||||
#if 0
|
#if 0
|
||||||
static void tyan_lcdm_set_cursor(unsigned char start_addr, int pos);
|
static void tyan_lcdm_set_cursor(unsigned char start_addr, int pos);
|
||||||
#endif
|
#endif
|
||||||
@@ -109,36 +109,39 @@ tyan_lcdm_init (Driver * drvthis, char *args)
|
|||||||
/* 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';
|
||||||
debug (RPT_INFO,"tyan_lcdm: Using device: %s", device);
|
debug(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, "tyan_lcdm_init: 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);
|
||||||
} else {
|
}
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
}
|
|
||||||
|
|
||||||
/* Which speed */
|
/* Which speed */
|
||||||
tmp = drvthis->config_get_int(drvthis->name , "Speed", 0, DEFAULT_SPEED);
|
tmp = drvthis->config_get_int(drvthis->name , "Speed", 0, DEFAULT_SPEED);
|
||||||
if (tmp == 4800) speed = B4800;
|
if (tmp == 4800) speed = B4800;
|
||||||
else if (tmp == 9600) speed = B9600;
|
else if (tmp == 9600) speed = B9600;
|
||||||
else { report (RPT_WARNING, "tyan_lcdm_init: Speed must be 4800 or 9600. Using default value.\n", speed);
|
else {
|
||||||
|
report(RPT_WARNING, "%s: Speed must be 4800 or 9600; using default %d",
|
||||||
|
drvthis->name, DEFAULT_SPEED);
|
||||||
|
speed = 9600;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set up io port correctly, and open it... */
|
/* Set up io port correctly, and open it... */
|
||||||
debug(RPT_DEBUG, "tyan_lcdm: Opening serial device: %s", device);
|
debug(RPT_DEBUG, "tyan_lcdm: Opening serial device: %s", 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, "tyan_lcdm_init: failed (%s)\n", strerror (errno));
|
report(RPT_ERR, "%s: open(%s) failed (%s)",
|
||||||
|
drvthis->name, device, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,14 +171,18 @@ tyan_lcdm_init (Driver * drvthis, char *args)
|
|||||||
|
|
||||||
/* Make sure the frame buffer is there... */
|
/* Make sure the frame buffer is there... */
|
||||||
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;
|
||||||
|
}
|
||||||
memset(framebuf, ' ', width * height);
|
memset(framebuf, ' ', width * height);
|
||||||
|
|
||||||
/* Set display-specific stuff.. */
|
/* Set display-specific stuff.. */
|
||||||
tyan_lcdm_switch_mode();
|
tyan_lcdm_switch_mode();
|
||||||
|
|
||||||
report (RPT_DEBUG, "tyan_lcdm_init: done\n");
|
report(RPT_DEBUG, "%s: init() done", drvthis->name);
|
||||||
|
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -186,10 +193,12 @@ tyan_lcdm_close (Driver * drvthis)
|
|||||||
{
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if(framebuf) free (framebuf);
|
if (framebuf)
|
||||||
|
free(framebuf);
|
||||||
framebuf = NULL;
|
framebuf = NULL;
|
||||||
|
|
||||||
if(old) free (old);
|
if (old)
|
||||||
|
free(old);
|
||||||
old = NULL;
|
old = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,7 +227,7 @@ MODULE_EXPORT void
|
|||||||
tyan_lcdm_flush (Driver * drvthis)
|
tyan_lcdm_flush (Driver * drvthis)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *xp, *xq;
|
unsigned char *xp, *xq;
|
||||||
/*
|
/*
|
||||||
* We don't use delta update yet.
|
* We don't use delta update yet.
|
||||||
* It is possible but not easy, we can only update a line, full or begining.
|
* It is possible but not easy, we can only update a line, full or begining.
|
||||||
@@ -252,7 +261,6 @@ for (i=0; i<width; i++) {
|
|||||||
}
|
}
|
||||||
xp++; xq++;
|
xp++; xq++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -261,11 +269,9 @@ for (i=0; i<width; i++) {
|
|||||||
MODULE_EXPORT const char *
|
MODULE_EXPORT const char *
|
||||||
tyan_lcdm_get_key (Driver *drvthis)
|
tyan_lcdm_get_key (Driver *drvthis)
|
||||||
{
|
{
|
||||||
unsigned char akey;
|
unsigned char key = tyan_lcdm_read_key();
|
||||||
|
|
||||||
akey = tyan_lcdm_read_key();
|
switch (key) {
|
||||||
|
|
||||||
switch(akey) {
|
|
||||||
case TYAN_LCDM_KEY_LEFT:
|
case TYAN_LCDM_KEY_LEFT:
|
||||||
return "Left";
|
return "Left";
|
||||||
break;
|
break;
|
||||||
@@ -285,7 +291,7 @@ tyan_lcdm_get_key (Driver *drvthis)
|
|||||||
return "Escape";
|
return "Escape";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
report( RPT_INFO, "tyan_lcdm: Untreated key 0x%2x", akey);
|
report(RPT_INFO, "%s: Untreated key 0x%02X", drvthis->name, key);
|
||||||
return NULL;
|
return NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -302,6 +308,7 @@ tyan_lcdm_chr (Driver * drvthis, int x, int y, char c)
|
|||||||
y--;
|
y--;
|
||||||
x--;
|
x--;
|
||||||
|
|
||||||
|
if ((x >= 0) && (y >= 0) && (x < width) && (y < height))
|
||||||
framebuf[(y * width) + x] = c;
|
framebuf[(y * width) + x] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,6 +329,7 @@ static void
|
|||||||
tyan_lcdm_switch_mode (Driver * drvthis)
|
tyan_lcdm_switch_mode (Driver * drvthis)
|
||||||
{
|
{
|
||||||
char lcdcmd[4];
|
char lcdcmd[4];
|
||||||
|
|
||||||
//set os selection
|
//set os selection
|
||||||
lcdcmd[0] = TYAN_LCDM_CMD_BEGIN;
|
lcdcmd[0] = TYAN_LCDM_CMD_BEGIN;
|
||||||
lcdcmd[1] = 0x73;
|
lcdcmd[1] = 0x73;
|
||||||
@@ -418,7 +426,6 @@ tyan_lcdm_init_vbar (Driver * drvthis)
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (custom != vbar) {
|
if (custom != vbar) {
|
||||||
// printf("+++ vbar +++\n");
|
|
||||||
tyan_lcdm_set_char(drvthis, 1, a);
|
tyan_lcdm_set_char(drvthis, 1, a);
|
||||||
tyan_lcdm_set_char(drvthis, 2, b);
|
tyan_lcdm_set_char(drvthis, 2, b);
|
||||||
tyan_lcdm_set_char(drvthis, 3, c);
|
tyan_lcdm_set_char(drvthis, 3, c);
|
||||||
@@ -557,6 +564,7 @@ tyan_lcdm_num (Driver * drvthis, int x, int num)
|
|||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
char out[5];
|
char out[5];
|
||||||
|
|
||||||
snprintf(out, sizeof(out), "%c%c%c", 28, x, num);
|
snprintf(out, sizeof(out), "%c%c%c", 28, x, num);
|
||||||
write(fd, out, 3);
|
write(fd, out, 3);
|
||||||
*/
|
*/
|
||||||
@@ -572,17 +580,17 @@ tyan_lcdm_num (Driver * drvthis, int x, int num)
|
|||||||
MODULE_EXPORT void
|
MODULE_EXPORT void
|
||||||
tyan_lcdm_set_char (Driver * drvthis, int n, char *dat)
|
tyan_lcdm_set_char (Driver * drvthis, int n, char *dat)
|
||||||
{
|
{
|
||||||
char out[8];
|
unsigned char out[8];
|
||||||
int row, col;
|
int row, col;
|
||||||
int letter;
|
|
||||||
|
|
||||||
if (n < 0 || n > 7)
|
if ((n < 0) || (n > 7))
|
||||||
return;
|
return;
|
||||||
if (!dat)
|
if (!dat)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (row = 0; row < cellheight; row++) {
|
for (row = 0; row < cellheight; row++) {
|
||||||
letter = 0;
|
int letter = 0;
|
||||||
|
|
||||||
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);
|
||||||
@@ -766,6 +774,7 @@ static void
|
|||||||
tyan_lcdm_hardware_clear (Driver * drvthis)
|
tyan_lcdm_hardware_clear (Driver * drvthis)
|
||||||
{
|
{
|
||||||
char lcdcmd[5];
|
char lcdcmd[5];
|
||||||
|
|
||||||
//set os selection
|
//set os selection
|
||||||
lcdcmd[0] = TYAN_LCDM_CMD_BEGIN;
|
lcdcmd[0] = TYAN_LCDM_CMD_BEGIN;
|
||||||
lcdcmd[1] = 0x70;
|
lcdcmd[1] = 0x70;
|
||||||
@@ -786,15 +795,16 @@ tyan_lcdm_string (Driver * drvthis, int x, int y, char string[])
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Convert 1-based coords to 0-based... */
|
/* Convert 1-based coords to 0-based... */
|
||||||
x -= 1;
|
x--;
|
||||||
y -= 1;
|
y--;
|
||||||
|
|
||||||
for (i = 0; string[i]; i++) {
|
if ((y < 0) || (y >= height))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (i = 0; (string[i] != '\0') && (x < width); i++, x++) {
|
||||||
/* Check for buffer overflows... */
|
/* Check for buffer overflows... */
|
||||||
if ((y * width) + x + i > (width * height))
|
if (x >= 0)
|
||||||
break;
|
framebuf[(y * width) + x] = string[i];
|
||||||
framebuf[(y * width) + x + i] = string[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -802,6 +812,7 @@ static
|
|||||||
void tyan_lcdm_set_rampos(unsigned char pos)
|
void tyan_lcdm_set_rampos(unsigned char pos)
|
||||||
{
|
{
|
||||||
char cmd_str[5];
|
char cmd_str[5];
|
||||||
|
|
||||||
cmd_str[0] = TYAN_LCDM_CMD_BEGIN;
|
cmd_str[0] = TYAN_LCDM_CMD_BEGIN;
|
||||||
cmd_str[1] = 0x70;
|
cmd_str[1] = 0x70;
|
||||||
cmd_str[2] = 0x00;
|
cmd_str[2] = 0x00;
|
||||||
@@ -811,13 +822,14 @@ void tyan_lcdm_set_rampos(unsigned char pos)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void tyan_lcdm_write_str(char *str,unsigned char start_addr, int length)
|
void tyan_lcdm_write_str(unsigned char *str,unsigned char start_addr, int length)
|
||||||
{
|
{
|
||||||
//CGRAM 0x40, 0x48,....
|
//CGRAM 0x40, 0x48,....
|
||||||
//if Line 1: start_addr = 0x80
|
//if Line 1: start_addr = 0x80
|
||||||
//if Line 2: start_addr = 0xc0
|
//if Line 2: start_addr = 0xc0
|
||||||
// 1<= length <=16
|
// 1<= length <=16
|
||||||
char cmd_str[20];
|
unsigned char cmd_str[20];
|
||||||
|
|
||||||
tyan_lcdm_set_rampos(start_addr);
|
tyan_lcdm_set_rampos(start_addr);
|
||||||
memset(cmd_str, ' ', 20);
|
memset(cmd_str, ' ', 20);
|
||||||
cmd_str[0] = TYAN_LCDM_CMD_BEGIN;
|
cmd_str[0] = TYAN_LCDM_CMD_BEGIN;
|
||||||
@@ -831,6 +843,7 @@ void tyan_lcdm_write_str(char *str,unsigned char start_addr, int length)
|
|||||||
static
|
static
|
||||||
void tyan_lcdm_set_cursor(unsigned char start_addr, int pos){
|
void tyan_lcdm_set_cursor(unsigned char start_addr, int pos){
|
||||||
char cmd_str[5];
|
char cmd_str[5];
|
||||||
|
|
||||||
tyan_lcdm_set_rampos(pos+start_addr);
|
tyan_lcdm_set_rampos(pos+start_addr);
|
||||||
cmd_str[0] = TYAN_LCDM_CMD_BEGIN;
|
cmd_str[0] = TYAN_LCDM_CMD_BEGIN;
|
||||||
cmd_str[1] = 0x70;
|
cmd_str[1] = 0x70;
|
||||||
@@ -843,13 +856,17 @@ void tyan_lcdm_set_cursor(unsigned char start_addr, int pos){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static
|
static
|
||||||
unsigned char tyan_lcdm_read_key(){
|
unsigned char tyan_lcdm_read_key()
|
||||||
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
char key_str[4];
|
char key_str[4];
|
||||||
|
|
||||||
memset(key_str, 0, 4);
|
memset(key_str, 0, 4);
|
||||||
count = read(fd, key_str, 4);
|
count = read(fd, key_str, 4);
|
||||||
if( key_str[0] == (char)TYAN_LCDM_CMD_BEGIN && key_str[1]==(char)0x72 && key_str[3]==(char)TYAN_LCDM_CMD_END){
|
if ((key_str[0] == (char) TYAN_LCDM_CMD_BEGIN)
|
||||||
|
&& (key_str[1] == (char) 0x72)
|
||||||
|
&& (key_str[3] == (char) TYAN_LCDM_CMD_END)) {
|
||||||
return key_str[2];
|
return key_str[2];
|
||||||
}
|
}
|
||||||
return 0xf4; //error
|
return 0xF4; //error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
#define DEFAULT_CELL_WIDTH 5
|
#define DEFAULT_CELL_WIDTH 5
|
||||||
#define DEFAULT_CELL_HEIGHT 8
|
#define DEFAULT_CELL_HEIGHT 8
|
||||||
#define DEFAULT_DEVICE "/dev/lcd"
|
#define DEFAULT_DEVICE "/dev/lcd"
|
||||||
#define DEFAULT_SPEED B9600
|
#define DEFAULT_SPEED 9600
|
||||||
#define DEFAULT_SIZE "16x2"
|
#define DEFAULT_SIZE "16x2"
|
||||||
|
|
||||||
MODULE_EXPORT int tyan_lcdm_init (Driver * drvthis, char *device);
|
MODULE_EXPORT int tyan_lcdm_init (Driver * drvthis, char *device);
|
||||||
|
|||||||
Reference in New Issue
Block a user