diff options
author | reinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f> | 2003-09-09 06:54:43 +0000 |
---|---|---|
committer | reinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f> | 2003-09-09 06:54:43 +0000 |
commit | dd4d20ad1a3970752a4fe81c95c164bf751c0f16 (patch) | |
tree | c78e80eb3a22e818c6039ca5aa68c7f46000fd94 | |
parent | ca55019e85e081afe878a93ba0dc83a44d862de9 (diff) | |
download | lcd4linux-dd4d20ad1a3970752a4fe81c95c164bf751c0f16.tar.gz |
[lcd4linux @ 2003-09-09 06:54:43 by reinelt]
new function 'cfg_number()'
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@233 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
-rw-r--r-- | Crystalfontz.c | 20 | ||||
-rw-r--r-- | Cwlinux.c | 22 | ||||
-rw-r--r-- | HD44780.c | 40 | ||||
-rw-r--r-- | M50530.c | 18 | ||||
-rw-r--r-- | MatrixOrbital.c | 31 | ||||
-rw-r--r-- | PalmPilot.c | 18 | ||||
-rw-r--r-- | Raster.c | 7 | ||||
-rw-r--r-- | USBLCD.c | 16 | ||||
-rw-r--r-- | XWindow.c | 9 | ||||
-rw-r--r-- | cfg.c | 56 | ||||
-rw-r--r-- | cfg.h | 9 | ||||
-rw-r--r-- | filter.c | 11 | ||||
-rw-r--r-- | lcd4linux.c | 13 | ||||
-rw-r--r-- | parport.c | 17 | ||||
-rw-r--r-- | processor.c | 25 |
15 files changed, 177 insertions, 135 deletions
diff --git a/Crystalfontz.c b/Crystalfontz.c index 8e11d35..5b4fe6f 100644 --- a/Crystalfontz.c +++ b/Crystalfontz.c @@ -1,4 +1,4 @@ -/* $Id: Crystalfontz.c,v 1.13 2003/08/24 05:17:58 reinelt Exp $ +/* $Id: Crystalfontz.c,v 1.14 2003/09/09 06:54:43 reinelt Exp $ * * driver for display modules from Crystalfontz * @@ -19,6 +19,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: Crystalfontz.c,v $ + * Revision 1.14 2003/09/09 06:54:43 reinelt + * new function 'cfg_number()' + * * Revision 1.13 2003/08/24 05:17:58 reinelt * liblcd4linux patch from Patrick Schemitz * @@ -145,7 +148,7 @@ static int CF_backlight (void) char buffer[3]; int backlight; - backlight=atoi(cfg_get("Backlight","0")); + if (cfg_number("Backlight", 0, 0, 100, &backlight)<0) return -1; snprintf (buffer, 3, "\016%c", backlight); CF_write (buffer, 2); return 0; @@ -157,7 +160,7 @@ static int CF_contrast (void) char buffer[3]; int contrast; - contrast=atoi(cfg_get("Contrast","50")); + if (cfg_number("Contrast", 50, 0, 100, &contrast)<0) return -1; snprintf (buffer, 3, "\017%c", contrast); CF_write (buffer, 2); return 0; @@ -192,7 +195,7 @@ static int CF_clear (int full) static int CF_init (LCD *Self) { char *port; - char *speed; + int speed; Lcd=*Self; @@ -216,9 +219,10 @@ static int CF_init (LCD *Self) } Port=strdup(port); - speed=cfg_get("Speed","19200"); - switch (atoi(speed)) { + if (cfg_number("Speed", 19200, 1200,19200, &speed)<0) return -1; + + switch (speed) { case 1200: Speed=B1200; break; @@ -232,11 +236,11 @@ static int CF_init (LCD *Self) Speed=B19200; break; default: - error ("Crystalfontz: unsupported speed '%s' in %s", speed, cfg_source()); + error ("Crystalfontz: unsupported speed '%d' in %s", speed, cfg_source()); return -1; } - debug ("using port %s at %d baud", Port, atoi(speed)); + debug ("using port %s at %d baud", Port, speed); Device=CF_open(); if (Device==-1) return -1; @@ -1,4 +1,4 @@ -/* $Id: Cwlinux.c,v 1.12 2003/08/24 05:17:58 reinelt Exp $ +/* $Id: Cwlinux.c,v 1.13 2003/09/09 06:54:43 reinelt Exp $ * * driver for Cwlinux serial display modules * @@ -20,6 +20,9 @@ * * * $Log: Cwlinux.c,v $ + * Revision 1.13 2003/09/09 06:54:43 reinelt + * new function 'cfg_number()' + * * Revision 1.12 2003/08/24 05:17:58 reinelt * liblcd4linux patch from Patrick Schemitz * @@ -242,10 +245,8 @@ static void CW_Brightness(void) { int level; char cmd[5]="\376A_\375"; - - level=atoi(cfg_get("Brightness","8")); - if (level<0) level=0; - if (level>8) level=8; + + if (cfg_number("Brightness", 8, 0, 8, &level)<0) return; switch (level) { case 0: @@ -268,7 +269,7 @@ static void CW_Brightness(void) int CW_init(LCD * Self) { char *port; - char *speed; + int speed; // char buffer[16]; Lcd = *Self; @@ -293,9 +294,8 @@ int CW_init(LCD * Self) } Port = strdup(port); - speed = cfg_get("Speed","19200"); - - switch (atoi(speed)) { + if (cfg_number("Speed", 19200, 9600,19200, &speed)<0) return -1; + switch (speed) { case 9600: Speed = B9600; break; @@ -303,11 +303,11 @@ int CW_init(LCD * Self) Speed = B19200; break; default: - error("Cwlinux: unsupported speed '%s' in %s", speed, cfg_source()); + error("Cwlinux: unsupported speed '%d' in %s", speed, cfg_source()); return -1; } - debug("using port %s at %d baud", Port, atoi(speed)); + debug("using port %s at %d baud", Port, speed); Device = CW_open(); if (Device == -1) @@ -1,4 +1,4 @@ -/* $Id: HD44780.c,v 1.36 2003/08/24 05:17:58 reinelt Exp $ +/* $Id: HD44780.c,v 1.37 2003/09/09 06:54:43 reinelt Exp $ * * driver for display modules based on the HD44780 chip * @@ -27,6 +27,9 @@ * * * $Log: HD44780.c,v $ + * Revision 1.37 2003/09/09 06:54:43 reinelt + * new function 'cfg_number()' + * * Revision 1.36 2003/08/24 05:17:58 reinelt * liblcd4linux patch from Patrick Schemitz * @@ -400,7 +403,7 @@ int HD_clear (int full) int HD_init (LCD *Self) { int rows=-1, cols=-1, gpos=-1; - char *s, *e; + char *s; s=cfg_get("Size",NULL); if (s==NULL || *s=='\0') { @@ -411,30 +414,16 @@ int HD_init (LCD *Self) error ("HD44780: bad size '%s'",s); return -1; } - - s=cfg_get ("GPOs",NULL); - if (s==NULL) { - gpos=0; - } - else { - gpos=strtol(s, &e, 0); - if (*e!='\0' || gpos<0 || gpos>8) { - error ("HD44780: bad GPOs '%s' in %s", s, cfg_source()); - return -1; - } - } - s=cfg_get("Controllers", "1"); - Controllers=strtol(s, &e, 0); - if (*e!='\0' || Controllers<1 || Controllers>2) { - error ("HD44780: bad Controllers '%s' in %s, should be '1' or '2'", s, cfg_source()); - return -1; - } + if (cfg_number("GPOs", 0, 0, 8, &gpos)<0) return -1; + info ("HD44780: controlling %d GPO's", gpos); + + if (cfg_number("Controllers", 1, 1, 2, &Controllers)<0) return -1; info ("wiring: using display with %d controllers", Controllers); // current controller Controller=1; - + Self->rows=rows; Self->cols=cols; Self->gpos=gpos; @@ -447,15 +436,14 @@ int HD_init (LCD *Self) error ("HD44780: framebuffer could not be allocated: malloc() failed"); return -1; } - - s=cfg_get("Bits", "8"); - Bits=strtol(s, &e, 0); - if (*e!='\0' || (Bits!=4 && Bits!=8)) { + + if (cfg_number("Bits", 8, 4, 8, &Bits)<0) return -1; + if (Bits!=4 && Bits!=8) { error ("HD44780: bad Bits '%s' in %s, should be '4' or '8'", s, cfg_source()); return -1; } info ("wiring: using %d bit mode", Bits); - + if (Bits==8) { if ((SIGNAL_RS = parport_wire_ctrl ("RS", "AUTOFD"))==0xff) return -1; if ((SIGNAL_RW = parport_wire_ctrl ("RW", "GND") )==0xff) return -1; @@ -1,4 +1,4 @@ -/* $Id: M50530.c,v 1.12 2003/08/24 05:17:58 reinelt Exp $ +/* $Id: M50530.c,v 1.13 2003/09/09 06:54:43 reinelt Exp $ * * driver for display modules based on the M50530 chip * @@ -20,6 +20,9 @@ * * * $Log: M50530.c,v $ + * Revision 1.13 2003/09/09 06:54:43 reinelt + * new function 'cfg_number()' + * * Revision 1.12 2003/08/24 05:17:58 reinelt * liblcd4linux patch from Patrick Schemitz * @@ -179,7 +182,7 @@ int M5_clear (int full) int M5_init (LCD *Self) { int rows=-1, cols=-1, gpos=-1; - char *s, *e; + char *s; s=cfg_get("Size",NULL); if (s==NULL || *s=='\0') { @@ -191,16 +194,7 @@ int M5_init (LCD *Self) return -1; } - s=cfg_get ("GPOs",NULL); - if (s==NULL) { - gpos=0; - } else { - gpos=strtol(s, &e, 0); - if (*e!='\0' || gpos<0 || gpos>8) { - error ("M50530: bad GPOs '%s' in %s", s, cfg_source()); - return -1; - } - } + if (cfg_number("GPOs", 0, 0, 8, &gpos)<0) return -1; Self->rows=rows; Self->cols=cols; diff --git a/MatrixOrbital.c b/MatrixOrbital.c index f27b04a..2c0a193 100644 --- a/MatrixOrbital.c +++ b/MatrixOrbital.c @@ -1,4 +1,4 @@ -/* $Id: MatrixOrbital.c,v 1.36 2003/09/09 05:30:33 reinelt Exp $ +/* $Id: MatrixOrbital.c,v 1.37 2003/09/09 06:54:43 reinelt Exp $ * * driver for Matrix Orbital serial display modules * @@ -20,6 +20,9 @@ * * * $Log: MatrixOrbital.c,v $ + * Revision 1.37 2003/09/09 06:54:43 reinelt + * new function 'cfg_number()' + * * Revision 1.36 2003/09/09 05:30:33 reinelt * even more icons stuff * @@ -255,7 +258,7 @@ static int MO_contrast (void) char buffer[4]; int contrast; - contrast=atoi(cfg_get("Contrast","160")); + if (cfg_number("Contrast", 160, 0, 255, &contrast)<0) return -1; snprintf (buffer, 4, "\376P%c", contrast); MO_write (buffer, 3); return 0; @@ -317,7 +320,7 @@ int MO_clear2 (int full) static int MO_init (LCD *Self, int protocol) { char *port; - char *s, *e; + int speed; Lcd=*Self; @@ -341,9 +344,8 @@ static int MO_init (LCD *Self, int protocol) } Port=strdup(port); - s=cfg_get("Speed","19200"); - - switch (atoi(s)) { + if (cfg_number("Speed", 19200, 1200,19200, &speed)<0) return -1; + switch (speed) { case 1200: Speed=B1200; break; @@ -357,28 +359,23 @@ static int MO_init (LCD *Self, int protocol) Speed=B19200; break; default: - error ("MatrixOrbital: unsupported speed '%s' in %s", s, cfg_source()); + error ("MatrixOrbital: unsupported speed '%d' in %s", speed, cfg_source()); return -1; } - - debug ("using port %s at %d baud", Port, atoi(s)); - + + debug ("using port %s at %d baud", Port, speed); + Device=MO_open(); if (Device==-1) return -1; - s=cfg_get("Icons", "0"); - Icons=strtol(s, &e, 0); - if (*e!='\0' || Icons<0 || Icons>8) { - error ("MatrixOrbital: bad Icons '%s' in %s, must be between 0 and 8", s, cfg_source()); - return -1; - } + if (cfg_number("Icons", 0, 0, 8, &Icons)<0) return -1; if (Icons>0) { info ("reserving %d of %d user-defined characters for icons", Icons, CHARS); icon_init(Lcd.rows, Lcd.cols, XRES, YRES, CHARS, Icons, MO_define_char); Self->icons=Icons; Lcd.icons=Icons; } - + bar_init(Lcd.rows, Lcd.cols, XRES, YRES, CHARS-Icons); bar_add_segment( 0, 0,255, 32); // ASCII 32 = blank bar_add_segment(255,255,255,255); // ASCII 255 = block diff --git a/PalmPilot.c b/PalmPilot.c index 7b1a8bb..502374f 100644 --- a/PalmPilot.c +++ b/PalmPilot.c @@ -1,4 +1,4 @@ -/* $Id: PalmPilot.c,v 1.11 2003/08/24 05:17:58 reinelt Exp $ +/* $Id: PalmPilot.c,v 1.12 2003/09/09 06:54:43 reinelt Exp $ * * driver for 3Com Palm Pilot * @@ -20,6 +20,9 @@ * * * $Log: PalmPilot.c,v $ + * Revision 1.12 2003/09/09 06:54:43 reinelt + * new function 'cfg_number()' + * * Revision 1.11 2003/08/24 05:17:58 reinelt * liblcd4linux patch from Patrick Schemitz * @@ -214,7 +217,8 @@ int Palm_clear (int full) int Palm_init (LCD *Self) { - char *port, *speed, *s; + char *port, *s; + int speed; int rows=-1, cols=-1; int xres=1, yres=-1; @@ -230,9 +234,9 @@ int Palm_init (LCD *Self) } Port=strdup(port); - speed=cfg_get("Speed","19200"); + if (cfg_number("Speed", 19200, 1200,19200, &speed)<0) return -1; - switch (atoi(speed)) { + switch (speed) { case 1200: Speed=B1200; break; @@ -249,11 +253,11 @@ int Palm_init (LCD *Self) Speed=B19200; break; default: - error ("PalmPilot: unsupported speed '%s' in %s", speed, cfg_source()); + error ("PalmPilot: unsupported speed '%d' in %s", speed, cfg_source()); return -1; } - debug ("using port %s at %d baud", Port, atoi(speed)); + debug ("using port %s at %d baud", Port, speed); if (sscanf(s=cfg_get("size","20x4"), "%dx%d", &cols, &rows)!=2 || rows<1 || cols<1) { error ("PalmPilot: bad size '%s'", s); @@ -277,7 +281,7 @@ int Palm_init (LCD *Self) if (rgap<0) rgap=pixel+pgap; if (cgap<0) cgap=pixel+pgap; - border=atoi(cfg_get("border","0")); + if (cfg_number("border", 0, 0, 1000000, &border)<0) return -1; if (pix_init (rows, cols, xres, yres)!=0) { error ("PalmPilot: pix_init(%d, %d, %d, %d) failed", rows, cols, xres, yres); @@ -1,4 +1,4 @@ -/* $Id: Raster.c,v 1.25 2003/08/24 05:17:58 reinelt Exp $ +/* $Id: Raster.c,v 1.26 2003/09/09 06:54:43 reinelt Exp $ * * driver for raster formats * @@ -20,6 +20,9 @@ * * * $Log: Raster.c,v $ + * Revision 1.26 2003/09/09 06:54:43 reinelt + * new function 'cfg_number()' + * * Revision 1.25 2003/08/24 05:17:58 reinelt * liblcd4linux patch from Patrick Schemitz * @@ -369,7 +372,7 @@ int Raster_init (LCD *Self) if (rgap<0) rgap=pixel+pgap; if (cgap<0) cgap=pixel+pgap; - border=atoi(cfg_get("border","0")); + if (cfg_number("border", 0, 0, 1000000, &border)<0) return -1; if (sscanf(s=cfg_get("foreground","#102000"), "#%x", &foreground)!=1) { error ("Raster: bad foreground color '%s'", s); @@ -1,4 +1,4 @@ -/* $Id: USBLCD.c,v 1.13 2003/09/09 05:30:34 reinelt Exp $ +/* $Id: USBLCD.c,v 1.14 2003/09/09 06:54:43 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.14 2003/09/09 06:54:43 reinelt + * new function 'cfg_number()' + * * Revision 1.13 2003/09/09 05:30:34 reinelt * even more icons stuff * @@ -224,7 +227,7 @@ int USBLCD_clear (int full) int USBLCD_init (LCD *Self) { int rows=-1, cols=-1 ; - char *port, *s, *e; + char *port, *s; if (Port) { free(Port); @@ -275,13 +278,7 @@ int USBLCD_init (LCD *Self) if (USBLCD_open()!=0) return -1; - s=cfg_get("Icons", "0"); - Icons=strtol(s, &e, 0); - if (*e!='\0' || Icons<0 || Icons>8) { - debug ("Icons=%d e=<%s>", Icons, e); - error ("USBLCD: bad Icons '%s' in %s, must be between 0 and 8", s, cfg_source()); - return -1; - } + if (cfg_number("Icons", 0, 0, 8, &Icons)<0) return -1; if (Icons>0) { info ("reserving %d of %d user-defined characters for icons", Icons, CHARS); icon_init(Lcd.rows, Lcd.cols, XRES, YRES, CHARS, Icons, USBLCD_define_char); @@ -335,7 +332,6 @@ int USBLCD_flush (void) { int row, col, pos1, pos2; int c, equal; - static int junk=0; //Fixme bar_process(USBLCD_define_char); @@ -1,4 +1,4 @@ -/* $Id: XWindow.c,v 1.32 2003/07/24 04:48:09 reinelt Exp $ +/* $Id: XWindow.c,v 1.33 2003/09/09 06:54:43 reinelt Exp $ * * X11 Driver for LCD4Linux * @@ -20,6 +20,9 @@ * * * $Log: XWindow.c,v $ + * Revision 1.33 2003/09/09 06:54:43 reinelt + * new function 'cfg_number()' + * * Revision 1.32 2003/07/24 04:48:09 reinelt * 'soft clear' needed for virtual rows * @@ -414,7 +417,9 @@ int xlcdinit(LCD *Self) } if (rgap<0) rgap=pixel+pgap; if (cgap<0) cgap=pixel+pgap; - border=atoi(cfg_get("border","0")); + + if (cfg_number("border", 0, 0, 1000000, &border)<0) return -1; + rgbfg=cfg_get("foreground","#000000"); rgbbg=cfg_get("background","#80d000"); rgbhg=cfg_get("halfground","#70c000"); @@ -1,4 +1,4 @@ -/* $Id: cfg.c,v 1.15 2003/08/24 05:17:58 reinelt Exp $ +/* $Id: cfg.c,v 1.16 2003/09/09 06:54:43 reinelt Exp $ * * config file stuff * @@ -20,6 +20,9 @@ * * * $Log: cfg.c,v $ + * Revision 1.16 2003/09/09 06:54:43 reinelt + * new function 'cfg_number()' + * * Revision 1.15 2003/08/24 05:17:58 reinelt * liblcd4linux patch from Patrick Schemitz * @@ -128,12 +131,14 @@ #include "debug.h" #include "cfg.h" + typedef struct { char *key; char *val; int lock; } ENTRY; + static char *Config_File=NULL; static ENTRY *Config=NULL; static int nConfig=0; @@ -156,6 +161,7 @@ static char *strip (char *s, int strip_comments) return s; } + static char *dequote (char *string) { char *s=string; @@ -172,6 +178,7 @@ static char *dequote (char *string) return string; } + static void cfg_add (char *key, char *val, int lock) { int i; @@ -191,6 +198,7 @@ static void cfg_add (char *key, char *val, int lock) Config[i].lock=lock; } + int l4l_cfg_cmd (char *arg) { char *key, *val; @@ -209,6 +217,7 @@ int l4l_cfg_cmd (char *arg) return 0; } + char *l4l_cfg_get (char *key, char *defval) { int i; @@ -221,6 +230,38 @@ char *l4l_cfg_get (char *key, char *defval) return defval; } + +int l4l_cfg_number (char *key, int defval, int min, int max, int *value) +{ + + char *s, *e; + + s=cfg_get(key, NULL); + if (s==NULL) { + *value=defval; + return 0; + } + + *value=strtol(s, &e, 0); + if (*e!='\0') { + error ("bad %s entry '%s' in %s", key, s, cfg_source()); + return -1; + } + + if (*value<min) { + error ("bad %s value '%s' in %s, minimum is %d", key, s, cfg_source(), min); + return -1; + } + + if (*value>max) { + error ("bad %s value '%s' in %s, maximum is %d", key, s, cfg_source(), max); + return -1; + } + + return 0; +} + + static int check_cfg_source(char *file) { /* as passwords and commands are stored in the config file, @@ -261,6 +302,7 @@ static int check_cfg_source(char *file) return error; } + int l4l_cfg_init (char *file) { FILE *stream; @@ -306,6 +348,7 @@ int l4l_cfg_init (char *file) return 0; } + char *l4l_cfg_source (void) { if (Config_File) @@ -315,8 +358,9 @@ char *l4l_cfg_source (void) } -int (*cfg_init) (char *source) = l4l_cfg_init; -char *(*cfg_source) (void) = l4l_cfg_source; -int (*cfg_cmd) (char *arg) = l4l_cfg_cmd; -char *(*cfg_get) (char *key, char *defval) = l4l_cfg_get; - +int (*cfg_init) (char *source) = l4l_cfg_init; +char *(*cfg_source) (void) = l4l_cfg_source; +int (*cfg_cmd) (char *arg) = l4l_cfg_cmd; +char *(*cfg_get) (char *key, char *defval) = l4l_cfg_get; +int (*cfg_number) (char *key, int defval, + int min, int max, int *value) = l4l_cfg_number; @@ -1,4 +1,4 @@ -/* $Id: cfg.h,v 1.4 2003/08/24 05:17:58 reinelt Exp $ +/* $Id: cfg.h,v 1.5 2003/09/09 06:54:43 reinelt Exp $ * * config file stuff * @@ -20,6 +20,9 @@ * * * $Log: cfg.h,v $ + * Revision 1.5 2003/09/09 06:54:43 reinelt + * new function 'cfg_number()' + * * Revision 1.4 2003/08/24 05:17:58 reinelt * liblcd4linux patch from Patrick Schemitz * @@ -47,10 +50,14 @@ extern int (*cfg_init) (char *source); extern char *(*cfg_source) (void); extern int (*cfg_cmd) (char *arg); extern char *(*cfg_get) (char *key, char *defval); +extern int (*cfg_number) (char *key, int defval, + int min, int max, int *value); int l4l_cfg_init (char *file); char *l4l_cfg_source (void); int l4l_cfg_cmd (char *arg); char *l4l_cfg_get (char *key, char *defval); +int l4l_cfg_number (char *key, int defval, + int min, int max, int *value); #endif @@ -1,4 +1,4 @@ -/* $Id: filter.c,v 1.6 2003/02/22 07:53:10 reinelt Exp $ +/* $Id: filter.c,v 1.7 2003/09/09 06:54:43 reinelt Exp $ * * smooth and damp functions * @@ -20,6 +20,9 @@ * * * $Log: filter.c,v $ + * Revision 1.7 2003/09/09 06:54:43 reinelt + * new function 'cfg_number()' + * * Revision 1.6 2003/02/22 07:53:10 reinelt * cfg_get(key,defval) * @@ -138,9 +141,9 @@ double damp(char *name, double value) double max; int i, j; - if (tau==-1) - tau=atoi(cfg_get("tau","500")); - + if (tau==-1) + if (cfg_number("tau", 500, 0, 1000000, &tau)<0) tau=0.0; + if (tau==0.0) return value; diff --git a/lcd4linux.c b/lcd4linux.c index 400fdd0..a95d148 100644 --- a/lcd4linux.c +++ b/lcd4linux.c @@ -1,4 +1,4 @@ -/* $Id: lcd4linux.c,v 1.45 2003/09/09 05:30:34 reinelt Exp $ +/* $Id: lcd4linux.c,v 1.46 2003/09/09 06:54:43 reinelt Exp $ * * LCD4Linux * @@ -20,6 +20,9 @@ * * * $Log: lcd4linux.c,v $ + * Revision 1.46 2003/09/09 06:54:43 reinelt + * new function 'cfg_number()' + * * Revision 1.45 2003/09/09 05:30:34 reinelt * even more icons stuff * @@ -241,6 +244,7 @@ char *release="LCD4Linux " VERSION " (c) 2003 Michael Reinelt <reinelt@eunet.at>"; char **my_argv; +int tick; int got_signal=0; extern char* output; @@ -321,9 +325,7 @@ int main (int argc, char *argv[]) { char *cfg="/etc/lcd4linux.conf"; char *driver; - char *s, *e; int c; - int tick; int quiet=0; // save arguments for restart @@ -466,10 +468,7 @@ int main (int argc, char *argv[]) signal(SIGQUIT, handler); signal(SIGTERM, handler); - s=cfg_get("tick", "100"); - tick=strtol(s, &e, 0); - if (*e!='\0' || tick<0) { - error ("bad tick entry '%s' in %s", s, cfg_source()); + if (cfg_number("Tick", 100, 1, 1000000, &tick)<0) { pid_exit(PIDFILE); exit (1); } @@ -1,4 +1,4 @@ -/* $Id: parport.c,v 1.7 2003/08/24 05:17:58 reinelt Exp $ +/* $Id: parport.c,v 1.8 2003/09/09 06:54:43 reinelt Exp $ * * generic parallel port handling * @@ -20,6 +20,9 @@ * * * $Log: parport.c,v $ + * Revision 1.8 2003/09/09 06:54:43 reinelt + * new function 'cfg_number()' + * * Revision 1.7 2003/08/24 05:17:58 reinelt * liblcd4linux patch from Patrick Schemitz * @@ -143,17 +146,9 @@ static int PPfd=-1; int parport_open (void) { char *s, *e; - + #ifdef USE_OLD_UDELAY - s=cfg_get ("Delay",NULL); - if (s==NULL || *s=='\0') { - error ("parport: no 'Delay' entry in %s", cfg_source()); - return -1; - } - if ((loops_per_usec=strtol(s, &e, 0))==0 || *e!='\0') { - error ("parport: bad delay '%s' in %s", s, cfg_source()); - return -1; - } + if (cfg_number("Delay", 0, 1, 1000000000, &loops_per_usec)<0) return -1; #else udelay_init(); #endif diff --git a/processor.c b/processor.c index 67e1129..481c4eb 100644 --- a/processor.c +++ b/processor.c @@ -1,4 +1,4 @@ -/* $Id: processor.c,v 1.39 2003/09/09 05:30:34 reinelt Exp $ +/* $Id: processor.c,v 1.40 2003/09/09 06:54:43 reinelt Exp $ * * main data processing * @@ -20,6 +20,9 @@ * * * $Log: processor.c,v $ + * Revision 1.40 2003/09/09 06:54:43 reinelt + * new function 'cfg_number()' + * * Revision 1.39 2003/09/09 05:30:34 reinelt * even more icons stuff * @@ -769,29 +772,26 @@ void process_init (void) debug ("Display: %d rows, %d columns, %dx%d pixels, %d icons, %d GPOs", rows, cols, xres, yres, icons, gpos); - lines=atoi(cfg_get("Rows","1")); - if (lines<1) { - error ("bad 'Rows' entry in %s, ignoring.", cfg_source()); + if (cfg_number("Rows", 1, 1, 1000, &lines)<0) { lines=1; + error ("ignoring bad 'Rows' value and using '%d'", lines); } if (lines>ROWS) { error ("%d virtual rows exceeds limit, reducing to %d rows", lines, ROWS); lines=ROWS; } if (lines>rows) { - scroll=atoi(cfg_get("Scroll","1")); - if (scroll<1) { - error ("bad 'Scroll' entry in %s, ignoring and using '1'", cfg_source()); + if (cfg_number("Scroll", 1, 1, 1000, &scroll)<0) { scroll=1; + error ("ignoring bad 'Scroll' value and using '%d'", scroll); } if (scroll>rows) { error ("'Scroll' entry in %s is %d, > %d display rows.", cfg_source(), scroll, rows); error ("This may lead to unexpected results!"); } - turn=atoi(cfg_get("Turn","1000")); - if (turn<1) { - error ("bad 'Turn' entry in %s, ignoring and using '1000'", cfg_source()); - turn=1; + if (cfg_number("Turn", 1000, 1, 1000000, &turn)<0) { + turn=1000; + error ("ignoring bad 'Scroll' value and using '%d'", turn); } debug ("Virtual: %d rows, scroll %d lines every %d msec", lines, scroll, turn); } else { @@ -826,6 +826,9 @@ void process (void) char *txt; static int offset=0; + // Fixme: smooth has gone... + int smooth=0; + collect_data(); if (smooth==0 && Turn()) { |