From d8b69803cf31c24c72ed80a9c10863db5ae3a90a Mon Sep 17 00:00:00 2001 From: reinelt <> Date: Mon, 6 Mar 2000 06:04:06 +0000 Subject: [lcd4linux @ 2000-03-06 06:04:06 by reinelt] minor cleanups --- MatrixOrbital.c | 31 +++++++++++++++++++++++- config.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- config.h | 41 +++++++++++++++++++++++++++++--- display.c | 32 +++++++++++++++++++++++-- display.h | 10 +++++--- filter.c | 53 +++++++++++++++++++++++++++++++++++++++-- filter.h | 34 +++++++++++++++++++++++++++ isdn.c | 38 ++++++++++++++++++++++++++++++ isdn.h | 34 +++++++++++++++++++++++++++ lcd2041.c | 12 +++++----- lcd4linux.h | 5 ---- system.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ system.h | 34 +++++++++++++++++++++++++++ 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 #include +#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 #include #include @@ -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 #include @@ -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 #include #include #include #include -#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 #include #include 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 #include #include 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 -- cgit v1.2.3