diff options
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | Makefile.in | 16 | ||||
-rw-r--r-- | README | 5 | ||||
-rw-r--r-- | Raster.c | 8 | ||||
-rw-r--r-- | TODO | 12 | ||||
-rw-r--r-- | battery.c | 111 | ||||
-rw-r--r-- | battery.h | 7 | ||||
-rw-r--r-- | lcd4linux.conf.sample | 7 | ||||
-rw-r--r-- | parser.c | 8 | ||||
-rw-r--r-- | parser.h | 10 | ||||
-rw-r--r-- | processor.c | 64 |
11 files changed, 228 insertions, 21 deletions
diff --git a/Makefile.am b/Makefile.am index 00f9462..ad090ce 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,6 +21,7 @@ system.c system.h \ isdn.c isdn.h \ mail.c mail.h \ seti.c seti.h \ +battery.c battery.h \ filter.c filter.h \ udelay.c udelay.h \ display.c display.h \ diff --git a/Makefile.in b/Makefile.in index 7ef71df..48acdae 100644 --- a/Makefile.in +++ b/Makefile.in @@ -76,7 +76,7 @@ lcd4linux_LDFLAGS = $(X_LIBS) lcd4linux_LDADD = @DRIVERS@ @DRVLIBS@ lcd4linux_DEPENDENCIES = @DRIVERS@ -lcd4linux_SOURCES = lcd4linux.c debug.c debug.h cfg.c cfg.h lock.c lock.h parser.c parser.h processor.c processor.h system.c system.h isdn.c isdn.h mail.c mail.h seti.c seti.h filter.c filter.h udelay.c udelay.h display.c display.h pixmap.c pixmap.h fontmap.c fontmap.h +lcd4linux_SOURCES = lcd4linux.c debug.c debug.h cfg.c cfg.h lock.c lock.h parser.c parser.h processor.c processor.h system.c system.h isdn.c isdn.h mail.c mail.h seti.c seti.h battery.c battery.h filter.c filter.h udelay.c udelay.h display.c display.h pixmap.c pixmap.h fontmap.c fontmap.h EXTRA_lcd4linux_SOURCES = BeckmannEgle.c Crystalfontz.c Crystalfontz.h HD44780.c MatrixOrbital.c PalmPilot.c PNG.c PPM.c SIN.c Skeleton.c XWindow.c @@ -99,8 +99,8 @@ X_LIBS = @X_LIBS@ X_EXTRA_LIBS = @X_EXTRA_LIBS@ X_PRE_LIBS = @X_PRE_LIBS@ lcd4linux_OBJECTS = lcd4linux.o debug.o cfg.o lock.o parser.o \ -processor.o system.o isdn.o mail.o seti.o filter.o udelay.o display.o \ -pixmap.o fontmap.o +processor.o system.o isdn.o mail.o seti.o battery.o filter.o udelay.o \ +display.o pixmap.o fontmap.o CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) @@ -115,11 +115,11 @@ TAR = tar GZIP_ENV = --best DEP_FILES = .deps/BeckmannEgle.P .deps/Crystalfontz.P .deps/HD44780.P \ .deps/MatrixOrbital.P .deps/PNG.P .deps/PPM.P .deps/PalmPilot.P \ -.deps/SIN.P .deps/Skeleton.P .deps/XWindow.P .deps/cfg.P .deps/debug.P \ -.deps/display.P .deps/filter.P .deps/fontmap.P .deps/isdn.P \ -.deps/lcd4linux.P .deps/lock.P .deps/mail.P .deps/parser.P \ -.deps/pixmap.P .deps/processor.P .deps/seti.P .deps/system.P \ -.deps/udelay.P +.deps/SIN.P .deps/Skeleton.P .deps/XWindow.P .deps/battery.P \ +.deps/cfg.P .deps/debug.P .deps/display.P .deps/filter.P \ +.deps/fontmap.P .deps/isdn.P .deps/lcd4linux.P .deps/lock.P \ +.deps/mail.P .deps/parser.P .deps/pixmap.P .deps/processor.P \ +.deps/seti.P .deps/system.P .deps/udelay.P SOURCES = $(lcd4linux_SOURCES) $(EXTRA_lcd4linux_SOURCES) OBJECTS = $(lcd4linux_OBJECTS) @@ -1,5 +1,5 @@ # -# $Id: README,v 1.11 2001/02/16 08:23:09 reinelt Exp $ +# $Id: README,v 1.12 2001/03/02 10:18:45 ltoetsch Exp $ # This is the README file for lcd4linux @@ -178,3 +178,6 @@ Tokens: 'tm', PPP bytes max (received, send) 's1', temperature of sensor 1 's2', temperature of sensor 2 (up to s9) + 'bp', battery percentage (APM by now) + 'bs', battery status ('=' = online, '+' = charging, '-' discharging) + 'bd', battery duration in s{econds}, m{ins}, h{ours} or d{ays} @@ -1,4 +1,4 @@ -/* $Id: Raster.c,v 1.14 2001/03/01 22:33:50 reinelt Exp $ +/* $Id: Raster.c,v 1.15 2001/03/02 10:18:03 ltoetsch Exp $ * * driver for raster formats * @@ -20,6 +20,9 @@ * * * $Log: Raster.c,v $ + * Revision 1.15 2001/03/02 10:18:03 ltoetsch + * added /proc/apm battery stat + * * Revision 1.14 2001/03/01 22:33:50 reinelt * * renamed Raster_flush() to PPM_flush() @@ -102,7 +105,8 @@ #include <sys/types.h> #include <sys/stat.h> #ifdef WITH_PNG -#include <gd/gd.h> +/* #include <gd/gd.h> */ +#include <gd.h> #endif #include "debug.h" @@ -4,8 +4,9 @@ ToDo-List / Wishlist for lcd4linux implement some sort of 'graphs', similar to bars, but with a time axis can be filled (made up of bars) or not (needs raster graphics) -2000-04-04 Michael Reinelt <reinelt@eunet.at> -write a driver for PNG. This should be the first step towards a WWW-driver. +// 2000-04-04 Michael Reinelt <reinelt@eunet.at> +// write a driver for PNG. This should be the first step towards a WWW-driver. +Done 2001-03-01 -lt. 2000-04-15 Thomas Skyt Jessen <thskyt@foni.net> show partition information (used, free, ...) @@ -30,6 +31,7 @@ accept data from external sources (fifo?) connect a LED to a spare pin of the parallel port and show if ISDN is online -2001-01-27 Axel Ehnert <axel@ehnert.net> -- display numer of emails in a mailbox -- display seti@home values +// 2001-01-27 Axel Ehnert <axel@ehnert.net> +// - display numer of emails in a mailbox +// - display seti@home values +done. diff --git a/battery.c b/battery.c new file mode 100644 index 0000000..a4a35e0 --- /dev/null +++ b/battery.c @@ -0,0 +1,111 @@ +/* + * battery.c interface to APM and (TODO:) ACPI + * + */ + +/* exported functions: + * + * int Battery (double *perc, int *status, double *lasting); + * returns: + * perc ... percentage of battery (0..100) + * status .. 0 (online), 1 (charging), 2 (discharging) + * lasting ... seconds, how long battery will last + * + */ +#include <stdlib.h> +#include <stdio.h> +#include <fcntl.h> +#include <ctype.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> +#include <sys/time.h> +#include <sys/stat.h> +#include <sys/types.h> + +#include "debug.h" + + +int Battery (int *perc, int *status, double *dur) +{ + static int fd = -2; + static int apm = 0; + + if (fd==-1) return -1; + + if (fd==-2) { + fd = open("/proc/apm", O_RDONLY | O_NDELAY); + if (fd==-1) { + error ("open(/proc/apm) failed: %s", strerror(errno)); + fd = open("/proc/acpi", O_RDONLY | O_NDELAY); /* FIXME */ + if (fd==-1) { + error ("open(/proc/acpi) failed: %s", strerror(errno)); + return -1; + } + debug ("open(/proc/acpi)=%d", fd); + } + else { + debug ("open(/proc/apm)=%d", fd); + apm = 1; + } + } + if (lseek(fd, 0L, SEEK_SET)!=0) { + error ("lseek(/proc/apm|acpi) failed: %s", strerror(errno)); + fd=-1; + return -1; + } + if (apm) { + int f3, f4; + char eh[4]; + char buffer[128]; + /* /usr/src/linux/arch/i386/kernel/apm.c : + p += sprintf(p, "%s %d.%d 0x%02x 0x%02x 0x%02x 0x%02x %d%% %d %s\n", + driver_version, + (apm_bios_info.version >> 8) & 0xff, + apm_bios_info.version & 0xff, + apm_bios_info.flags, + ac_line_status, + battery_status, + battery_flag, + percentage, + time_units, + units); + 3) AC line status + 0x00: Off-line + 0x01: On-line + 0x02: On backup power (BIOS >= 1.1 only) + 0xff: Unknown + 4) Battery status + 0x00: High + 0x01: Low + 0x02: Critical + 0x03: Charging + 0x04: Selected battery not present (BIOS >= 1.2 only) + 0xff: Unknown + */ + + if (read (fd, &buffer, sizeof(buffer)-1)==-1) { + error ("read(/proc/apm) failed: %s", strerror(errno)); + fd=-1; + return -1; + } + /* Ver v.v fl as bs bf perc tu u*/ + sscanf(buffer, "%*s %*s %*s %x %x %*s %d%% %lf %3s", &f3, &f4, perc, dur, eh); + if (f3 == 0x1) + *status = 0; /* Online */ + else + *status = 2; /* Offline = discharging */ + if (f4 == 0x3) + *status = 1; /* charging */ + eh[1] = '\0'; /* m | s */ + if (*eh == 'm') + *dur *= 60; +#ifdef DEBUG_BATT + info("perc=%d, f3=%x, f4=%x, stat=%d, dur=%lf", *perc,f3,f4, *status, *dur); +#endif + } + else { + /* FIXME: parse ACPI */ + } + return 0; +} diff --git a/battery.h b/battery.h new file mode 100644 index 0000000..023323c --- /dev/null +++ b/battery.h @@ -0,0 +1,7 @@ +#ifndef _BATTERY_H_ +#define _BATTERY_H_ + + +int Battery ( int *perc, int *stat, double *dur); + +#endif diff --git a/lcd4linux.conf.sample b/lcd4linux.conf.sample index 07c1b11..0032ff3 100644 --- a/lcd4linux.conf.sample +++ b/lcd4linux.conf.sample @@ -75,6 +75,13 @@ Tau 500 Overload 2.0 +# flash bp-Bar if below Battwarning +# I use Row6 "Bat%bp%bs%bd$r10bp+bp" +# which gives a nice flash effect +# default 10 + +Battwarning 10 + SetiDir /etc/setiathome Mailbox1 /var/spool/mail/michii @@ -1,4 +1,4 @@ -/* $Id: parser.c,v 1.10 2001/02/19 00:15:46 reinelt Exp $ +/* $Id: parser.c,v 1.11 2001/03/02 10:18:03 ltoetsch Exp $ * * row definition parser * @@ -20,6 +20,9 @@ * * * $Log: parser.c,v $ + * Revision 1.11 2001/03/02 10:18:03 ltoetsch + * added /proc/apm battery stat + * * Revision 1.10 2001/02/19 00:15:46 reinelt * * integrated mail and seti client @@ -145,6 +148,9 @@ static SYMTAB Symtab[] = {{ "%", T_PERCENT, C_GENERIC, 0 }, { "tm", T_PPP_MAX, C_PPP, 1 }, { "hc", T_SETI_PRC, C_SETI, 1 }, { "ht", T_SETI_CPU, C_SETI, 0 }, + { "bp", T_BATT_PERC, C_BATT, 1 }, + { "bs", T_BATT_STAT, C_BATT, 0 }, + { "bd", T_BATT_DUR, C_BATT, 0 }, { "e*", T_MAIL, C_MAIL, 0 }, { "s*", T_SENSOR, C_SENSOR, 1 }, { "", -1, 0 }}; @@ -1,4 +1,4 @@ -/* $Id: parser.h,v 1.8 2001/02/19 00:15:46 reinelt Exp $ +/* $Id: parser.h,v 1.9 2001/03/02 10:18:03 ltoetsch Exp $ * * row definition parser * @@ -20,6 +20,9 @@ * * * $Log: parser.h,v $ + * Revision 1.9 2001/03/02 10:18:03 ltoetsch + * added /proc/apm battery stat + * * Revision 1.8 2001/02/19 00:15:46 reinelt * * integrated mail and seti client @@ -76,13 +79,16 @@ typedef enum { T_PPP_RX, T_PPP_TX, T_PPP_TOTAL, T_PPP_MAX, T_ISDN_USED, T_ISDN_IN, T_ISDN_OUT, T_ISDN_TOTAL, T_ISDN_MAX, T_SETI_PRC, T_SETI_CPU, + T_BATT_PERC, T_BATT_STAT, T_BATT_DUR, T_EXTENDED, T_MAIL, T_SENSOR } TOKEN; typedef enum { - C_GENERIC, C_MEM, C_LOAD, C_CPU, C_DISK, C_ETH, C_PPP, C_ISDN, C_SETI, C_MAIL, C_SENSOR + C_GENERIC, C_MEM, C_LOAD, C_CPU, C_DISK, C_ETH, C_PPP, C_ISDN, C_SETI, + C_BATT, + C_MAIL, C_SENSOR } CLASS; char *parse_row (char *string, int supported_bars, int usage[]); diff --git a/processor.c b/processor.c index 0687fc6..aa320c6 100644 --- a/processor.c +++ b/processor.c @@ -1,4 +1,4 @@ -/* $Id: processor.c,v 1.14 2001/02/19 00:15:46 reinelt Exp $ +/* $Id: processor.c,v 1.15 2001/03/02 10:18:03 ltoetsch Exp $ * * main data processing * @@ -20,6 +20,9 @@ * * * $Log: processor.c,v $ + * Revision 1.15 2001/03/02 10:18:03 ltoetsch + * added /proc/apm battery stat + * * Revision 1.14 2001/02/19 00:15:46 reinelt * * integrated mail and seti client @@ -113,6 +116,7 @@ #include "display.h" #include "processor.h" #include "mail.h" +#include "battery.h" #include "seti.h" #define ROWS 16 @@ -130,6 +134,7 @@ struct { int read, write, total, max, peak; } disk; struct { int rx, tx, total, max, peak, bytes; } net; struct { int usage, in, out, total, max, peak; } isdn; struct { int rx, tx, total, max, peak; } ppp; +struct { int perc, stat; double dur; } batt; struct { double perc, cput; } seti; struct { int num; } mail[MAILBOXES]; struct { double val, min, max; } sensor[SENSORS]; @@ -215,6 +220,13 @@ static double query (int token) case T_SETI_CPU: return seti.cput; + case T_BATT_PERC: + return batt.perc; + case T_BATT_STAT: + return batt.stat; + case T_BATT_DUR: + return batt.dur; + case T_MAIL: return mail[(token>>8)-'0'].num; @@ -224,6 +236,7 @@ static double query (int token) return 0.0; } +/* return a value 0..1 */ static double query_bar (int token) { int i; @@ -275,7 +288,15 @@ static double query_bar (int token) case T_SETI_PRC: return value; - + + case T_BATT_PERC: + { + static int alarm; + alarm=(++alarm % 3); + if(value < atoi(cfg_get("battwarning")?:"10") && !alarm) /* flash bar */ + value = 0; + return value/100; + } case T_SENSOR: i=(token>>8)-'0'; return (value-sensor[i].min)/(sensor[i].max-sensor[i].min); @@ -374,6 +395,41 @@ static void print_token (int token, char **p) (int)((int)val%86400)/3600, (int)(((int)val%86400)%3600)/60 ); break; + + case T_BATT_PERC: + *p+=sprintf(*p, "%3.0f", query(token)); + break; + case T_BATT_STAT: + { int ival = (int) query(token); + switch (ival) { + case 0: **p = '='; break; + case 1: **p = '+'; break; + case 2: **p = '-'; break; + default: **p = '?'; break; + } + } + (*p)++; + break; + case T_BATT_DUR: + { + char eh = 's'; + val = query(token); + if (val > 99) { + val /= 60; + eh = 'm'; + } + if (val > 99) { + val /= 60; + eh = 'h'; + } + if (val > 99) { + val /= 24; + eh = 'd'; + } + *p+=sprintf(*p, "%2.0f%c", val, eh); + } + break; + case T_MAIL: val=query(token); *p+=sprintf (*p, "%3.0f", val); @@ -432,6 +488,10 @@ static void collect_data (void) if (token_usage[C_SETI]) { Seti (&seti.perc, &seti.cput); } + + if (token_usage[C_BATT]) { + Battery (&batt.perc, &batt.stat, &batt.dur); + } for (i=1; i<=MAILBOXES; i++) { if (token_usage[T_MAIL]&(1<<i)) { |