From a8d642c8c2dcb10ebaf878b7b97c7da8f8c3062d Mon Sep 17 00:00:00 2001 From: reinelt <> Date: Sat, 16 Aug 2003 07:31:35 +0000 Subject: [lcd4linux @ 2003-08-16 07:31:35 by reinelt] double buffering in all drivers --- USBLCD.c | 91 +++++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 26 deletions(-) (limited to 'USBLCD.c') diff --git a/USBLCD.c b/USBLCD.c index 6d58c61..c9a0986 100644 --- a/USBLCD.c +++ b/USBLCD.c @@ -1,4 +1,4 @@ -/* $Id: USBLCD.c,v 1.10 2003/07/24 04:48:09 reinelt Exp $ +/* $Id: USBLCD.c,v 1.11 2003/08/16 07:31:35 reinelt Exp $ * * Driver for USBLCD ( see http://www.usblcd.de ) * This Driver is based on HD44780.c @@ -22,6 +22,9 @@ * * * $Log: USBLCD.c,v $ + * Revision 1.11 2003/08/16 07:31:35 reinelt + * double buffering in all drivers + * * Revision 1.10 2003/07/24 04:48:09 reinelt * 'soft clear' needed for virtual rows * @@ -94,13 +97,13 @@ #define CHARS 8 static LCD Lcd; - -int usblcd_file; - static char *Port=NULL; -static char Txt[4][40]; +static int usblcd_file; + +static char *FrameBuffer1=NULL; +static char *FrameBuffer2=NULL; -static unsigned char Buffer[1024]; +static unsigned char *Buffer; static unsigned char *BufPtr; static void USBLCD_send () @@ -195,19 +198,15 @@ static void USBLCD_define_char (int ascii, char *buffer) int USBLCD_clear (int full) { - int row, col; - - for (row=0; rowcols=cols; Lcd=*Self; + // Init the command buffer + Buffer = (char*)malloc(1024); + if (Buffer==NULL) { + error ("USBLCD: coommand buffer could not be allocated: malloc() failed"); + return -1; + } + + // Init the framebuffers + FrameBuffer1 = (char*)malloc(Lcd.cols*Lcd.rows*sizeof(char)); + FrameBuffer2 = (char*)malloc(Lcd.cols*Lcd.rows*sizeof(char)); + if (FrameBuffer1==NULL || FrameBuffer2==NULL) { + error ("USBLCD: framebuffer could not be allocated: malloc() failed"); + return -1; + } + if (USBLCD_open()!=0) return -1; @@ -271,7 +285,7 @@ void USBLCD_goto (int row, int col) int USBLCD_put (int row, int col, char *text) { - char *p=&Txt[row][col]; + char *p=FrameBuffer1+row*Lcd.cols+col; char *t=text; while (*t && col++<=Lcd.cols) { @@ -289,9 +303,8 @@ int USBLCD_bar (int type, int row, int col, int max, int len1, int len2) int USBLCD_flush (void) { - char buffer[256]; - char *p; - int c, row, col; + int row, col, pos1, pos2; + int c, equal; bar_process(USBLCD_define_char); @@ -299,31 +312,57 @@ int USBLCD_flush (void) for (col=0; col2) break; + } else { + pos2=col; + equal=0; + } } - USBLCD_write (buffer, p-buffer); + USBLCD_write (FrameBuffer1+row*Lcd.cols+pos1, pos2-pos1+1); } } USBLCD_send(); + memcpy (FrameBuffer2, FrameBuffer1, Lcd.rows*Lcd.cols*sizeof(char)); + return 0; } int USBLCD_quit (void) { + info("USBLCD: shutting down."); USBLCD_send(); + debug ("closing port %s", Port); close(usblcd_file); + + if (Buffer) { + free(Buffer); + Buffer=NULL; + } + + if (FrameBuffer1) { + free(FrameBuffer1); + FrameBuffer1=NULL; + } + + if (FrameBuffer2) { + free(FrameBuffer2); + FrameBuffer2=NULL; + } + return 0; } -- cgit v1.2.3