From db2a64cd4d6e46a6563181f38da2a0a01f56a559 Mon Sep 17 00:00:00 2001 From: reinelt <> Date: Sat, 22 Feb 2003 07:23:24 +0000 Subject: [lcd4linux @ 2003-02-22 07:23:24 by reinelt] Cwlinux fixes --- Cwlinux.c | 190 +++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 102 insertions(+), 88 deletions(-) (limited to 'Cwlinux.c') diff --git a/Cwlinux.c b/Cwlinux.c index 07cbda4..6cbb51a 100644 --- a/Cwlinux.c +++ b/Cwlinux.c @@ -1,4 +1,4 @@ -/* $Id: Cwlinux.c,v 1.3 2002/09/12 05:24:54 reinelt Exp $ +/* $Id: Cwlinux.c,v 1.4 2003/02/22 07:23:24 reinelt Exp $ * * driver for Cwlinux serial display modules * @@ -20,6 +20,9 @@ * * * $Log: Cwlinux.c,v $ + * Revision 1.4 2003/02/22 07:23:24 reinelt + * Cwlinux fixes + * * Revision 1.3 2002/09/12 05:24:54 reinelt * code cleanup, character defining for bars * @@ -57,27 +60,7 @@ #define YRES 8 #define CHARS 7 -#define LCD_CMD 254 -#define LCD_CMD_END 253 -#define LCD_INIT_CHINESE_T 56 -#define LCD_INIT_CHINESE_S 55 -#define LCD_LIGHT_ON 66 -#define LCD_LIGHT_OFF 70 -#define LCD_CLEAR 88 -#define LCD_SET_INSERT 71 -#define LCD_INIT_INSERT 72 -#define LCD_SET_BAUD 57 -#define LCD_ENABLE_WRAP 67 -#define LCD_DISABLE_WRAP 68 -#define LCD_SETCHAR 78 -#define LCD_ENABLE_CURSOR 81 -#define LCD_DISABLE_CURSOR 82 - -#define LCD_LENGTH 20 - -#define DELAY 20 -#define UPDATE_DELAY 0 /* 1 sec */ -#define SETUP_DELAY 0 /* 2 sec */ +#define DELAY 200 static LCD Lcd; static char *Port = NULL; @@ -86,7 +69,8 @@ static int Device = -1; static char Txt[4][20]; -static int CwLnx_open(void) + +static int CW_open(void) { int fd; pid_t pid; @@ -99,6 +83,7 @@ static int CwLnx_open(void) error("Cwlinux: port %s is locked by process %d", Port, pid); return -1; } + fd = open(Port, O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) { error("Cwlinux: open(%s) failed: %s", Port, strerror(errno)); @@ -111,16 +96,19 @@ static int CwLnx_open(void) return -1; } cfmakeraw(&portset); + cfsetispeed(&portset, Speed); cfsetospeed(&portset, Speed); if (tcsetattr(fd, TCSANOW, &portset) == -1) { error("Cwlinux: tcsetattr(%s) failed: %s", Port, strerror(errno)); unlock_port(Port); return -1; } + return fd; } -static void CwLnx_write(char *string, int len) + +static void CW_write(char *string, int len) { if (write (Device, string, len)==-1) { if (errno==EAGAIN) { @@ -129,32 +117,48 @@ static void CwLnx_write(char *string, int len) } error ("Cwlinux: write(%s) failed: %s", Port, strerror(errno)); } + usleep(DELAY); +} + + +static int CW_read(char *string, int len) +{ + int ret; + + ret=read (Device, string, len); + if (ret<0 && errno==EAGAIN) { + usleep(1000); + ret=read (Device, string, len); + } + debug ("read(%s)=%d", string, ret); + + if (ret<0) { + error("Cwlinux: read() failed: %s", strerror(errno)); + } - // Fixme: Why? - // usleep(DELAY); + usleep(DELAY); + + return ret; } -static void CwLnx_Goto(int row, int col) + +static void CW_Goto(int row, int col) { - char cmd[5]; + char cmd[5]="\376Gxy\375"; - cmd[0]=LCD_CMD; - cmd[1]=LCD_SET_INSERT; cmd[2]=(char)col; cmd[3]=(char)row; - cmd[4]=LCD_CMD_END; - - CwLnx_write(cmd,5); + CW_write(cmd,5); + usleep(DELAY); + } -static void CwLnx_define_char (int ascii, char *buffer) +static void CW_define_char (int ascii, char *buffer) { - char cmd[10]; int i, j; + char cmd[10]="\376Nn123456\375"; - cmd[0]=LCD_CMD; - cmd[1]=LCD_SETCHAR; - cmd[2]=(char)ascii; + cmd[2]=(char)ascii+1; // Cwlinux uses a vertical bitmap layout, so // we have to kind of 'rotate' the bitmap. @@ -163,19 +167,18 @@ static void CwLnx_define_char (int ascii, char *buffer) cmd[3+i]=0; for (j=0; j<8;j++) { if (buffer[j] & (1<<(5-i))) { - cmd[3+i]|=(1<