From f73848014030f0fb62b4f9738e9192621fae1aa2 Mon Sep 17 00:00:00 2001 From: reinelt Date: Wed, 14 Feb 2001 07:40:16 +0000 Subject: [lcd4linux @ 2001-02-14 07:40:16 by reinelt] first (incomplete) GPO implementation git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@80 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- HD44780.c | 52 +++++++++++++++++++++++++++++++++++++++++++++------- MatrixOrbital.c | 37 +++++++++++++++++++++++++++++-------- display.c | 13 +++++++++---- display.h | 8 ++++++-- lcd4linux.c | 8 ++++++-- parser.c | 33 ++++++++++++++++++++++++++++++--- parser.h | 9 +++++++-- processor.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++------- 8 files changed, 178 insertions(+), 35 deletions(-) diff --git a/HD44780.c b/HD44780.c index e23865e..aea9a56 100644 --- a/HD44780.c +++ b/HD44780.c @@ -1,4 +1,4 @@ -/* $Id: HD44780.c,v 1.11 2001/02/13 12:43:24 reinelt Exp $ +/* $Id: HD44780.c,v 1.12 2001/02/14 07:40:16 reinelt Exp $ * * driver for display modules based on the HD44780 chip * @@ -20,6 +20,10 @@ * * * $Log: HD44780.c,v $ + * Revision 1.12 2001/02/14 07:40:16 reinelt + * + * first (incomplete) GPO implementation + * * Revision 1.11 2001/02/13 12:43:24 reinelt * * HD_gpo() was missing @@ -137,6 +141,7 @@ static unsigned short Port=0; static char Txt[4][40]; static BAR Bar[4][40]; +static int GPO=0; static int nSegment=2; static SEGMENT Segment[128] = {{ len1:0, len2:0, type:255, used:0, ascii:32 }, @@ -155,13 +160,24 @@ static void HD_write (char *string, int len, int delay) { while (len--) { outb (*string++, Port); // put data on DB1..DB8 - outb (0x00, Port+2); // set Enable = bit 0 invertet + outb (0x00, Port+2); // set Enable = bit 0 invertet udelay (1); - outb (0x01, Port+2); // clear Enable + outb (0x01, Port+2); // clear Enable udelay (delay); } } +static void HD_setGPO (int bits) +{ + if (Lcd.gpos>0) { + outb (bits, Port); // put data on DB1..DB8 + outb (0x05, Port+2); // set INIT = bit 2 invertet + udelay (1); + outb (0x03, Port+2); // clear INIT + udelay (1); + } +} + static int HD_open (void) { debug ("using port 0x%x", Port); @@ -177,7 +193,6 @@ static int HD_open (void) HD_command (0x08, 40); // Display off, cursor off, blink off HD_command (0x0c, 1640); // Display on, cursor off, blink off, wait 1.64 ms HD_command (0x06, 40); // curser moves to right, no shift - return 0; } @@ -361,13 +376,15 @@ int HD_clear (void) Bar[row][col].segment=-1; } } + GPO=0; + HD_setGPO (GPO); // All GPO's off HD_command (0x01, 1640); // clear display return 0; } int HD_init (LCD *Self) { - int rows=-1, cols=-1; + int rows=-1, cols=-1, gpos=-1; char *s, *e; s=cfg_get ("Port"); @@ -400,15 +417,25 @@ int HD_init (LCD *Self) return -1; } + s=cfg_get ("GPOs"); + if (s==NULL) { + gpos=0; + } + else if ((gpos=strtol(s, &e, 0))==0 || *e!='\0' || gpos<0 || gpos>8) { + error ("HD44780: bad GPOs '%s' in %s", s, cfg_file()); + return -1; + } + Self->rows=rows; Self->cols=cols; + Self->gpos=gpos; Lcd=*Self; - + if (HD_open()!=0) return -1; HD_clear(); - + return 0; } @@ -504,6 +531,14 @@ int HD_bar (int type, int row, int col, int max, int len1, int len2) int HD_gpo (int num, int val) { + if (num>=Lcd.gpos) + return -1; + + if (val) { + GPO |= 1<=Lcd.gpos) + return -1; + + if (val) { + GPO |= 1<rows; - if(cols) *cols=Lcd->cols; + if (cols) *cols=Lcd->cols; if (xres) *xres=Lcd->xres; if (yres) *yres=Lcd->yres; if (bars) *bars=Lcd->bars; + if (gpos) *gpos=Lcd->gpos; return 0; } diff --git a/display.h b/display.h index c4c74d6..bf9915f 100644 --- a/display.h +++ b/display.h @@ -1,4 +1,4 @@ -/* $Id: display.h,v 1.12 2001/02/13 09:00:13 reinelt Exp $ +/* $Id: display.h,v 1.13 2001/02/14 07:40:16 reinelt Exp $ * * framework for device drivers * @@ -20,6 +20,10 @@ * * * $Log: display.h,v $ + * Revision 1.13 2001/02/14 07:40:16 reinelt + * + * first (incomplete) GPO implementation + * * Revision 1.12 2001/02/13 09:00:13 reinelt * * prepared framework for GPO's (general purpose outputs) @@ -113,7 +117,7 @@ typedef struct { int lcd_list (void); int lcd_init (char *driver); -int lcd_query (int *rows, int *cols, int *xres, int *yres, int *bars); +int lcd_query (int *rows, int *cols, int *xres, int *yres, int *bars, int *gpos); int lcd_clear (void); int lcd_put (int row, int col, char *text); int lcd_bar (int type, int row, int col, int max, int len1, int len2); diff --git a/lcd4linux.c b/lcd4linux.c index de971eb..3bc0144 100644 --- a/lcd4linux.c +++ b/lcd4linux.c @@ -1,4 +1,4 @@ -/* $Id: lcd4linux.c,v 1.28 2000/10/25 08:10:48 reinelt Exp $ +/* $Id: lcd4linux.c,v 1.29 2001/02/14 07:40:16 reinelt Exp $ * * LCD4Linux * @@ -20,6 +20,10 @@ * * * $Log: lcd4linux.c,v $ + * Revision 1.29 2001/02/14 07:40:16 reinelt + * + * first (incomplete) GPO implementation + * * Revision 1.28 2000/10/25 08:10:48 reinelt * * added restart funnctionality @@ -204,7 +208,7 @@ int hello (void) "(c) M.Reinelt", NULL }; - lcd_query (&y, &x, NULL, NULL, NULL); + lcd_query (&y, &x, NULL, NULL, NULL, NULL); flag=0; for (i=0; line1[i]; i++) { diff --git a/parser.c b/parser.c index f9fd99d..35f1b70 100644 --- a/parser.c +++ b/parser.c @@ -1,4 +1,4 @@ -/* $Id: parser.c,v 1.7 2000/08/10 09:44:09 reinelt Exp $ +/* $Id: parser.c,v 1.8 2001/02/14 07:40:16 reinelt Exp $ * * row definition parser * @@ -20,6 +20,10 @@ * * * $Log: parser.c,v $ + * Revision 1.8 2001/02/14 07:40:16 reinelt + * + * first (incomplete) GPO implementation + * * Revision 1.7 2000/08/10 09:44:09 reinelt * * new debugging scheme: error(), info(), debug() @@ -63,11 +67,16 @@ /* * exported functions: * - * char *parse (char *string, int supported_bars, int usage[]) + * char *parse_row (char *string, int supported_bars, int usage[]) * converts a row definition from the config file * into the internal form using tokens * sets the array usage[token] to usage count * + * char parse_gpo (char *string, int usage[]) + * converts a GPO definition from the config file + * into the internal form using tokens + * sets the array usage[token] to usage count + * */ #include @@ -167,7 +176,7 @@ static TOKEN get_token (char *s, char **p, int bar, int usage[]) return -1; } -char *parse (char *string, int supported_bars, int usage[]) +char *parse_row (char *string, int supported_bars, int usage[]) { static char buffer[256]; char *s=string; @@ -254,3 +263,21 @@ char *parse (char *string, int supported_bars, int usage[]) *p='\0'; return buffer; } + +char parse_gpo (char *string, int usage[]) +{ + char *s=string; + TOKEN token=-1; + + if (*s=='%') { + if ((token=get_token (++s, &s, 0, usage))==-1) { + error ("WARNING: unknown token <%%%c> in <%s>", *s, string); + } + } + + if (*s!='\0') { + error ("WARNING: error while parsing <%s>", string); + } + + return token; +} diff --git a/parser.h b/parser.h index 948c676..fa6b4ac 100644 --- a/parser.h +++ b/parser.h @@ -1,4 +1,4 @@ -/* $Id: parser.h,v 1.5 2000/05/21 06:20:35 reinelt Exp $ +/* $Id: parser.h,v 1.6 2001/02/14 07:40:16 reinelt Exp $ * * row definition parser * @@ -20,6 +20,10 @@ * * * $Log: parser.h,v $ + * Revision 1.6 2001/02/14 07:40:16 reinelt + * + * first (incomplete) GPO implementation + * * Revision 1.5 2000/05/21 06:20:35 reinelt * * added ppp throughput @@ -70,6 +74,7 @@ typedef enum { C_GENERIC, C_MEM, C_LOAD, C_CPU, C_DISK, C_ETH, C_PPP, C_ISDN, C_SENSOR } CLASS; -char *parse (char *string, int supported_bars, int usage[]); +char *parse_row (char *string, int supported_bars, int usage[]); +char parse_gpo (char *string, int usage[]); #endif diff --git a/processor.c b/processor.c index 18eb22e..50a3acf 100644 --- a/processor.c +++ b/processor.c @@ -1,4 +1,4 @@ -/* $Id: processor.c,v 1.10 2001/02/13 09:00:13 reinelt Exp $ +/* $Id: processor.c,v 1.11 2001/02/14 07:40:16 reinelt Exp $ * * main data processing * @@ -20,6 +20,10 @@ * * * $Log: processor.c,v $ + * Revision 1.11 2001/02/14 07:40:16 reinelt + * + * first (incomplete) GPO implementation + * * Revision 1.10 2001/02/13 09:00:13 reinelt * * prepared framework for GPO's (general purpose outputs) @@ -97,9 +101,11 @@ #define ROWS 16 +#define GPOS 16 char *row[ROWS]; -int rows, cols, xres, yres, supported_bars; +char gpo[GPOS]; +int rows, cols, xres, yres, supported_bars, gpos; int token_usage[256]={0,}; struct { int total, used, free, shared, buffer, cache, avail; } ram; @@ -440,32 +446,65 @@ static char *process_row (int r) return buffer; } +static int process_gpo (int r) +{ + int token; + double val; + + token=(unsigned char)gpo[r]; + val=query(token); + + return (val > 0.0); +} + void process_init (void) { int i; load.overload=atof(cfg_get("overload")?:"2.0"); - lcd_query (&rows, &cols, &xres, &yres, &supported_bars); - debug ("%d rows, %d columns, %dx%d pixels", rows, cols, xres, yres); + + lcd_query (&rows, &cols, &xres, &yres, &supported_bars, &gpos); + if (rows>ROWS) { + error ("%d rows exceeds limit, reducing to %d rows", rows, ROWS); + rows=ROWS; + } + if (gpos>GPOS) { + error ("%d gpos exceeds limit, reducing to %d gpos", gpos, GPOS); + gpos=GPOS; + } + debug ("%d rows, %d columns, %dx%d pixels, %d GPOs", rows, cols, xres, yres, gpos); + for (i=1; i<=rows; i++) { char buffer[8], *p; snprintf (buffer, sizeof(buffer), "Row%d", i); p=cfg_get(buffer)?:""; debug ("%s: %s", buffer, p); - row[i]=strdup(parse(p, supported_bars, token_usage)); + row[i]=strdup(parse_row(p, supported_bars, token_usage)); + } + + for (i=1; i<=gpos; i++) { + char buffer[8], *p; + snprintf (buffer, sizeof(buffer), "GPO%d", i); + p=cfg_get(buffer)?:""; + debug ("%s: %s", buffer, p); + gpo[i]=parse_gpo(p, token_usage); } } void process (int smooth) { - int i; + int i, val; char *txt; - + collect_data(); for (i=1; i<=rows; i++) { txt=process_row (i); if (smooth==0) lcd_put (i, 1, txt); } + for (i=1; i<=gpos; i++) { + val=process_gpo (i); + lcd_gpo (i, val); + } lcd_flush(); } -- cgit v1.2.3