harmonize coding style and messages; add more checks; silence warnings
This commit is contained in:
+169
-152
@@ -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
|
||||||
@@ -104,52 +104,55 @@ tyan_lcdm_init (Driver * drvthis, char *args)
|
|||||||
int speed = DEFAULT_SPEED;
|
int speed = DEFAULT_SPEED;
|
||||||
char size[200] = DEFAULT_SIZE;
|
char size[200] = DEFAULT_SIZE;
|
||||||
|
|
||||||
debug(RPT_INFO, "tyan_lcdm: init(%p,%s)", drvthis, args );
|
debug(RPT_INFO, "tyan_lcdm: init(%p,%s)", drvthis, 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",
|
||||||
sscanf( DEFAULT_SIZE , "%dx%d", &w, &h );
|
drvthis->name, size, DEFAULT_SIZE);
|
||||||
} else {
|
sscanf(DEFAULT_SIZE , "%dx%d", &w, &h);
|
||||||
width = w;
|
|
||||||
height = h;
|
|
||||||
}
|
}
|
||||||
|
width = w;
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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_cflag = CS8 | CREAD | CLOCAL;
|
portset.c_cflag = CS8 | CREAD | CLOCAL;
|
||||||
portset.c_iflag = IXON | IXOFF | IGNBRK | IGNCR;
|
portset.c_iflag = IXON | IXOFF | IGNBRK | IGNCR;
|
||||||
portset.c_oflag &= ~ONLCR;
|
portset.c_oflag &= ~ONLCR;
|
||||||
@@ -160,22 +163,26 @@ tyan_lcdm_init (Driver * drvthis, char *args)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Set port speed */
|
/* Set port speed */
|
||||||
cfsetospeed (&portset, speed);
|
cfsetospeed(&portset, speed);
|
||||||
cfsetispeed (&portset, speed);
|
cfsetispeed(&portset, speed);
|
||||||
|
|
||||||
/* 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 = (unsigned char *) malloc (width * height);
|
framebuf = (unsigned char *) malloc(width * height);
|
||||||
memset (framebuf, ' ', width * height);
|
if (framebuf == NULL) {
|
||||||
|
report(RPT_ERR, "%s: unable to create framebuffer", drvthis->name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -184,12 +191,14 @@ tyan_lcdm_init (Driver * drvthis, char *args)
|
|||||||
MODULE_EXPORT void
|
MODULE_EXPORT void
|
||||||
tyan_lcdm_close (Driver * drvthis)
|
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,41 +227,40 @@ 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.
|
||||||
*/
|
*/
|
||||||
if (old==NULL) {
|
if (old == NULL) {
|
||||||
old = (unsigned char *) malloc (width * height);
|
old = (unsigned char *) malloc(width * height);
|
||||||
memset (old, ' ', width * height);
|
memset(old, ' ', width * height);
|
||||||
tyan_lcdm_hardware_clear (drvthis);
|
tyan_lcdm_hardware_clear(drvthis);
|
||||||
}
|
}
|
||||||
|
|
||||||
xp = framebuf;
|
xp = framebuf;
|
||||||
xq = old;
|
xq = old;
|
||||||
|
|
||||||
for (i=0; i<width; i++) {
|
for (i = 0; i < width; i++) {
|
||||||
if (*xp != *xq) {
|
if (*xp != *xq) {
|
||||||
tyan_lcdm_write_str(framebuf,0x80,16);
|
tyan_lcdm_write_str(framebuf, 0x80, 16);
|
||||||
memcpy(old, framebuf, width);
|
memcpy(old, framebuf, width);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
xp++; xq++;
|
xp++; xq++;
|
||||||
}
|
}
|
||||||
|
|
||||||
xp = &framebuf[width];
|
xp = &framebuf[width];
|
||||||
xq = &old[width];
|
xq = &old[width];
|
||||||
|
|
||||||
for (i=0; i<width; i++) {
|
for (i = 0; i < width; i++) {
|
||||||
if (*xp != *xq) {
|
if (*xp != *xq) {
|
||||||
tyan_lcdm_write_str(&framebuf[width],0xc0,16);
|
tyan_lcdm_write_str(&framebuf[width], 0xc0, 16);
|
||||||
memcpy(&old[width], &framebuf[width], width);
|
memcpy(&old[width], &framebuf[width], width);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
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,7 +308,8 @@ tyan_lcdm_chr (Driver * drvthis, int x, int y, char c)
|
|||||||
y--;
|
y--;
|
||||||
x--;
|
x--;
|
||||||
|
|
||||||
framebuf[(y * width) + x] = c;
|
if ((x >= 0) && (y >= 0) && (x < width) && (y < height))
|
||||||
|
framebuf[(y * width) + x] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -322,18 +329,19 @@ 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;
|
||||||
lcdcmd[2]=0x01;
|
lcdcmd[2] = 0x01;
|
||||||
lcdcmd[3]=TYAN_LCDM_CMD_END;
|
lcdcmd[3] = TYAN_LCDM_CMD_END;
|
||||||
write(fd,lcdcmd,4);
|
write(fd, lcdcmd, 4);
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
//send "LCD Ready" cmd
|
//send "LCD Ready" cmd
|
||||||
lcdcmd[1]=0x6c;
|
lcdcmd[1] = 0x6c;
|
||||||
lcdcmd[2]=TYAN_LCDM_CMD_END;
|
lcdcmd[2] = TYAN_LCDM_CMD_END;
|
||||||
write(fd,lcdcmd,3);
|
write(fd, lcdcmd, 3);
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -418,14 +426,13 @@ 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);
|
tyan_lcdm_set_char(drvthis, 4, d);
|
||||||
tyan_lcdm_set_char (drvthis, 4, d);
|
tyan_lcdm_set_char(drvthis, 5, e);
|
||||||
tyan_lcdm_set_char (drvthis, 5, e);
|
tyan_lcdm_set_char(drvthis, 6, f);
|
||||||
tyan_lcdm_set_char (drvthis, 6, f);
|
tyan_lcdm_set_char(drvthis, 7, g);
|
||||||
tyan_lcdm_set_char (drvthis, 7, g);
|
|
||||||
custom = vbar;
|
custom = vbar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -499,12 +506,12 @@ tyan_lcdm_init_hbar (Driver * drvthis)
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (custom != hbar) {
|
if (custom != hbar) {
|
||||||
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);
|
||||||
tyan_lcdm_set_char (drvthis, 4, d);
|
tyan_lcdm_set_char(drvthis, 4, d);
|
||||||
tyan_lcdm_set_char (drvthis, 5, e);
|
tyan_lcdm_set_char(drvthis, 5, e);
|
||||||
tyan_lcdm_set_char (drvthis, 6, f);
|
tyan_lcdm_set_char(drvthis, 6, f);
|
||||||
custom = hbar;
|
custom = hbar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -557,8 +564,9 @@ 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);
|
|
||||||
write (fd, out, 3);
|
snprintf(out, sizeof(out), "%c%c%c", 28, x, num);
|
||||||
|
write(fd, out, 3);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -572,32 +580,32 @@ 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);
|
||||||
/* I should remove that debug code. */
|
/* I should remove that debug code. */
|
||||||
// if (dat[(row * cellheight) + col] == 0) printf(".");
|
//if (dat[(row * cellheight) + col] == 0) printf(".");
|
||||||
// if (dat[(row * cellheight) + col] == 1) printf("+");
|
//if (dat[(row * cellheight) + col] == 1) printf("+");
|
||||||
// if (dat[(row * cellheight) + col] == 2) printf("x");
|
//if (dat[(row * cellheight) + col] == 2) printf("x");
|
||||||
// if (dat[(row * cellheight) + col] == 3) printf("*");
|
//if (dat[(row * cellheight) + col] == 3) printf("*");
|
||||||
// printf("'%1d'", dat[(row * cellwidth) + col]);
|
//printf("'%1d'", dat[(row * cellwidth) + col]);
|
||||||
// printf("%3d ", letter);
|
//printf("%3d ", letter);
|
||||||
}
|
}
|
||||||
out[row+1]=letter;
|
out[row+1] = letter;
|
||||||
// printf(": %d\n", letter);
|
//printf(": %d\n", letter);
|
||||||
}
|
}
|
||||||
tyan_lcdm_write_str(out,(unsigned char)(0x40+n*8),8);
|
tyan_lcdm_write_str(out, (unsigned char) (0x40 + n * 8), 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -698,50 +706,50 @@ tyan_lcdm_icon (Driver * drvthis, int x, int y, int icon)
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Yes we know, this is a VERY BAD implementation :-) */
|
/* Yes we know, this is a VERY BAD implementation :-) */
|
||||||
switch( icon ) {
|
switch (icon) {
|
||||||
case ICON_BLOCK_FILLED:
|
case ICON_BLOCK_FILLED:
|
||||||
tyan_lcdm_chr( drvthis, x, y, 255 );
|
tyan_lcdm_chr(drvthis, x, y, 255);
|
||||||
break;
|
break;
|
||||||
case ICON_HEART_FILLED:
|
case ICON_HEART_FILLED:
|
||||||
custom = cust;
|
custom = cust;
|
||||||
tyan_lcdm_set_char( drvthis, 0, icons[1] );
|
tyan_lcdm_set_char(drvthis, 0, icons[1]);
|
||||||
tyan_lcdm_chr( drvthis, x, y, 0 );
|
tyan_lcdm_chr(drvthis, x, y, 0);
|
||||||
break;
|
break;
|
||||||
case ICON_HEART_OPEN:
|
case ICON_HEART_OPEN:
|
||||||
custom = cust;
|
custom = cust;
|
||||||
tyan_lcdm_set_char( drvthis, 0, icons[0] );
|
tyan_lcdm_set_char(drvthis, 0, icons[0]);
|
||||||
tyan_lcdm_chr( drvthis, x, y, 0 );
|
tyan_lcdm_chr(drvthis, x, y, 0);
|
||||||
break;
|
break;
|
||||||
case ICON_ARROW_UP:
|
case ICON_ARROW_UP:
|
||||||
custom = cust;
|
custom = cust;
|
||||||
tyan_lcdm_set_char( drvthis, 1, icons[2] );
|
tyan_lcdm_set_char(drvthis, 1, icons[2]);
|
||||||
tyan_lcdm_chr( drvthis, x, y, 1 );
|
tyan_lcdm_chr(drvthis, x, y, 1);
|
||||||
break;
|
break;
|
||||||
case ICON_ARROW_DOWN:
|
case ICON_ARROW_DOWN:
|
||||||
custom = cust;
|
custom = cust;
|
||||||
tyan_lcdm_set_char( drvthis, 2, icons[3] );
|
tyan_lcdm_set_char(drvthis, 2, icons[3]);
|
||||||
tyan_lcdm_chr( drvthis, x, y, 2 );
|
tyan_lcdm_chr(drvthis, x, y, 2);
|
||||||
break;
|
break;
|
||||||
case ICON_ARROW_LEFT:
|
case ICON_ARROW_LEFT:
|
||||||
tyan_lcdm_chr( drvthis, x, y, 0x7F );
|
tyan_lcdm_chr(drvthis, x, y, 0x7F);
|
||||||
break;
|
break;
|
||||||
case ICON_ARROW_RIGHT:
|
case ICON_ARROW_RIGHT:
|
||||||
tyan_lcdm_chr( drvthis, x, y, 0x7E );
|
tyan_lcdm_chr(drvthis, x, y, 0x7E);
|
||||||
break;
|
break;
|
||||||
case ICON_CHECKBOX_OFF:
|
case ICON_CHECKBOX_OFF:
|
||||||
custom = cust;
|
custom = cust;
|
||||||
tyan_lcdm_set_char( drvthis, 3, icons[4] );
|
tyan_lcdm_set_char(drvthis, 3, icons[4]);
|
||||||
tyan_lcdm_chr( drvthis, x, y, 3 );
|
tyan_lcdm_chr(drvthis, x, y, 3);
|
||||||
break;
|
break;
|
||||||
case ICON_CHECKBOX_ON:
|
case ICON_CHECKBOX_ON:
|
||||||
custom = cust;
|
custom = cust;
|
||||||
tyan_lcdm_set_char( drvthis, 4, icons[5] );
|
tyan_lcdm_set_char(drvthis, 4, icons[5]);
|
||||||
tyan_lcdm_chr( drvthis, x, y, 4 );
|
tyan_lcdm_chr(drvthis, x, y, 4);
|
||||||
break;
|
break;
|
||||||
case ICON_CHECKBOX_GRAY:
|
case ICON_CHECKBOX_GRAY:
|
||||||
custom = cust;
|
custom = cust;
|
||||||
tyan_lcdm_set_char( drvthis, 5, icons[6] );
|
tyan_lcdm_set_char(drvthis, 5, icons[6]);
|
||||||
tyan_lcdm_chr( drvthis, x, y, 5 );
|
tyan_lcdm_chr(drvthis, x, y, 5);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1; /* Let the core do other icons */
|
return -1; /* Let the core do other icons */
|
||||||
@@ -756,7 +764,7 @@ tyan_lcdm_icon (Driver * drvthis, int x, int y, int icon)
|
|||||||
MODULE_EXPORT void
|
MODULE_EXPORT void
|
||||||
tyan_lcdm_clear (Driver * drvthis)
|
tyan_lcdm_clear (Driver * drvthis)
|
||||||
{
|
{
|
||||||
memset (framebuf, ' ', width * height);
|
memset(framebuf, ' ', width * height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -766,13 +774,14 @@ 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;
|
||||||
lcdcmd[2]=0x00;
|
lcdcmd[2] = 0x00;
|
||||||
lcdcmd[3]=0x01;
|
lcdcmd[3] = 0x01;
|
||||||
lcdcmd[4]=TYAN_LCDM_CMD_END;
|
lcdcmd[4] = TYAN_LCDM_CMD_END;
|
||||||
write(fd,lcdcmd,5);
|
write(fd, lcdcmd, 5);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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,35 +812,38 @@ 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[1]=0x70;
|
cmd_str[0] = TYAN_LCDM_CMD_BEGIN;
|
||||||
cmd_str[2]=0x00;
|
cmd_str[1] = 0x70;
|
||||||
cmd_str[3]=pos;
|
cmd_str[2] = 0x00;
|
||||||
cmd_str[4]=TYAN_LCDM_CMD_END;
|
cmd_str[3] = pos;
|
||||||
write( fd,cmd_str,5);
|
cmd_str[4] = TYAN_LCDM_CMD_END;
|
||||||
|
write(fd, cmd_str, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
cmd_str[1] = 0x70;
|
cmd_str[1] = 0x70;
|
||||||
cmd_str[2] = 0x02;
|
cmd_str[2] = 0x02;
|
||||||
cmd_str[19] = TYAN_LCDM_CMD_END;
|
cmd_str[19] = TYAN_LCDM_CMD_END;
|
||||||
memcpy(cmd_str+3,str,length);
|
memcpy(cmd_str+3, str, length);
|
||||||
write(fd,cmd_str,20);
|
write(fd, cmd_str, 20);
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
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);
|
|
||||||
count=read(fd,key_str,4);
|
memset(key_str, 0, 4);
|
||||||
if( key_str[0] == (char)TYAN_LCDM_CMD_BEGIN && key_str[1]==(char)0x72 && key_str[3]==(char)TYAN_LCDM_CMD_END){
|
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)) {
|
||||||
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