]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2000-03-06 06:04:06 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Mon, 6 Mar 2000 06:04:06 +0000 (06:04 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Mon, 6 Mar 2000 06:04:06 +0000 (06:04 +0000)
minor cleanups

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

13 files changed:
MatrixOrbital.c
config.c
config.h
display.c
display.h
filter.c
filter.h
isdn.c
isdn.h
lcd2041.c
lcd4linux.h
system.c
system.h

index 38c2d260cc454a2ab28197b35935e0309a4bed32..c5dc6a74406ec21f9c4bf562ce1fb911031fa3f8 100644 (file)
@@ -6,12 +6,41 @@
 #include <string.h>
 #include <errno.h>
 
+#include "config.h"
 #include "display.h"
 
+static DISPLAY Display;
+static char *Device=NULL;
 
-int MO_init (void)
+int MO_init (DISPLAY *Self)
 {
+  char *port;
+  
   printf ("initializing MatrixOrbital...\n");
+
+  if (Device) {
+    free (Device);
+    Device=NULL;
+  }
+
+  port=cfg_get ("port");
+  if (port==NULL || *port=='\0') {
+    fprintf (stderr, "MatrixOrbital: no 'port' entry in %s\n", cfg_file());
+    return -1;
+  }
+  Device=strdup(port);
+  
+  lcd=lcd_open();
+  if (lcd==-1) return -1;
+  
+  lcd_clear();
+  lcd_write ("\376B", 3);  // backlight on
+  lcd_write ("\376K", 2);  // cursor off
+  lcd_write ("\376T", 2);  // blink off
+  lcd_write ("\376D", 2);  // line wrapping off
+  lcd_write ("\376R", 2);  // auto scroll off
+  lcd_write ("\376V", 2);  // GPO off
+
   return 0;
 }
 
index c55d63ca87c8eb245348cb24e13014056f82cf3e..0f30f1139b34a3a90e120350336920013e4e9ea6 100644 (file)
--- a/config.c
+++ b/config.c
@@ -1,3 +1,54 @@
+/* $Id: config.c,v 1.2 2000/03/06 06:04:06 reinelt Exp $
+ *
+ * config file stuff
+ *
+ * Copyright 1999, 2000 by Michael Reinelt (reinelt@eunet.at)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Log: config.c,v $
+ * Revision 1.2  2000/03/06 06:04:06  reinelt
+ *
+ * minor cleanups
+ *
+ *
+ */
+
+/* 
+ * exported functions:
+ *
+ * cfg_set (key, value)
+ *   pre-set key's value
+ *   should be called before cfg_read()
+ *   so we can specify 'default values'
+ *
+ * cfg_get (key) 
+ *   return the a value for a given key 
+ *   or NULL if key does not exist
+ *
+ * cfg_read (file)
+ *   read configuration from file   
+ *   returns  0 if successful
+ *   returns -1 in case of an error
+ * 
+ * cfg_file (void)
+ *   returns the file the configuration was read from
+ * 
+ */
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -10,9 +61,11 @@ typedef struct {
   char *val;
 } ENTRY;
 
+static char  *Config_File=NULL;
 static ENTRY *Config=NULL;
 static int   nConfig=0;
 
+
 static char *strip (char *s)
 {
   char *p;
@@ -30,7 +83,8 @@ static char *strip (char *s)
   return s;
 }
 
-void set_cfg (char *key, char *val)
+
+void cfg_set (char *key, char *val)
 {
   int i;
   
@@ -47,7 +101,8 @@ void set_cfg (char *key, char *val)
   Config[i].val=strdup(val);
 }
 
-char *get_cfg (char *key)
+
+char *cfg_get (char *key)
 {
   int i;
 
@@ -60,7 +115,7 @@ char *get_cfg (char *key)
 }
 
 
-int read_cfg (char *file)
+int cfg_read (char *file)
 {
   FILE *stream;
   char buffer[256];
@@ -71,6 +126,10 @@ int read_cfg (char *file)
     fprintf (stderr, "open(%s) failed: %s\n", file, strerror(errno));
     return-1;
   }
+
+  if (Config_File) free (Config_File);
+  Config_File=strdup(file);
+    
   while ((line=fgets(buffer,256,stream))!=NULL) {
     if (*(line=strip(line))=='\0') continue;
     for (p=line; *p; p++) {
@@ -96,3 +155,11 @@ int read_cfg (char *file)
   return 0;
 }
 
+
+char *cfg_file (void)
+{
+  if (Config_File)
+    return Config_File;
+  else
+    return "";
+}
index b07adc6a7e27aff419c6a7e7fa10b59b93d9d1f5..953cc8732ad8ce47d301696d2161b5fb08e2c7fa 100644 (file)
--- a/config.h
+++ b/config.h
@@ -1,3 +1,38 @@
-int  read_cfg (char *file);
-char *get_cfg (char *key);
-void  set_cfg (char *key, char *value);
+/* $Id: config.h,v 1.2 2000/03/06 06:04:06 reinelt Exp $
+ *
+ * config file stuff
+ *
+ * Copyright 1999, 2000 by Michael Reinelt (reinelt@eunet.at)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Log: config.h,v $
+ * Revision 1.2  2000/03/06 06:04:06  reinelt
+ *
+ * minor cleanups
+ *
+ *
+ */
+
+#ifndef _CONFIG_H_
+#define _CONFIG_H_
+
+void  cfg_set (char *key, char *value);
+char *cfg_get (char *key);
+int   cfg_read (char *file);
+char *cfg_file (void);
+
+#endif
index d154b67c44be01ee04a45079091cd302fb48dc58..50f926a7e55ecf6854a89d59cfdfece5fa96d129 100644 (file)
--- a/display.c
+++ b/display.c
@@ -1,3 +1,32 @@
+/* $Id: display.c,v 1.2 2000/03/06 06:04:06 reinelt Exp $
+ *
+ * framework for device drivers
+ *
+ * Copyright 1999, 2000 by Michael Reinelt (reinelt@eunet.at)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Log: display.c,v $
+ * Revision 1.2  2000/03/06 06:04:06  reinelt
+ *
+ * minor cleanups
+ *
+ *
+ */
+
 #include <stdlib.h>
 #include <stdio.h>
 
@@ -20,7 +49,7 @@ int lcd_init (char *display)
     for (j=0; Driver[i].Display[j].name[0]; j++) {
       if (strcmp (Driver[i].Display[j].name, display)==0) {
        Display=&Driver[i].Display[j];
-       return Display->init();
+       return Display->init(Display);
       }
     }
   }
@@ -49,7 +78,6 @@ int lcd_flush (void)
 }
 
 void main (void) {
-  int i, j;
   
   lcd_init ("junk");
   lcd_init ("LCD2041");
index 1f5d6e9310562db59e6bad8f6556687941b245b3..a87f15d626842d301cd1a3581ee97a1ee52c380b 100644 (file)
--- a/display.h
+++ b/display.h
@@ -1,4 +1,4 @@
-/* $Id: display.h,v 1.2 2000/01/16 16:58:50 reinelt Exp $
+/* $Id: display.h,v 1.3 2000/03/06 06:04:06 reinelt Exp $
  *
  * framework for device drivers
  *
  *
  *
  * $Log: display.h,v $
+ * Revision 1.3  2000/03/06 06:04:06  reinelt
+ *
+ * minor cleanups
+ *
  * Revision 1.2  2000/01/16 16:58:50  reinelt
  * *** empty log message ***
  *
 #define BAR_D 8
 #define BAR_S 256
 
-typedef struct {
+typedef struct DISPLAY {
   char name[16];
   int rows;
   int cols;
   int xres;
   int yres;
   int bars;
-  int (*init) (void);
+  int (*init) (struct DISPLAY *Self);
   int (*clear) (void);
   int (*put) (int x, int y, char *text);
   int (*bar) (int type, int x, int y, int max, int len1, int len2);
index f61a9edfd74bbc18e4e04cbaf2565103fd4242b0..74ae3fdfda8ec16c6a933a2b506a131c7b34a038 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -1,13 +1,59 @@
+/* $Id: filter.c,v 1.2 2000/03/06 06:04:06 reinelt Exp $
+ *
+ *  smooth and damp functions
+ *
+ * Copyright 1999, 2000 by Michael Reinelt (reinelt@eunet.at)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Log: filter.c,v $
+ * Revision 1.2  2000/03/06 06:04:06  reinelt
+ *
+ * minor cleanups
+ *
+ *
+ */
+
+/* 
+ *
+ * exported fuctions:
+ *
+ * smooth (name, period, value)
+ *   returns an average value over a given period
+ *   uses global variable "tick"
+ *
+ * damp (name, value)
+ *   damps a value with exp(-t/tau) 
+ *   uses global variable "tau"
+ *
+ */
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <math.h>
 #include <sys/time.h>
 
-#include "lcd4linux.h"
 #include "filter.h"
 
+extern int tick;
+extern int tau;
+
 #define SLOTS 64
+#define SECONDS(x) (x.tv_sec+x.tv_usec/1000000.0)
 
 typedef struct {
   char *name;
@@ -16,7 +62,6 @@ typedef struct {
   double *value;
 } FILTER;
 
-#define SECONDS(x) (x.tv_sec+x.tv_usec/1000000.0)
 
 double smooth(char *name, int period, double value)
 {
@@ -68,6 +113,7 @@ double smooth(char *name, int period, double value)
     return v/t;
 }
 
+
 double damp(char *name, double value)
 {
   static FILTER *Filter=NULL;
@@ -76,6 +122,9 @@ double damp(char *name, double value)
   double max;
   int i, j;
   
+  if (tau==0.0)
+    return value;
+  
   gettimeofday (&now, NULL);
   
   for (i=0; i<nFilter; i++) {
index a3b44a473604c577ad266894fc8141a3c8b58d29..0501b04db12ebfd2ddf02e2475dce045db1c02d0 100644 (file)
--- a/filter.h
+++ b/filter.h
@@ -1,2 +1,36 @@
+/* $Id: filter.h,v 1.2 2000/03/06 06:04:06 reinelt Exp $
+ *
+ *  smooth and damp functions
+ *
+ * Copyright 1999, 2000 by Michael Reinelt (reinelt@eunet.at)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Log: filter.h,v $
+ * Revision 1.2  2000/03/06 06:04:06  reinelt
+ *
+ * minor cleanups
+ *
+ *
+ */
+
+#ifndef _FILTER_H_
+#define _FILTER_H_
+
 double smooth (char *name, int period, double value);
 double damp (char *name, double value);
+
+#endif
diff --git a/isdn.c b/isdn.c
index fab470ae8c1a8ae9fe5c92f668154779a70f3ed6..eaecbc359bf8c8962460a21949e72c3f5dc11677 100644 (file)
--- a/isdn.c
+++ b/isdn.c
@@ -1,3 +1,41 @@
+/* $Id: isdn.c,v 1.2 2000/03/06 06:04:06 reinelt Exp $
+ *
+ * ISDN specific functions
+ *
+ * Copyright 1999, 2000 by Michael Reinelt (reinelt@eunet.at)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Log: isdn.c,v $
+ * Revision 1.2  2000/03/06 06:04:06  reinelt
+ *
+ * minor cleanups
+ *
+ *
+ */
+
+/* 
+ * exported functions:
+ *
+ * Isdn (int *rx, int *tx)
+ *   returns all channel's USAGE or'ed together
+ *   sets received/transmitted bytes in *rx, *tx
+ *
+ */
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/isdn.h b/isdn.h
index 62f1979903c9e1757b15d2b6da565b88306adbc9..2c9831beb2523cceb08f785d7857aebca80e070e 100644 (file)
--- a/isdn.h
+++ b/isdn.h
@@ -1 +1,35 @@
+/* $Id: isdn.h,v 1.2 2000/03/06 06:04:06 reinelt Exp $
+ *
+ * ISDN specific functions
+ *
+ * Copyright 1999, 2000 by Michael Reinelt (reinelt@eunet.at)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Log: isdn.h,v $
+ * Revision 1.2  2000/03/06 06:04:06  reinelt
+ *
+ * minor cleanups
+ *
+ *
+ */
+
+#ifndef _ISDN_H_
+#define _ISDN_H_
+
 int Isdn (int *rx, int *tx);
+
+#endif
index 4987697ab0631519427a7d0c6a26de79570e8e40..8abee97766e5be58b2bc40c73ca08934b0b0cb4a 100644 (file)
--- a/lcd2041.c
+++ b/lcd2041.c
@@ -295,12 +295,12 @@ int lcd_init (char *device)
   if (lcd==-1) return -1;
   
   lcd_clear();
-  lcd_write ("\376B", 3); // backlight on
-  lcd_write ("\376K", 2);   // cursor off
-  lcd_write ("\376T", 2);   // blink off
-  lcd_write ("\376D", 2);   // line wrapping off
-  lcd_write ("\376R", 2);   // auto scroll off
-  lcd_write ("\376V", 2);   // GPO off
+  lcd_write ("\376B", 3);  // backlight on
+  lcd_write ("\376K", 2);  // cursor off
+  lcd_write ("\376T", 2);  // blink off
+  lcd_write ("\376D", 2);  // line wrapping off
+  lcd_write ("\376R", 2);  // auto scroll off
+  lcd_write ("\376V", 2);  // GPO off
 
   return 0;
 }
index f7c91ae4685196bd13816efccd60dbe09585fc9a..ec9da8cddc84f98cd025a51473364a6d4865e878 100644 (file)
@@ -1,6 +1 @@
-extern int tick;
-extern int tack;
-extern int tau;
 extern char *sensor;
-
-
index 0d3679ffe3e2a72a2911024a5ccf3dd938e11b1f..228913964b9b128c8120e96c143326cf872f5875 100644 (file)
--- a/system.c
+++ b/system.c
@@ -1,3 +1,66 @@
+/* $Id: system.c,v 1.2 2000/03/06 06:04:06 reinelt Exp $
+ *
+ * system status retreivement
+ *
+ * Copyright 1999, 2000 by Michael Reinelt (reinelt@eunet.at)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Log: system.c,v $
+ * Revision 1.2  2000/03/06 06:04:06  reinelt
+ *
+ * minor cleanups
+ *
+ *
+ */
+
+/* 
+ * exported functions:
+ *
+ * char *System (void);
+ *   returns OS name ('Linux')
+ *
+ * char *Release (void);
+ *   returns OS release ('2.0.38')
+ * 
+ * char *Processor (void);
+ *   returns processor type ('i686')
+ *
+ * int   Memory (void);
+ *   returns main memory (Megabytes)
+ *
+ * double Load (void);
+ *   returns load average
+ *
+ * double Busy (void);
+ *   returns CPU utilization
+ *
+ * int Disk (int *r, int *w);
+ *   returns disk utilization
+ *
+ * int Net (int *r, int *w);
+ *   returns network utilization
+ *
+ * double Temperature (void);
+ *   returns temperature 
+ *   a sensor must be specified with a 'temperature'-line  
+ *   in the config file
+ *
+ */
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
index d3e3e28d47f06fb4d6434b31293e0fc173b71bb0..0726d6cb7f9754d40618a8c43e4d783a98e2fc40 100644 (file)
--- a/system.h
+++ b/system.h
@@ -1,3 +1,35 @@
+/* $Id: system.h,v 1.2 2000/03/06 06:04:06 reinelt Exp $
+ *
+ * system status retreivement
+ *
+ * Copyright 1999, 2000 by Michael Reinelt (reinelt@eunet.at)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Log: system.h,v $
+ * Revision 1.2  2000/03/06 06:04:06  reinelt
+ *
+ * minor cleanups
+ *
+ *
+ */
+
+#ifndef _SYSTEM_H_
+#define _SYSTEM_H_
+
 char *System (void);
 char *Release (void);
 char *Processor (void);
@@ -7,3 +39,5 @@ double Busy (void);
 int Disk (int *r, int *w);
 int Net (int *r, int *w);
 double Temperature (void);
+
+#endif