[Pkg-wmaker-commits] [wmbattery] 54/241: * Another patch from Hugo Haas, this time it adds time-till-charged estimates for systems that lack them. The estimates are on by default, though they're only linear guesses and may not be accurate. * Display dimmed time estimate field if there is no estimate available. * -e switch renamed to -r and forces both estimates on.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Mon Aug 24 23:37:30 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 68a285ac359d94db7525803ddeb222cace551279
Author: joey <joey at a4a2c43b-8ac3-0310-8836-e0e880c912e2>
Date:   Thu Aug 7 21:15:29 2003 +0000

       * Another patch from Hugo Haas, this time it adds time-till-charged
         estimates for systems that lack them. The estimates are on by default,
         though they're only linear guesses and may not be accurate.
       * Display dimmed time estimate field if there is no estimate available.
       * -e switch renamed to -r and forces both estimates on.
---
 README           |  2 ++
 debian/changelog | 10 ++++++++
 debian/control   |  2 +-
 wmbattery.1x     |  8 +++---
 wmbattery.c      | 77 ++++++++++++++++++++++++++++++++++----------------------
 5 files changed, 64 insertions(+), 35 deletions(-)

diff --git a/README b/README
index 8947653..1779ee6 100644
--- a/README
+++ b/README
@@ -19,6 +19,8 @@ some improvements in wmbattery:
     for some Sony laptops that do not have apm support.
   - ACPI support, including multiple battery support and battery charging
     completion countdown timer.
+  - Can make its own estimatess of time remaining or time until full
+    charge, even if APM does not.
 
 Conversely, here are some reasons to stick with wmapm:
 
diff --git a/debian/changelog b/debian/changelog
index e379643..1b68b01 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,13 @@
+wmbattery (2.16) unstable; urgency=low
+
+  * Another patch from Hugo Haas, this time it adds time-till-charged
+    estimates for systems that lack them. The estimates are on by default,
+    though they're only linear guesses and may not be accurate.
+  * Display dimmed time estimate field if there is no estimate available.
+  * -e switch renamed to -r and forces both estimates on.
+
+ -- Joey Hess <joeyh at debian.org>  Thu,  7 Aug 2003 16:41:37 -0400
+
 wmbattery (2.15) unstable; urgency=low
 
   * Patch from Hugo Haas <hugo at larve.net> to change when the icon is
diff --git a/debian/control b/debian/control
index 8e3f9ac..4c71d91 100644
--- a/debian/control
+++ b/debian/control
@@ -20,4 +20,4 @@ Description: display laptop battery info, dockable in WindowMaker
  .
  wmbattery can use APM, ACPI, or even the SPIC that is in some Sony laptops.
  With ACPI, it supports multi-battery machines, and can estimate how long
- it will take the battery to finish charging.
+ it will take the battery to finish charging or discharging.
diff --git a/wmbattery.1x b/wmbattery.1x
index ec29afa..6089009 100644
--- a/wmbattery.1x
+++ b/wmbattery.1x
@@ -91,10 +91,10 @@ By default, this percentage is determined by APM or ACPI, and you shouldn't
 need to set it. If you set this, you should probably also set the -l
 switch.
 .TP
-.B \-r
+.B \-e
 wmbattery contains code for estimating the time remaining before discharge,
-and this code is used if no other source of this informaton is available.
-This switch makes wmbattery use its time remaining estimation code even
-if some other estimate of time remaining is available.
+and until full charge,and this code is used if no other source of this
+informaton is available. This switch makes wmbattery use its time 
+estimation code even if some other estimate is available.
 .SH AUTHOR
 Joey Hess <joey at kitenet.net>
diff --git a/wmbattery.c b/wmbattery.c
index a28a57c..def435c 100644
--- a/wmbattery.c
+++ b/wmbattery.c
@@ -81,47 +81,65 @@ void estimate_timeleft(apm_info *cur_info) {
 	static time_t prev_estimate = 0;
 	/* Percentage at the last estimate */
 	static short percent = 0;
+	/* Where we charging or discharging the last time we were called? */
+	static short was_charging = 1;
+	/* Have we made a guess lately? */
+	static short guessed_lately = 0;
 
 	time_t t;
 	int interval;
+	short is_charging = cur_info->battery_flags & BATTERY_FLAGS_CHARGING;
 
 	errno = 0;
 	if (time(&t) == ((time_t)-1) && errno != 0)
 		goto estim_values;
-	
-	/* No change: decrease estimate */
-	if (percent == cur_info->battery_percentage) {
-		estimate -= t - estimate_time;
+
+	if ((
+	     /* AC is on and battery is not charging anymore or ... */
+	     (cur_info->ac_line_status == AC_LINE_STATUS_ON) && !is_charging
+	     ) ||
+	    (
+	     /* ... the charging state has changed */
+	     is_charging ^ was_charging
+	     )) {
+		/* Reset counters */
+		battery_change_time = t;
+		estimate = -1;
+		guessed_lately = 0;
 		estimate_time = t;
-		if (estimate < 0)
-			estimate = 0;
+		prev_estimate = 0;
 		goto estim_values;
 	}
 
-	/* The battery was charged: reset counters */
-	if (percent < cur_info->battery_percentage) {
-		percent = cur_info->battery_percentage;
-		battery_change_time = t;
-		estimate = 0;
+	/* No change: decrease estimate */
+	if (percent == cur_info->battery_percentage) {
+		estimate -= t - estimate_time;
 		estimate_time = t;
-		prev_estimate = 0;
+		if (guessed_lately && estimate < 0)
+			estimate = 0;
 		goto estim_values;
 	}
 
-	/* The battery level decreased: calculate estimate based
-	 * on decrease speed and previous estimate */
+	/* The battery level changed: calculate estimate based
+	 * on change speed and previous estimate */
+	guessed_lately = 1;
 	estimate_time = t;
 	interval = estimate_time - battery_change_time;
 	prev_estimate = estimate;
 	battery_change_time = estimate_time;
-	estimate = cur_info->battery_percentage * interval 
-		   / (percent - cur_info->battery_percentage);
-	percent = cur_info->battery_percentage;
+	estimate = (is_charging
+		    ? (cur_info->battery_percentage - 100)
+		    : cur_info->battery_percentage)
+		* interval / (percent - cur_info->battery_percentage);
 	if (prev_estimate > 0)
 		estimate = (estimate * 2 + prev_estimate) / 3;
 
 estim_values:
+	percent = cur_info->battery_percentage;
+	was_charging = is_charging;
 	cur_info->battery_time = estimate;
+	if (estimate < 0)
+		estimate = 0;
 	cur_info->using_minutes = 0;
 }
 
@@ -150,7 +168,7 @@ char *parse_commandline(int argc, char *argv[]) {
 	extern char *optarg;
 	
   	while (c != -1) {
-  		c=getopt(argc, argv, "hd:g:f:b:w:c:l:r");
+  		c=getopt(argc, argv, "hd:g:f:b:w:c:l:e");
 		switch (c) {
 		  case 'h':
 			printf("Usage: wmbattery [options]\n");
@@ -161,7 +179,7 @@ char *parse_commandline(int argc, char *argv[]) {
 			printf("\t-w secs\t\tseconds between updates\n");
 			printf("\t-l percent\tlow percentage\n");
 			printf("\t-c percent\tcritical percentage\n");
-			printf("\t-r\t\testimate remaining time\n");
+			printf("\t-e\t\tuse own time estimates\n");
                		exit(0);
 		 	break;
 		  case 'd':
@@ -404,20 +422,22 @@ void recalc_window(apm_info cur_info) {
 	}
 
       	/* Show time left */
+
+	/* A negative number means that it is unknown. Dim the field. */
+	if (cur_info.battery_time < 0) {
+		draw_letter(10, BIGFONT, COLON_OFFSET);
+		redraw_window();
+		return;
+	}
+
         if (cur_info.using_minutes)
         	time_left = cur_info.battery_time;
         else
         	time_left = cur_info.battery_time / 60; 
-	if (time_left < 0)
-		time_left = time_left * -1;
         hour_left = time_left / 60;
         min_left = time_left % 60;
         digit = hour_left / 10;
-	if (cur_info.battery_time < 0)
-		/* Sacrifice a diget to display the minus sign. */
-		draw_letter(11, BIGFONT, HOURS_TENS_OFFSET);
-	else
-	        draw_letter(digit,BIGFONT,HOURS_TENS_OFFSET);
+	draw_letter(digit,BIGFONT,HOURS_TENS_OFFSET);
         digit = hour_left % 10;
 	draw_letter(digit,BIGFONT,HOURS_ONES_OFFSET);
        	digit = min_left / 10;
@@ -441,10 +461,7 @@ void alarmhandler(int sig) {
 		/* Apm uses negative numbers here to indicate error or
 		 * missing battery or something. */
 		if (cur_info.battery_time < 0) {
-			if (cur_info.ac_line_status == AC_LINE_STATUS_ON) {
-				cur_info.battery_time = 0;
-			}
-			else if (! always_estimate_remaining) {
+			if (! always_estimate_remaining) {
 				/* No battery life indicated; estimate it */
 				estimate_timeleft(&cur_info);
 			}

-- 
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