[Pkg-wmaker-commits] [wmbattery] 27/241: * Added support for querying for battery status via the sonypi driver, for sony laptops that do not have apm support. This is a stopgap until linux gets full ACPI support.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Mon Aug 24 23:37:24 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch master
in repository wmbattery.

commit 563397cf499c2e9ec13928c561dedca80f35e936
Author: joey <joey at a4a2c43b-8ac3-0310-8836-e0e880c912e2>
Date:   Fri Apr 5 00:39:44 2002 +0000

       * Added support for querying for battery status via the sonypi driver, for
         sony laptops that do not have apm support. This is a stopgap until linux
         gets full ACPI support.
---
 README           |   2 +
 TODO             |   4 --
 debian/changelog |   8 ++++
 debian/control   |   5 ++-
 debian/copyright |   2 +-
 wmbattery.1x     |  15 +++++--
 wmbattery.c      | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 7 files changed, 134 insertions(+), 19 deletions(-)

diff --git a/README b/README
index b9c506a..78cc246 100644
--- a/README
+++ b/README
@@ -15,6 +15,8 @@ some improvements in wmbattery:
   - It consumes a little less memory.
   - Uses only 10 colors.
   - You can run in on a different display via -d (broken in wmapm).
+  - Support for getting battery status from the sonypi driver instead of APM,
+    for some Sony laptops that do not have apm support.
 
 Conversely, here are some reasons to stick with wmapm:
 
diff --git a/TODO b/TODO
index 7d6bf1c..f807179 100644
--- a/TODO
+++ b/TODO
@@ -1,9 +1,5 @@
 * The dial doesn't fill up/drain out very prettily. Add some code to special
   case things so it looks better.
-* Can /proc/apm be kept open and rewound?
-  - Yes, it can -- libapm.a does this. I could use it in linux, though it
-    would increase executrable size some. Would be good though as I'd have
-    less code to maintain.
 * Make it load up the mask from file, not #include it.
 * Allow user-settable colors, like asclock does.
 * Allow the user to define when it should display different battery colors.
diff --git a/debian/changelog b/debian/changelog
index 97e70de..8a94a76 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,11 @@
+wmbattery (1.23) unstable; urgency=low
+
+  * Added support for querying for battery status via the sonypi driver, for
+    sony laptops that do not have apm support. This is a stopgap until linux
+    gets full ACPI support.
+
+ -- Joey Hess <joeyh at debian.org>  Thu,  4 Apr 2002 10:25:31 -0500
+
 wmbattery (1.22) unstable; urgency=low
 
   * Converted to use libapm, instead of the hacked up old version of it
diff --git a/debian/control b/debian/control
index 13fda7e..ff22d78 100644
--- a/debian/control
+++ b/debian/control
@@ -3,7 +3,7 @@ Section: x11
 Priority: extra
 Build-Depends: debhelper (>= 3), xlibs-dev, autoconf, libapm-dev
 Maintainer: Joey Hess <joeyh at debian.org>
-Standards-Version: 3.5.6.0
+Standards-Version: 3.5.6.1
 
 Package: wmbattery
 Architecture: any
@@ -21,4 +21,5 @@ Description: Display laptop battery info, dockable in WindowMaker
  .
  To use this program you need to enable APM support for your kernel during
  configuration; the corresponding questions are in the 'Character devices'
- section. It will only work on laptops with an APM BIOS.
+ section. It will only work on laptops with an APM BIOS and on Sony laptops
+ with the sonypi device.
diff --git a/debian/copyright b/debian/copyright
index 04da2f4..dd09bf9 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -1,4 +1,4 @@
-Wmbattery is copyright (C) 1998, 2001, 2002 by Joey Hess <joey at kitenet.net>
+Wmbattery is copyright (C) 1998-2002 by Joey Hess <joey at kitenet.net>
 
 Wmbattery uses code and images from the following sources:
 
diff --git a/wmbattery.1x b/wmbattery.1x
index 21fe1d4..577d409 100644
--- a/wmbattery.1x
+++ b/wmbattery.1x
@@ -1,4 +1,4 @@
-.TH WMBATTERY 1 "24 February 2001"
+.TH WMBATTERY 1 "04 April 2002"
 .SH NAME
 WMBATTERY \- Dockable APM/Battery Monitor
 .SH SYNOPSIS
@@ -7,13 +7,15 @@ WMBATTERY \- Dockable APM/Battery Monitor
 .SH DESCRIPTION
 .PP
 .B wmbattery
-is an APM/Battery Monitor.  It is used to visually display the
-APM/Battery status from the system's BIOS.
+is a battery monitor.  It is used to visually display the system's battery 
+status.
 .PP
 Currently,
 .B wmbattery
 is supported on Linux (where it reads APM information from /proc/apm),
-and Free/Net/OpenBSD (where it reads /dev/apm).
+and Free/Net/OpenBSD (where it reads /dev/apm). It also has special support
+for some Sony laptops that lack APM support, but do have a sonypi driver in
+linux that can report on the battery status.
 .B wmbattery
 is dockable using WindowMaker and AfterStep window-managers; under
 other window-managers
@@ -64,6 +66,11 @@ Use the designated X display.
 .TP
 .B \-g +x+y
 Specify geometry. This specifies position, not size.
+.TP
+.B \-s
+If APM cannot be initialized, don't give up, but instead use the sonypi driver
+and /dev/sonypi. This is useful on some Sony laptops that lack APM support.
+It is inferior to APM.
 .SH AUTHOR
 Joey Hess <joey at kitenet.net>, based on wmapm by
 Chris D. Faulhaber <jedgar at speck.ml.org>
diff --git a/wmbattery.c b/wmbattery.c
index 4dd7cac..310eabf 100644
--- a/wmbattery.c
+++ b/wmbattery.c
@@ -8,6 +8,10 @@
 #include <stdarg.h>
 #include <signal.h>
 #include <apm.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
 
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
@@ -15,6 +19,7 @@
 
 #include "wmbattery.h"
 #include "mask.xbm"
+#include "sonypi.h"
 
 Pixmap images[NUM_IMAGES];
 Window root, iconwin, win;
@@ -24,6 +29,10 @@ Display *display;
 GC NormalGC;
 int pos[2] = {0, 0};
 
+int try_sonypi = 0;
+int use_sonypi = 0;
+signed int spicfd = -1;
+
 void error(const char *fmt, ...) {
   	va_list arglist;
   
@@ -82,7 +91,7 @@ char *parse_commandline(int argc, char *argv[]) {
 	extern char *optarg;
 	
   	while (c != -1) {
-  		c=getopt(argc, argv, "hd:g:f:");
+  		c=getopt(argc, argv, "hd:g:f:s");
 		switch (c) {
 		  case 'h':
 			printf("\nUsage: wmbattery [options]\n");
@@ -106,6 +115,9 @@ char *parse_commandline(int argc, char *argv[]) {
                           }
                         }
                         break;
+		  case 's':
+			try_sonypi = 1;
+			break;
       		}
     	}
   
@@ -315,8 +327,8 @@ void recalc_window(apm_info cur_info) {
         	digit = min_left % 10;
         	draw_letter(digit,BIGFONT,MINUTES_ONES_OFFSET);
       	}
-
-      	/* Show percent remaining */
+      	
+	/* Show percent remaining */
       	if (cur_info.battery_percentage >= 0) {
         	digit = cur_info.battery_percentage / 10;
        		if (digit == 10) {
@@ -334,6 +346,11 @@ void recalc_window(apm_info cur_info) {
 	  	draw_letter(10,SMALLFONT,PERCENT_OFFSET);
 	  	draw_letter(10,BIGFONT,COLON_OFFSET);
 	}
+	
+	if (cur_info.battery_time < 0) {
+		/* TIme remaining is unknown, so dim the colon. */
+	  	draw_letter(10,BIGFONT,COLON_OFFSET);
+	}
 
 	redraw_window();
 }
@@ -341,9 +358,15 @@ void recalc_window(apm_info cur_info) {
 void alarmhandler(int sig) {
 	apm_info cur_info;
 	
-	if (apm_read(&cur_info) != 0)
-		error("Cannot read APM information.");
-	
+	if (! use_sonypi) {
+		if (apm_read(&cur_info) != 0)
+			error("Cannot read APM information.");
+	}
+	else {
+		if (sonypi_read(&cur_info) != 0)
+			error("Cannot read sonypi information.");
+	}
+		
 	/* If APM data changes redraw and wait for next update */
 	/* Always redraw if the status is critical, to make it blink. */
 	if (!apm_change(&cur_info) || cur_info.battery_status == 2)
@@ -352,12 +375,90 @@ void alarmhandler(int sig) {
 	alarm(DELAY);
 }
 
+inline int sonypi_ioctl(int ioctlno, void *param) {
+	if (ioctl(spicfd, ioctlno, param) < 0)
+		return 0;
+	return 1;
+}
+
+/* Read battery info from sonypi device and shove it into an apm_into
+ * struct. */
+int sonypi_read (apm_info *info) {
+	__u8 batflags;
+	__u16 cap, rem;
+	int havebatt = 0;
+	
+	info->using_minutes = info->battery_flags = 0;
+	
+	if (! sonypi_ioctl(SONYPI_IOCGBATFLAGS, &batflags)) {
+		return 1;
+	}
+
+	info->ac_line_status = (batflags & SONYPI_BFLAGS_AC) != 0;
+	if (batflags & SONYPI_BFLAGS_B1) {
+		if (! sonypi_ioctl(SONYPI_IOCGBAT1CAP, &cap))
+			return 1;
+		if (! sonypi_ioctl(SONYPI_IOCGBAT1REM, &rem))
+			return 1;
+		havebatt = 1;
+	}
+	else if (batflags & SONYPI_BFLAGS_B2) {
+		/* Not quite right, if there is a second battery I should
+		 * probably merge the two somehow.. */
+		if (! sonypi_ioctl(SONYPI_IOCGBAT2CAP, &cap))
+			return 1;
+		if (! sonypi_ioctl(SONYPI_IOCGBAT2REM, &rem))
+			return 1;
+		havebatt = 1;
+	}
+	else {
+		info->battery_percentage = 0;
+		info->battery_status = -1; /* no battery */
+	}
+	
+	if (havebatt) {
+		info->battery_percentage = 100 * rem / cap;
+		/* Guess at whether the battery is charging. */
+		if (info->battery_percentage < 99 && info->ac_line_status == 1) {
+			info->battery_flags = info->battery_flags | 8;
+			info->battery_status = 3; /* charging */
+		}
+		else {
+			/* Guess at battery status. */
+			if (info->battery_percentage > 10)
+				info->battery_status = 0; /* full */
+			else if (info->battery_percentage > 5)
+				info->battery_status = 1; /* medium */
+			else 
+				info->battery_status = 2; /* critical */
+		}
+	}
+	
+	/* Sadly, there is no way to estimate this. */
+	info->battery_time = -1;
+	
+	return 0;
+}
+
 int main(int argc, char *argv[]) {
 	make_window(parse_commandline(argc, argv), argc ,argv);
 
 	/*  Check for APM support (returns 0 on success). */
-	if (apm_exists() != 0)
-		error("No APM support in kernel.");
+	if (apm_exists() != 0) {
+		if (try_sonypi) {
+			/* Try to open the sonypi device. */
+			if ((spicfd = open("/dev/sonypi", O_RDWR)) == -1) {
+				error("Unable to open /dev/sonypi: %s",
+						strerror(errno));
+			}
+			else {
+				use_sonypi = 1;
+			}
+		}
+		else {
+			error("No APM support in kernel.");
+		}
+	}
 	
 	load_images();
 	

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmbattery.git



More information about the Pkg-wmaker-commits mailing list