]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2001-02-14 07:40:16 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Wed, 14 Feb 2001 07:40:16 +0000 (07:40 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Wed, 14 Feb 2001 07:40:16 +0000 (07:40 +0000)
first (incomplete) GPO implementation

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@80 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

HD44780.c
MatrixOrbital.c
display.c
display.h
lcd4linux.c
parser.c
parser.h
processor.c

index e23865ea71a944b7cc2a66d5da01ed1dd2af6dfe..aea9a56274dd6bfd551dadd8521dc98445695f7b 100644 (file)
--- 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
  *
  *
  *
  * $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;
 }
 
index cb23d92d6abd6c3e5523fa3678ae56b2460ba5a3..b2ae3e7d52df3a3fd7aaf69926cb50268fb44bda 100644 (file)
@@ -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
  *
  *
  *
  * $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 }
 };
index 497cf421ce5dc2ec1504fbf4e84794ec00b4089b..3c0e260e951539c0cb55fd3c8a6d6eed1c705b77 100644 (file)
--- a/display.c
+++ b/display.c
@@ -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
  *
  *
  *
  * $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)
  * 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;
 }
index c4c74d64dee40ac3d056c2d29d25838bf56be7e3..bf9915fcd4c451089a3dacb93bea52c37669e4db 100644 (file)
--- 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
  *
  *
  *
  * $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);
index de971eb4a65e712a1ff118b4d0b1f99608c63c2e..3bc0144d964d983f9a848adfdb06b950e1a1d2ee 100644 (file)
@@ -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
  *
  *
  *
  * $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++) {
index f9fd99d2e1b5d36f9540012d117de3034a0351ce..35f1b700d443784e14b65fb3e4c3471f27989130 100644 (file)
--- 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
  *
  *
  *
  * $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()
 /* 
  * 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;
+}
index 948c676eb04c44538e7966c27841b7d0430b601c..fa6b4ac7499cd1b5d7e079a4769e45a8f1bc343b 100644 (file)
--- 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
  *
  *
  *
  * $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
index 18eb22ec6b8d9947a10d6b455352892b0e157526..50a3acf6061ab50c25f234fb78f5c3897f38757f 100644 (file)
@@ -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
  *
  *
  *
  * $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)
 
 
 #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();
 }