summaryrefslogtreecommitdiff
path: root/sysutils
diff options
context:
space:
mode:
authorkivinen <kivinen>2004-06-09 21:00:05 +0000
committerkivinen <kivinen>2004-06-09 21:00:05 +0000
commitd419bd44736a8a90f478507b286bf7030390e7d1 (patch)
tree5251cd3eacd556d190f4df3285e7978d4235103a /sysutils
parent19e98b8b3d8f0bab658264c7586b51637516f169 (diff)
downloadpkgsrc-d419bd44736a8a90f478507b286bf7030390e7d1.tar.gz
Implemented support for envsys to get battery etc information
from acpi. Only tested on one laptop, I do not know whether the envsys names for the acpi devices are stable enough to be used, but I didn't find any other way to distinguish different things. As this laptop does not support apm, I hope it still works after these modifications.
Diffstat (limited to 'sysutils')
-rw-r--r--sysutils/asapm/Makefile3
-rw-r--r--sysutils/asapm/distinfo6
-rw-r--r--sysutils/asapm/patches/patch-ac31
-rw-r--r--sysutils/asapm/patches/patch-ad13
-rw-r--r--sysutils/asapm/patches/patch-ae25
-rw-r--r--sysutils/asapm/patches/patch-af178
6 files changed, 254 insertions, 2 deletions
diff --git a/sysutils/asapm/Makefile b/sysutils/asapm/Makefile
index 8f656ea8a34..46a15d062be 100644
--- a/sysutils/asapm/Makefile
+++ b/sysutils/asapm/Makefile
@@ -1,8 +1,9 @@
-# $NetBSD: Makefile,v 1.26 2004/04/25 03:21:16 snj Exp $
+# $NetBSD: Makefile,v 1.27 2004/06/09 21:00:05 kivinen Exp $
#
DISTNAME= asapm-2.11
CATEGORIES= sysutils x11
+PKGREVISION= 1
MASTER_SITES= http://www.tigr.net/afterstep/download/asapm/ \
ftp://ftp.afterstep.org/apps/asapm/ \
ftp://fuf.sh.cvut.cz/pub/AfterStep/apps/asapm/
diff --git a/sysutils/asapm/distinfo b/sysutils/asapm/distinfo
index a42572c346c..697e37a191c 100644
--- a/sysutils/asapm/distinfo
+++ b/sysutils/asapm/distinfo
@@ -1,6 +1,10 @@
-$NetBSD: distinfo,v 1.4 2001/11/26 19:55:40 wiz Exp $
+$NetBSD: distinfo,v 1.5 2004/06/09 21:00:05 kivinen Exp $
SHA1 (asapm-2.11.tar.gz) = cd89c5557d76dbb19ee565435b533ab48f05f102
Size (asapm-2.11.tar.gz) = 58729 bytes
SHA1 (patch-aa) = 570d2240f6afbf78d3cd72e1c1b963beb7ae074d
SHA1 (patch-ab) = 8796f1f6220ecdbd23d360bb18f721e1ef83febf
+SHA1 (patch-ac) = edfe7deae628b9e2aa57b67666f4e7dea13c19bf
+SHA1 (patch-ad) = f6a82aa2cff611f03e999a0773f8b47156b9550f
+SHA1 (patch-ae) = 28b0e4c446c466a90d4a2ae0952b2326385a8c6c
+SHA1 (patch-af) = 92a01d1079c62916cc6dd7fa069214f99045fd0a
diff --git a/sysutils/asapm/patches/patch-ac b/sysutils/asapm/patches/patch-ac
new file mode 100644
index 00000000000..bdac6c1472a
--- /dev/null
+++ b/sysutils/asapm/patches/patch-ac
@@ -0,0 +1,31 @@
+$NetBSD: patch-ac,v 1.3 2004/06/09 21:00:05 kivinen Exp $
+
+--- asapm.c.orig 2001-11-23 23:14:24.000000000 +0200
++++ asapm.c
+@@ -22,6 +22,7 @@
+ struct apm_state state;
+
+ char apm_device_file[256];
++char sysmon_device_file[256];
+
+ char statuscolor[50],
+ greencolor[50],
+@@ -52,6 +53,7 @@ char mainGeometry[50];
+ void defaults()
+ {
+ safecopy(apm_device_file, APM_PROC, 256);
++ safecopy(sysmon_device_file, SYSMON_DEV, 256);
+
+ /* I use RoyalBlue personally, but the author might not like me */
+ /* arbitrary aesthetic changes to his progam. ;) --Dagmar */
+@@ -178,6 +180,10 @@ void parsecmdline(int argc, char *arg
+ if (++i >= argc)
+ usage();
+ safecopy(apm_device_file, argv[i], 256);
++ } else if (!strncmp(argument,"-sysmondev",4)) {
++ if (++i >= argc)
++ usage();
++ safecopy(sysmon_device_file, argv[i], 256);
+ } else if (!strncmp(argument,"-fail",5)) {
+ state.fail=1;
+ } else if (!strncmp(argument,"-u",2)) {
diff --git a/sysutils/asapm/patches/patch-ad b/sysutils/asapm/patches/patch-ad
new file mode 100644
index 00000000000..28c92493607
--- /dev/null
+++ b/sysutils/asapm/patches/patch-ad
@@ -0,0 +1,13 @@
+$NetBSD: patch-ad,v 1.1 2004/06/09 21:00:05 kivinen Exp $
+
+--- state.h.orig 1999-03-09 12:35:24.000000000 +0200
++++ state.h
+@@ -13,6 +13,8 @@
+ /* file -> APM device */
+ #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+ #define APM_PROC "/dev/apm"
++#include <paths.h>
++#define SYSMON_DEV _PATH_SYSMON
+ #else
+ #define APM_PROC "/proc/apm"
+ #endif
diff --git a/sysutils/asapm/patches/patch-ae b/sysutils/asapm/patches/patch-ae
new file mode 100644
index 00000000000..b27022977b3
--- /dev/null
+++ b/sysutils/asapm/patches/patch-ae
@@ -0,0 +1,25 @@
+$NetBSD: patch-ae,v 1.1 2004/06/09 21:00:05 kivinen Exp $
+
+--- apm_rc.c.orig 1999-03-09 12:35:24.000000000 +0200
++++ apm_rc.c
+@@ -9,6 +9,7 @@ extern struct apm_state state;
+ #include "apm_react.h"
+
+ extern char apm_device_file[];
++extern char sysmon_device_file[];
+ extern char statuscolor[];
+ extern char greencolor[];
+ extern char yellowcolor[];
+@@ -93,6 +94,12 @@ void ReadFile( FILE * fd )
+ #ifdef DEBUG
+ printf("APM device = %s\n", apm_device_file);
+ #endif
++ } else if ( !strcasecmp("SysmonDevice", buffer) ) {
++ fgets( buffer, 256, fd );
++ safecopy( sysmon_device_file, Strip(buffer), 256 );
++#ifdef DEBUG
++ printf("Sysmon device = %s\n", sysmon_device_file);
++#endif
+ } else if ( !strcasecmp("Status", buffer) ) {
+ fgets( buffer, 256, fd );
+ safecopy( statuscolor, Strip(buffer), 50 );
diff --git a/sysutils/asapm/patches/patch-af b/sysutils/asapm/patches/patch-af
new file mode 100644
index 00000000000..f1eb73488fc
--- /dev/null
+++ b/sysutils/asapm/patches/patch-af
@@ -0,0 +1,178 @@
+$NetBSD: patch-af,v 1.1 2004/06/09 21:00:05 kivinen Exp $
+
+--- apm_read.c.orig 2001-11-23 23:07:19.000000000 +0200
++++ apm_read.c
+@@ -31,6 +31,7 @@
+
+ /* file -> APM device */
+ extern char apm_device_file[];
++extern char sysmon_device_file[];
+
+ #include "state.h"
+ extern struct apm_state state;
+@@ -136,18 +137,163 @@ void ReadAPMDevice( ) /* FreeBSD versio
+ state.time_left = info.ai_batt_time / 60;
+ }
+ #elif defined(__NetBSD__)||defined(__OpenBSD__)
++
++#include <sys/envsys.h>
++
++int match_end(const char *str, const char *end_part)
++{
++ int len1, len2;
++ len1 = strlen(str);
++ len2 = strlen(end_part);
++ if (len1 < len2)
++ return 0;
++ return strcmp(str + len1 - len2, end_part) == 0;
++}
++
++void TrySysmonDevice( )
++{
++ int fd;
++ int count = 0;
++ envsys_basic_info_t ebis;
++ envsys_tre_data_t etds;
++ int32_t design, charge, warn_cap, low_cap, rate;
++ int connected, percent, time_units, battery_status;
++
++ if ((fd = open(sysmon_device_file, O_RDONLY)) == -1) {
++ error_handle(1, "");
++ return;
++ }
++
++ design = 0;
++ charge = 0;
++ warn_cap = 0;
++ low_cap = 0;
++ rate = 0;
++ connected = 0;
++ percent = 0;
++ time_units = 0;
++
++ for(etds.sensor = 0; ; etds.sensor++) {
++ if (ioctl(fd, ENVSYS_GTREDATA, &etds) == -1) {
++ error_handle(4, "");
++ close(fd);
++ return;
++ }
++ if (!(etds.validflags & ENVSYS_FVALID))
++ break;
++
++ ebis.sensor = etds.sensor;
++ if (ioctl(fd, ENVSYS_GTREINFO, &ebis) == -1) {
++ error_handle(4, "");
++ close(fd);
++ return;
++ }
++
++ if (etds.units != ebis.units) {
++ error_handle(6, "units does not match");
++ }
++
++ if (!(etds.validflags & ENVSYS_FCURVALID))
++ continue;
++
++ if (etds.units == ENVSYS_SWATTHOUR) {
++ /* Watt hours, this must be battery capacity info. */
++ if (match_end(ebis.desc, "design cap")) {
++ design += etds.cur.data_s;
++ } else if (match_end(ebis.desc, "charge")) {
++ charge += etds.cur.data_s;
++ } else if (match_end(ebis.desc, "warn cap")) {
++ warn_cap += etds.cur.data_s;
++ } else if (match_end(ebis.desc, "low cap")) {
++ low_cap += etds.cur.data_s;
++ }
++ } else if (etds.units == ENVSYS_INDICATOR) {
++ /* Indicator of something, check for connected. */
++ if (match_end(ebis.desc, " connected")) {
++ connected = etds.cur.data_us;
++ }
++ } else if (etds.units == ENVSYS_SWATTS) {
++ /* Watts, this must discharge rate. */
++ if (match_end(ebis.desc, "discharge rate")) {
++ rate += etds.cur.data_s;
++ }
++ }
++ }
++
++ if (state.ac_line_status != connected) {
++ state.ac_line_status = connected ? AC_BATTERY : AC_ONLINE;
++ ++state.update;
++ if ( state.ac_line_status == AC_ONLINE )
++ state.flags |= CHANGE_AC_ON;
++ else
++ state.flags |= CHANGE_AC_OFF;
++ }
++ if (connected) {
++ if (charge > design) {
++ battery_status = BATTERY_HIGH;
++ } else {
++ battery_status = BATTERY_CHARGING;
++ }
++ } else {
++ if (charge > warn_cap) {
++ battery_status = BATTERY_HIGH;
++ } else if (charge > low_cap) {
++ battery_status = BATTERY_LOW;
++ } else {
++ battery_status = BATTERY_CRITICAL;
++ }
++ }
++
++ if (state.battery_status != battery_status) {
++ state.battery_status = battery_status;
++ ++state.update;
++ }
++
++ if (design != 0) {
++ percent = charge / (design / 100);
++ if (percent > 100) {
++ percent = 100;
++ }
++ else if (percent < 0) {
++ percent = 0;
++ }
++ }
++ if (state.percent != percent) {
++ if ( state.percent < percent )
++ state.flags |= CHANGE_POWER_UP;
++ else
++ state.flags |= CHANGE_POWER_DOWN;
++ state.percent = percent;
++ ++state.update;
++ }
++
++ if (rate != 0) {
++ time_units = charge / (rate / 60);
++ }
++
++ /* we can display maximum 99:59 */
++ if ( time_units > 5999 )
++ time_units = 5999;
++ if (state.time_left != time_units) {
++ state.time_left = time_units;
++ ++state.update;
++ }
++ close(fd);
++ return;
++}
++
+ void ReadAPMDevice( ) /* NetBSD version */
+ {
+ int fd;
+ struct apm_power_info info;
+ memset(&info, 0, sizeof(info));
+ if ((fd = open(apm_device_file, O_RDONLY)) == -1) {
+- error_handle(1, "");
++ TrySysmonDevice();
+ return;
+ }
+ if (ioctl(fd, APM_IOC_GETPOWER, &info) == -1) {
+- error_handle(4, "");
+ close(fd);
++ TrySysmonDevice();
+ return;
+ }
+ close(fd);