aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2000-03-06 06:04:06 +0000
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2000-03-06 06:04:06 +0000
commit164a0b9f9a7efe4c717b38b7b2c13b2e83b6bf66 (patch)
treec29227526b71f99f88185e9c6e9e6ae5b1cc6021
parent3d773c59e479921ea9acc1272798dec5a49e9de8 (diff)
downloadlcd4linux-164a0b9f9a7efe4c717b38b7b2c13b2e83b6bf66.tar.gz
[lcd4linux @ 2000-03-06 06:04:06 by reinelt]
minor cleanups git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@4 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
-rw-r--r--MatrixOrbital.c31
-rw-r--r--config.c73
-rw-r--r--config.h41
-rw-r--r--display.c32
-rw-r--r--display.h10
-rw-r--r--filter.c53
-rw-r--r--filter.h34
-rw-r--r--isdn.c38
-rw-r--r--isdn.h34
-rw-r--r--lcd2041.c12
-rw-r--r--lcd4linux.h5
-rw-r--r--system.c63
-rw-r--r--system.h34
13 files changed, 435 insertions, 25 deletions
diff --git a/MatrixOrbital.c b/MatrixOrbital.c
index 38c2d26..c5dc6a7 100644
--- a/MatrixOrbital.c
+++ b/MatrixOrbital.c
@@ -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;
}
diff --git a/config.c b/config.c
index c55d63c..0f30f11 100644
--- 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 "";
+}
diff --git a/config.h b/config.h
index b07adc6..953cc87 100644
--- 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
diff --git a/display.c b/display.c
index d154b67..50f926a 100644
--- 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");
diff --git a/display.h b/display.h
index 1f5d6e9..a87f15d 100644
--- 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
*
@@ -20,6 +20,10 @@
*
*
* $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 ***
*
@@ -35,14 +39,14 @@
#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);
diff --git a/filter.c b/filter.c
index f61a9ed..74ae3fd 100644
--- 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++) {
diff --git a/filter.h b/filter.h
index a3b44a4..0501b04 100644
--- 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 fab470a..eaecbc3 100644
--- 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 62f1979..2c9831b 100644
--- 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
diff --git a/lcd2041.c b/lcd2041.c
index 4987697..8abee97 100644
--- 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;
}
diff --git a/lcd4linux.h b/lcd4linux.h
index f7c91ae..ec9da8c 100644
--- a/lcd4linux.h
+++ b/lcd4linux.h
@@ -1,6 +1 @@
-extern int tick;
-extern int tack;
-extern int tau;
extern char *sensor;
-
-
diff --git a/system.c b/system.c
index 0d3679f..2289139 100644
--- 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>
diff --git a/system.h b/system.h
index d3e3e28..0726d6c 100644
--- 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