LCDproc development and user support list

Text archives Help


[Lcdproc] [PATCH] MtxOrb.c for both 0.4.5 & 0.5


Chronological Thread 
  • From: lcdproc AT neko.me.uk (Chris Lansley)
  • Subject: [Lcdproc] [PATCH] MtxOrb.c for both 0.4.5 & 0.5
  • Date: Tue Sep 14 01:03:01 2004

OK - I've now got CVS write access!

I've got so many changes to make to the MtxOrb.c file that it would =
simply be too
much for anyone to review, so I've broken the change into smaller =
changes.

Here is my first small change - I'm combined some tidying up with the =
real reason
for the change; the use of strncpy on the framebuffer.


Here's a quick summary of the changes:

MtxOrb_parse_keypad_setting:
small tidy up - was doing a pointless strncpy.

MtxOrb_init:
small tidy up - was doing pointless strncpys.

MtxOrb_draw_frame:
Using strncpy on framebuffer - this is silly because the framebuffer =
contain 0 (which is the first custom char).


Below is a patch against the current 0.4.5 branch - I've also checked =
0.5 and the change could also be made there.

Chris.
[PS: Would people perfer to have the patch in an attachment?]


diff -u -r1.34.2.15.2.3 MtxOrb.c
--- MtxOrb.c 3 Feb 2003 16:53:58 -0000 1.34.2.15.2.3
+++ MtxOrb.c 14 Sep 2004 00:57:06 -0000
@@ -159,13 +159,10 @@
{
char return_val =3D 0;
char * s;
- char buf [255];
=20
s =3D config_get_string ( sectionname, keyname, 0, NULL);
if (s !=3D NULL){
- strncpy (buf, s, sizeof(buf));
- buf[sizeof(buf)-1]=3D0;
- return_val =3D buf[0];
+ return_val =3D *s;
} else {
return_val=3Ddefault_value;
}
@@ -200,8 +197,8 @@
int contrast =3D MTXORB_DEF_CONTRAST;
char device[256] =3D MTXORB_DEF_DEVICE;
int speed =3D MTXORB_DEF_SPEED;
- char size[256] =3D MTXORB_DEF_SIZE;
- char buf[256] =3D "";
+ char *size;
+ char *type;
int tmp, w, h;
=20
MtxOrb_type =3D MTXORB_LKD; // Assume it's an LCD w/keypad
@@ -222,8 +219,7 @@
report (RPT_INFO,"MtxOrb: Using device: %s", device);
=20
/* Get display size */
- strncpy(size, config_get_string ( DriverName , "size" , 0 , =
MTXORB_DEF_SIZE),sizeof(size));
- size[sizeof(size)-1]=3D0;
+ size=3Dconfig_get_string ( DriverName , "size" , 0 , MTXORB_DEF_SIZE);
if( sscanf(size , "%dx%d", &w, &h ) !=3D 2
|| (w <=3D 0) || (w > LCD_MAX_WIDTH)
|| (h <=3D 0) || (h > LCD_MAX_HEIGHT)) {
@@ -257,23 +253,27 @@
speed =3D B19200;
break;
default:
- speed =3D MTXORB_DEF_SPEED;
- switch (speed) {
- case B1200:
- strncpy(buf,"1200", sizeof(buf));
- break;
- case B2400:
- strncpy(buf,"2400", sizeof(buf));
- break;
- case B9600:
- strncpy(buf,"9600", sizeof(buf));
- break;
- case B19200:
- strncpy(buf,"19200", sizeof(buf));
- break;
+ {
+ int baud=3D0;
+ speed =3D MTXORB_DEF_SPEED;
+ switch (speed) {
+ case B1200:
+ baud=3D1200;
+ break;
+ case B2400:
+ baud=3D2400;
+ break;
+ case B9600:
+ baud=3D9600;
+ break;
+ case B19200:
+ baud=3D19200;
+ break;
+ }
+ report (RPT_WARNING ,=20
+ "MtxOrb: Speed must be 1200,
2400, 9600 or "
+ "19200. Using default
value of %u baud!", baud);
}
- report (RPT_WARNING , "MtxOrb: Speed must be 1200,
2400, 9600 or =
19200. Using default value of %s baud!", buf);
- strncpy(buf,"", sizeof(buf));
}
=20
=20
@@ -283,19 +283,19 @@
}
=20
/* Get display type */
- strncpy(buf, config_get_string ( DriverName , "type" , 0 , =
MTXORB_DEF_TYPE),sizeof(size));
- buf[sizeof(buf)-1]=3D0;
+ type=3Dconfig_get_string ( DriverName , "type" , 0 , MTXORB_DEF_TYPE);
=20
- if (strncasecmp(buf, "lcd", 3) =3D=3D 0) {
+ if (strncasecmp(type, "lcd", 3) =3D=3D 0) {
MtxOrb_type =3D MTXORB_LCD;
- } else if (strncasecmp(buf, "lkd", 3) =3D=3D 0) {
+ } else if (strncasecmp(type, "lkd", 3) =3D=3D 0) {
MtxOrb_type =3D MTXORB_LKD;
- } else if (strncasecmp (buf, "vfd", 3) =3D=3D 0) {
+ } else if (strncasecmp (type, "vfd", 3) =3D=3D 0) {
MtxOrb_type =3D MTXORB_VFD;
- } else if (strncasecmp (buf, "vkd", 3) =3D=3D 0) {
+ } else if (strncasecmp (type, "vkd", 3) =3D=3D 0) {
MtxOrb_type =3D MTXORB_VKD;
} else {
- report (RPT_ERR, "MtxOrb: unknwon display type %s; must be
one of =
lcd, lkd, vfd, or vkd", buf);
+ report (RPT_ERR, "MtxOrb: unknown display type %s; "
+ "must be one of lcd,
lkd, vfd, or vkd", type);
return (-1);
}
=20
@@ -1082,7 +1082,7 @@
write(fd, "\x0FEG\x01\x01", 4);
write(fd, dat, MtxOrb->wid * MtxOrb->hgt);
=20
- strncpy(old, dat, MtxOrb->wid * MtxOrb->hgt);
+ memcpy(old, dat, MtxOrb->wid * MtxOrb->hgt);
=20
return;
=20
@@ -1125,7 +1125,7 @@
*}
*/
=20
- strncpy(old, dat, MtxOrb->wid * MtxOrb->hgt);
+ memcpy(old, 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