diff options
| -rw-r--r-- | HD44780.c | 52 | ||||
| -rw-r--r-- | MatrixOrbital.c | 37 | ||||
| -rw-r--r-- | display.c | 13 | ||||
| -rw-r--r-- | display.h | 8 | ||||
| -rw-r--r-- | lcd4linux.c | 8 | ||||
| -rw-r--r-- | parser.c | 33 | ||||
| -rw-r--r-- | parser.h | 9 | ||||
| -rw-r--r-- | processor.c | 53 | 
8 files changed, 178 insertions, 35 deletions
| @@ -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<<num;     // set bit +  } else { +    GPO &= ~(1<<num);  // clear bit +  }    return 0;  } @@ -539,6 +574,9 @@ int HD_flush (void)        HD_write (buffer, p-buffer, 40);      }    } + +  HD_setGPO(GPO); +    return 0;  } diff --git a/MatrixOrbital.c b/MatrixOrbital.c index cb23d92..b2ae3e7 100644 --- a/MatrixOrbital.c +++ b/MatrixOrbital.c @@ -1,4 +1,4 @@ -/* $Id: MatrixOrbital.c,v 1.20 2001/02/13 09:00:13 reinelt Exp $ +/* $Id: MatrixOrbital.c,v 1.21 2001/02/14 07:40:16 reinelt Exp $   *   * driver for Matrix Orbital serial display modules   * @@ -20,6 +20,10 @@   *   *   * $Log: MatrixOrbital.c,v $ + * Revision 1.21  2001/02/14 07:40:16  reinelt + * + * first (incomplete) GPO implementation + *   * Revision 1.20  2001/02/13 09:00:13  reinelt   *   * prepared framework for GPO's (general purpose outputs) @@ -157,6 +161,7 @@ static int Device=-1;  static char Txt[4][40];  static BAR  Bar[4][40]; +static int  GPO;  static int nSegment=2;  static SEGMENT Segment[128] = {{ len1:0,   len2:0,   type:255, used:0, ascii:32 }, @@ -397,7 +402,9 @@ int MO_clear (void)        Bar[row][col].segment=-1;      }    } -  MO_write ("\014", 1); +  MO_write ("\014",  1);  // Clear Screen +  MO_write ("\376V", 2);  // GPO off +  GPO=0;    return 0;  } @@ -453,7 +460,6 @@ int MO_init (LCD *Self)    MO_write ("\376T", 2);  // blink off    MO_write ("\376D", 2);  // line wrapping off    MO_write ("\376R", 2);  // auto scroll off -  MO_write ("\376V", 2);  // GPO off    return 0;  } @@ -542,6 +548,14 @@ int MO_bar (int type, int row, int col, int max, int len1, int len2)  int MO_gpo (int num, int val)  { +  if (num>=Lcd.gpos)  +    return -1; + +  if (val) { +    GPO |= 1<<num;     // set bit +  } else { +    GPO &= ~(1<<num);  // clear bit +  }    return 0;  } @@ -578,6 +592,13 @@ int MO_flush (void)        MO_write (buffer, p-buffer);      }    } + +  if (GPO & 1) { +    MO_write ("\376W", 2);  // GPO on +  } else { +    MO_write ("\376V", 2);  // GPO off +  } +    return 0;  } @@ -590,10 +611,10 @@ int MO_quit (void)  }  LCD MatrixOrbital[] = { -  { "LCD0821",2, 8,XRES,YRES,BARS,0,MO_init,MO_clear,MO_put,MO_bar,MO_gpo,MO_flush,MO_quit }, -  { "LCD1621",2,16,XRES,YRES,BARS,0,MO_init,MO_clear,MO_put,MO_bar,MO_gpo,MO_flush,MO_quit }, -  { "LCD2021",2,20,XRES,YRES,BARS,0,MO_init,MO_clear,MO_put,MO_bar,MO_gpo,MO_flush,MO_quit }, -  { "LCD2041",4,20,XRES,YRES,BARS,0,MO_init,MO_clear,MO_put,MO_bar,MO_gpo,MO_flush,MO_quit }, -  { "LCD4021",2,40,XRES,YRES,BARS,0,MO_init,MO_clear,MO_put,MO_bar,MO_gpo,MO_flush,MO_quit }, +  { "LCD0821",2, 8,XRES,YRES,BARS,1,MO_init,MO_clear,MO_put,MO_bar,MO_gpo,MO_flush,MO_quit }, +  { "LCD1621",2,16,XRES,YRES,BARS,1,MO_init,MO_clear,MO_put,MO_bar,MO_gpo,MO_flush,MO_quit }, +  { "LCD2021",2,20,XRES,YRES,BARS,1,MO_init,MO_clear,MO_put,MO_bar,MO_gpo,MO_flush,MO_quit }, +  { "LCD2041",4,20,XRES,YRES,BARS,1,MO_init,MO_clear,MO_put,MO_bar,MO_gpo,MO_flush,MO_quit }, +  { "LCD4021",2,40,XRES,YRES,BARS,1,MO_init,MO_clear,MO_put,MO_bar,MO_gpo,MO_flush,MO_quit },    { NULL }  }; @@ -1,4 +1,4 @@ -/* $Id: display.c,v 1.22 2001/02/13 09:00:13 reinelt Exp $ +/* $Id: display.c,v 1.23 2001/02/14 07:40:16 reinelt Exp $   *   * framework for device drivers   * @@ -20,6 +20,10 @@   *   *   * $Log: display.c,v $ + * Revision 1.23  2001/02/14 07:40:16  reinelt + * + * first (incomplete) GPO implementation + *   * Revision 1.22  2001/02/13 09:00:13  reinelt   *   * prepared framework for GPO's (general purpose outputs) @@ -128,7 +132,7 @@   * lcd_init (char *driver)   *    initializes the named driver   * - * lcd_query (int *rows, int *cols, int *xres, int *yres, int *bars) + * lcd_query (int *rows, int *cols, int *xres, int *yres, int *bars, int *gpos)   *    queries the attributes of the selected driver   *   * lcd_clear () @@ -219,16 +223,17 @@ int lcd_init (char *driver)    return -1;  } -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)  {    if (Lcd==NULL)      return -1;    if (rows) *rows=Lcd->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;  } @@ -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++) { @@ -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 <stdlib.h> @@ -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; +} @@ -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();  } | 
