#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;
}
+/* $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>
char *val;
} ENTRY;
+static char *Config_File=NULL;
static ENTRY *Config=NULL;
static int nConfig=0;
+
static char *strip (char *s)
{
char *p;
return s;
}
-void set_cfg (char *key, char *val)
+
+void cfg_set (char *key, char *val)
{
int i;
Config[i].val=strdup(val);
}
-char *get_cfg (char *key)
+
+char *cfg_get (char *key)
{
int i;
}
-int read_cfg (char *file)
+int cfg_read (char *file)
{
FILE *stream;
char buffer[256];
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++) {
return 0;
}
+
+char *cfg_file (void)
+{
+ if (Config_File)
+ return Config_File;
+ else
+ return "";
+}
-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
+/* $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>
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);
}
}
}
}
void main (void) {
- int i, j;
lcd_init ("junk");
lcd_init ("LCD2041");
-/* $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);
+/* $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;
double *value;
} FILTER;
-#define SECONDS(x) (x.tv_sec+x.tv_usec/1000000.0)
double smooth(char *name, int period, double value)
{
return v/t;
}
+
double damp(char *name, double value)
{
static FILTER *Filter=NULL;
double max;
int i, j;
+ if (tau==0.0)
+ return value;
+
gettimeofday (&now, NULL);
for (i=0; i<nFilter; i++) {
+/* $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
+/* $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>
+/* $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
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;
}
-extern int tick;
-extern int tack;
-extern int tau;
extern char *sensor;
-
-
+/* $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>
+/* $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);
int Disk (int *r, int *w);
int Net (int *r, int *w);
double Temperature (void);
+
+#endif