[Lcdproc] Patch for CW1602 USB, lcdproc 0.5.0

Tomislav Secen chense@vip.hr
Thu Sep 21 14:40:02 2006


This is a multi-part message in MIME format.
--------------080408030102040503060102
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi all,

I had some trouble getting CW1602 USB (the USB model with 16x2 chars) to work
with lcdproc 0.5.0, so after some messing around something came out. It still
isn't perfect - still bogs/garbles some characters at viscous scrolling, but
at least works (without these changes all I got was a bunch of garbled
characters on the screen).

I don't know what is the suggested method of submitting patches, nor if this
issues were addressed before - so if it isn't or if they were, sorry ;).

Issues spotted and fixed with the CW1602:
     -each character has 5x8 pixels (was 6x8)
     -custom characters are stored on locations 1-8, not 1-16
     -set_char routine needs to write 8 bytes out, one for each row of the
custom character (lcdproc wrote only 6 bytes in the define custom char command -
set_char function - which produced the totally garbled state of the LCD screen).
     -didn't modify the icons (to 5x8 pixels)

Was this driver written with 20x4 display in mind?

If anybody has any suggestions and/or proposals on how to further improve this 
driver, I would love to hear them.

Thanks!

--
Kind regards,
   chense

--------------080408030102040503060102
Content-Type: text/plain;
 name="lcdproc-0.5.0-CwLnx.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="lcdproc-0.5.0-CwLnx.patch"

diff -Naur lcdproc-0.5.0/server/drivers/CwLnx.c lcdproc-0.5.0-cwfix/server/drivers/CwLnx.c
--- lcdproc-0.5.0/server/drivers/CwLnx.c	2006-04-12 10:48:56.000000000 +0000
+++ lcdproc-0.5.0-cwfix/server/drivers/CwLnx.c	2006-09-21 13:08:59.000000000 +0000
@@ -185,6 +185,7 @@
     int rc;
 
     rc = write(fd, c, size);
+    if (rc==0 && rc==-1) printf ("write to fd failed!");
 /* Debuging code to be cleaned when very stable */
 /* 
     if (size == 1) {
@@ -516,9 +517,9 @@
     p->fd = -1;
     p->framebuf = NULL;
     p->backingstore = NULL;
-    p->cellwidth = DEFAULT_CELLWIDTH;
-    p->cellheight = DEFAULT_CELLHEIGHT;
-
+    p->cellwidth = 5;//DEFAULT_CELLWIDTH;
+    p->cellheight = 8;//DEFAULT_CELLHEIGHT;
+    
     p->saved_backlight = -1;
     p->backlight = DEFAULT_BACKLIGHT;
 
@@ -1156,7 +1157,7 @@
     char c;
     int rc;
 
-    if (n < 1 || n > 16)
+    if (n < 1 || n > 8)
 	return;
     if (!dat)
 	return;
@@ -1168,14 +1169,20 @@
     c = (char) n;
     rc = Write_LCD(p->fd, &c, 1);
 
-    for (col = 0; col < p->cellwidth; col++) {
-	letter = 0;
-	for (row = 0; row < p->cellheight; row++) {
-	    letter <<= 1;
-	    letter |= (dat[(col * p->cellheight) + row] > 0);
-	}
-	c = letter;
-	Write_LCD(p->fd, &c, 1);
+    //0 -> 7
+    for (col = 0; col<p->cellheight;  col++) 
+    {
+        letter = 0;
+        // 5, 1 -> 5
+        for (row = 1; row <= p->cellwidth;  row++) 
+        {
+            letter <<= 1;
+            letter |= (dat[row * p->cellheight -1-col] > 0);
+            // printf(" ndx=%d ",row * p->cellheight -1-col);
+        }
+        c = letter;
+        //      printf("col=%d row=%d letter=%x\n",col,row,letter);
+        Write_LCD(p->fd, &c, 1);
     }
     c = LCD_CMD_END;
     rc = Write_LCD(p->fd, &c, 1);
@@ -1288,44 +1295,44 @@
 /* Yes we know, this is a VERY BAD implementation */
 	switch (icon) {
 		case ICON_HEART_FILLED:
-			CwLnx_set_char(drvthis, 8, heart_filled);
-			CwLnx_chr(drvthis, x, y, 8);
+			CwLnx_set_char(drvthis, 1, heart_filled);
+			CwLnx_chr(drvthis, x, y, 1);
 			break;
 		case ICON_HEART_OPEN:
-			CwLnx_set_char(drvthis, 8, heart_open);
-			CwLnx_chr(drvthis, x, y, 8);
+			CwLnx_set_char(drvthis, 2, heart_open);
+			CwLnx_chr(drvthis, x, y, 2);
 			break;
 		case ICON_CHECKBOX_GRAY:
-			CwLnx_set_char(drvthis, 9, checkbox_gray);
-			CwLnx_chr(drvthis, x, y, 9);
+			CwLnx_set_char(drvthis, 3, checkbox_gray);
+			CwLnx_chr(drvthis, x, y, 3);
 			break;
 		case ICON_BLOCK_FILLED:
-			CwLnx_set_char(drvthis, 10, block_filled);
-			CwLnx_chr(drvthis, x, y, 10);
+			CwLnx_set_char(drvthis, 4, block_filled);
+			CwLnx_chr(drvthis, x, y, 4);
 			break;
 		case ICON_ARROW_UP:
-			CwLnx_set_char(drvthis, 11, arrow_up);
-			CwLnx_chr(drvthis, x, y, 11);
+			CwLnx_set_char(drvthis, 5, arrow_up);
+			CwLnx_chr(drvthis, x, y, 5);
 			break;
 		case ICON_ARROW_DOWN:
-			CwLnx_set_char(drvthis, 12, arrow_down);
-			CwLnx_chr(drvthis, x, y, 12);
+			CwLnx_set_char(drvthis, 6, arrow_down);
+			CwLnx_chr(drvthis, x, y, 6);
 			break;
 		case ICON_ARROW_LEFT:
-			CwLnx_set_char(drvthis, 13, arrow_left);
-			CwLnx_chr(drvthis, x, y, 13);
+			CwLnx_set_char(drvthis, 7, arrow_left);
+			CwLnx_chr(drvthis, x, y, 7);
 			break;
 		case ICON_ARROW_RIGHT:
-			CwLnx_set_char(drvthis, 14, arrow_right);
-			CwLnx_chr(drvthis, x, y, 14);
+			CwLnx_set_char(drvthis, 8, arrow_right);
+			CwLnx_chr(drvthis, x, y, 8);
 			break;
 		case ICON_CHECKBOX_OFF:
-			CwLnx_set_char(drvthis, 15, checkbox_off);
-			CwLnx_chr(drvthis, x, y, 15);
+			CwLnx_set_char(drvthis, 1, checkbox_off);
+			CwLnx_chr(drvthis, x, y, 1);
 			break;
 		case ICON_CHECKBOX_ON:
-			CwLnx_set_char(drvthis, 16, checkbox_on);
-			CwLnx_chr(drvthis, x, y, 16);
+			CwLnx_set_char(drvthis, 2, checkbox_on);
+			CwLnx_chr(drvthis, x, y, 2);
 			break;
 		default:
 			return -1; /* Let the core do other icons */

--------------080408030102040503060102--