LCDproc development and user support list

Text archives Help


[Lcdproc] [PATCH] MtxOrb.c - patch 2


Chronological Thread 
  • From: lcdproc AT neko.me.uk (Chris Lansley)
  • Subject: [Lcdproc] [PATCH] MtxOrb.c - patch 2
  • Date: Tue Sep 14 02:15:01 2004

Here's a second patch:

The bignum code uses a "dirty character" of 254, which is ok as nobody =
is going to be using 254 on the framebuffer; because it's the command =
escape code for Matrix Orbitals. The problem is that this "dirty =
character" gets on to the wire and ends up sending random commands to =
the LCD! There are also a few other small changes included.


Heres' a quick summary of the change:
MtxOrb_draw_frame:
- don't allow the dirty character on to the wire.
- there's no need to keep sending custom chars (<8) they will =
automatically change when they are redefined.
- share the "old" copy of the frame buffer with MtxOrb_flush_box
(make =
it global)
- remove commented out code - it's stored forever in CVS anyway.
=09
MtxOrb_flush_box:
- <same as MtxOrb_draw_frame>
- update the "old" copy of the frame buffer

MtxOrb_init:
- fill frame buffer with spaces, just to be safe.
- malloc the "old" copy of the frame buffer and fill with dirty char

MtxOrb_close:
- free the "old" copy of the frame buffer

Below is a patch against the current 0.4.5 branch patched with my =
previous patch - I've checked 0.5 and it doesn't seem to make sense to =
make this change there (no dirty char and no MtxOrb_flush_box).

Chris.


--- MtxOrb.c.patch1 Tue Sep 14 02:33:22 2004
+++ MtxOrb.c Tue Sep 14 03:26:24 2004
@@ -106,6 +106,7 @@
barb =3D 255
} bar_type;
=20
+static unsigned char *lcd_contains; // what we think is actually on the =
LCD
static int custom =3D 0;
static enum {MTXORB_LCD, MTXORB_LKD, MTXORB_VFD, MTXORB_VKD} =
MtxOrb_type;
static int fd;
@@ -341,6 +342,18 @@
report(RPT_ERR, "MtxOrb: Error: unable to create =
framebuffer.");
return -1;
}
+=09
+ // Initialize to be empty, just to be safe.
+ memset (MtxOrb->framebuf, ' ', (MtxOrb->wid * MtxOrb->hgt));
+
+ lcd_contains =3D malloc(MtxOrb->wid * MtxOrb->hgt);
+ if (!lcd_contains) {
+ report(RPT_ERR, "MtxOrb: Error: unable to create =
lcd_contains.");
+ return -1;
+ }
+ // Fill it with the dirty char so the first LCD screen will all be =
sent.
+ memset(lcd_contains, DIRTY_CHAR, MtxOrb->wid * MtxOrb->hgt);
+
=20
/* Set up io port correctly, and open it... */
fd =3D open (device, O_RDWR | O_NOCTTY);
@@ -475,6 +488,10 @@
=20
MtxOrb->framebuf =3D NULL;
=20
+ if (lcd_contains)
+ free (lcd_contains);
+ lcd_contains=3DNULL;
+
report(RPT_INFO, "MtxOrb: closed");
}
=20
@@ -507,16 +524,41 @@
static void
MtxOrb_flush_box (int lft, int top, int rgt, int bot)
{
- int y;
- char out[LCD_MAX_WIDTH];
+ int y;
+ int x;
+ int mv=3D0;
+ unsigned char *p, *q;
+ =20
+ debug(RPT_DEBUG, "MtxOrb: flush_box(%d,%d,%d,%d)", lft, top, rgt, =
bot);
+
+ // We can't just write it out because it could contain
+ // the dirty character.
+ for (y =3D top; y <=3D bot; y++) {
+ p=3D(unsigned char *)MtxOrb->framebuf + (y * MtxOrb->wid) + =
lft;
+ q =3D lcd_contains + (y*MtxOrb->wid) + lft;
+ mv =3D 1;
+
+ for (x =3D lft; x <=3D rgt; x++) {
+
+ if ((*p =3D=3D *q) || (*p =3D=3D DIRTY_CHAR))
+ mv =3D 1;
+ else {
+
+ if (mv =3D=3D 1)
+ {
+ char out[5];
+ snprintf(out, sizeof(out), "\x0FEG%c%c", x, y);
+ write (fd, out, 4);
+ mv =3D 0;
+ }
+ write (fd, p, 1);
+ *q =3D *p;
+ }
+ p++;
+ q++;
+ }
+ }
=20
- debug(RPT_DEBUG, "MtxOrb: flush_box(%d,%d,%d,%d)", lft, top, rgt, =
bot);
-
- for (y =3D top; y <=3D bot; y++) {
- snprintf (out, sizeof(out), "\x0FEG%c%c", lft, y);
- write (fd, out, 4);
- write (fd, MtxOrb->framebuf + (y * MtxOrb->wid) + lft, rgt -
lft + =
1);
- }
debug(RPT_DEBUG, "MtxOrb: frame buffer box flushed");
}
=20
@@ -974,6 +1016,11 @@
* hiden behind the hardware bignum dirty so that they get cleaned
* when draw_frame is called. There is no dirty char so I will use 254
* hoping nobody is using that char. GLU
+ *
+ * Nobody is going to be using 254 - as that's the command escape =
character! CJL
+ *
+ * TODO: No support for num=3D=3D10 - this is meant to be a colon - CJL
+ *
*/
=20
=
/************************************************************************=
*
@@ -1070,39 +1117,21 @@
{
char out[12];
int i,j,mv =3D 1;
- static char *old =3D NULL;
- char *p, *q;
+ unsigned char *p, *q;
=20
if (!dat)
return;
=20
- if (old =3D=3D NULL) {
- old =3D malloc(MtxOrb->wid * MtxOrb->hgt);
-
- write(fd, "\x0FEG\x01\x01", 4);
- write(fd, dat, MtxOrb->wid * MtxOrb->hgt);
-
- memcpy(old, dat, MtxOrb->wid * MtxOrb->hgt);
-
- return;
-
- } else {
- if (! new_framebuf(MtxOrb, old))
- return;
- }
-
- p =3D dat;
- q =3D old;
+ p =3D (unsigned char*)dat;
+ q =3D lcd_contains;
=20
for (i =3D 1; i <=3D MtxOrb->hgt; i++) {
for (j =3D 1; j <=3D MtxOrb->wid; j++) {
=20
- if ((*p =3D=3D *q) && (*p > 8))
+ if ((*p =3D=3D *q) || (*p =3D=3D DIRTY_CHAR))
mv =3D 1;
else {
- /* Draw characters that have changed, as well
- + as custom characters. We know not if a
custom
- * character has changed.
+ /* Draw characters that have changed.
*/
=20
if (mv =3D=3D 1) {
@@ -1117,15 +1146,7 @@
}
}
=20
-
- /*for (i =3D 0; i < MtxOrb->hgt; i++) {
- * snprintf (out, sizeof(out), "\x0FEG\x001%c", i + 1);
- * write (fd, out, 4);
- * write (fd, dat + (MtxOrb->wid * i), MtxOrb->wid);
- *}
- */
-
- memcpy(old, dat, MtxOrb->wid * MtxOrb->hgt);
+ memcpy(lcd_contains, dat, MtxOrb->wid * MtxOrb->hgt);
}
=20
/* TODO: Recover the code for I2C connectivity to MtxOrb







Archive powered by MHonArc 2.6.18.

Top of page