[Pkg-wmaker-commits] [wmbattery] 53/241: * Patch from Hugo Haas <hugo at larve.net> to change when the icon is refreshed for less latency. * Patch from Hugo Haas to have wmbattery do its own time left estimates if that info is not available from the machine. * Add -r switch to force wmbattery to estimate the time left.
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 1a95f110896100a53f9954939b9a1a412aa54842
Author: joey <joey at a4a2c43b-8ac3-0310-8836-e0e880c912e2>
Date: Sun Aug 3 15:12:36 2003 +0000
* Patch from Hugo Haas <hugo at larve.net> to change when the icon is
refreshed for less latency.
* Patch from Hugo Haas to have wmbattery do its own time left estimates
if that info is not available from the machine.
* Add -r switch to force wmbattery to estimate the time left.
---
TODO | 1 +
debian/changelog | 10 +++++++
debian/copyright | 3 +-
wmbattery.1x | 8 +++++-
wmbattery.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++------
5 files changed, 99 insertions(+), 11 deletions(-)
diff --git a/TODO b/TODO
index 66ee2ee..2682e50 100644
--- a/TODO
+++ b/TODO
@@ -2,3 +2,4 @@
case things so it looks better.
* Make it load up the mask from file, not #include it.
* Allow user-settable colors, like asclock does.
+* Improve the battery lifetime estimation algo.
diff --git a/debian/changelog b/debian/changelog
index 9fc1adf..e379643 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,13 @@
+wmbattery (2.15) unstable; urgency=low
+
+ * Patch from Hugo Haas <hugo at larve.net> to change when the icon is
+ refreshed for less latency.
+ * Patch from Hugo Haas to have wmbattery do its own time left estimates
+ if that info is not available from the machine.
+ * Add -r switch to force wmbattery to estimate the time left.
+
+ -- Joey Hess <joeyh at debian.org> Sun, 3 Aug 2003 00:00:09 -0400
+
wmbattery (2.14) unstable; urgency=low
* Set the cutoff point for old acpi to 20020214 (was 20020208).
diff --git a/debian/copyright b/debian/copyright
index ca641b3..ced2802 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -1,4 +1,4 @@
-wmbattery is copyright (C) 1998-2002 by Joey Hess <joey at kitenet.net>
+wmbattery is copyright � 1998-2003 by Joey Hess <joey at kitenet.net>
wmbattery uses code and images from the following sources:
@@ -28,4 +28,3 @@ The following copyright applies to this package:
On Debian systems the complete text of the GPL is in
/usr/share/common-licenses/GPL
-
diff --git a/wmbattery.1x b/wmbattery.1x
index 1e7d418..ec29afa 100644
--- a/wmbattery.1x
+++ b/wmbattery.1x
@@ -1,4 +1,4 @@
-.TH WMBATTERY 1 "05 April 2002"
+.TH WMBATTERY 1
.SH NAME
wmbattery \- dockable battery monitor
.SH SYNOPSIS
@@ -90,5 +90,11 @@ Set the percentage at which the battery is considered to be critically low.
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
+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.
.SH AUTHOR
Joey Hess <joey at kitenet.net>
diff --git a/wmbattery.c b/wmbattery.c
index a8858bf..a28a57c 100644
--- a/wmbattery.c
+++ b/wmbattery.c
@@ -7,6 +7,8 @@
#include <X11/extensions/shape.h>
#include <stdarg.h>
#include <signal.h>
+#include <time.h>
+#include <errno.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
@@ -29,6 +31,7 @@ int battnum = 1;
int use_sonypi = 0;
int use_acpi = 0;
int delay = 0;
+int always_estimate_remaining = 0;
signed int low_pct = -1;
signed int critical_pct = -1;
@@ -66,6 +69,62 @@ int apm_change(apm_info *cur) {
return i;
}
+/* Calculate battery estimate */
+void estimate_timeleft(apm_info *cur_info) {
+ /* Time of the last estimate */
+ static time_t estimate_time = 0;
+ /* Estimated time left */
+ static time_t estimate = 0;
+ /* Time when we last noticed a battery level change */
+ static time_t battery_change_time = 0;
+ /* The previous estimation we had before the battery level changed */
+ static time_t prev_estimate = 0;
+ /* Percentage at the last estimate */
+ static short percent = 0;
+
+ time_t t;
+ int interval;
+
+ 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;
+ estimate_time = t;
+ if (estimate < 0)
+ 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;
+ estimate_time = t;
+ prev_estimate = 0;
+ goto estim_values;
+ }
+
+ /* The battery level decreased: calculate estimate based
+ * on decrease speed and previous estimate */
+ 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;
+ if (prev_estimate > 0)
+ estimate = (estimate * 2 + prev_estimate) / 3;
+
+estim_values:
+ cur_info->battery_time = estimate;
+ cur_info->using_minutes = 0;
+}
+
/* Load up the images this program uses. */
void load_images() {
int x;
@@ -91,7 +150,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:");
+ c=getopt(argc, argv, "hd:g:f:b:w:c:l:r");
switch (c) {
case 'h':
printf("Usage: wmbattery [options]\n");
@@ -102,6 +161,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");
exit(0);
break;
case 'd':
@@ -131,6 +191,8 @@ char *parse_commandline(int argc, char *argv[]) {
case 'c':
critical_pct = atoi(optarg);
break;
+ case 'r':
+ always_estimate_remaining = 1;
}
}
@@ -227,12 +289,12 @@ void flush_expose(Window w) {
}
void redraw_window() {
- flush_expose(iconwin);
XCopyArea(display, images[FACE], iconwin, NormalGC, 0, 0,
image_info[FACE].width, image_info[FACE].height, 0,0);
- flush_expose(win);
+ flush_expose(iconwin);
XCopyArea(display, images[FACE], win, NormalGC, 0, 0,
image_info[FACE].width, image_info[FACE].height, 0,0);
+ flush_expose(win);
}
/*
@@ -377,16 +439,26 @@ void alarmhandler(int sig) {
if (apm_read(&cur_info) != 0)
error("Cannot read APM information.");
/* Apm uses negative numbers here to indicate error or
- * missing battery or something. I use it for time
- * remaining in ACPI, so.. */
- if (cur_info.battery_time < 0)
- cur_info.battery_time = 0;
+ * 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) {
+ /* No battery life indicated; estimate it */
+ estimate_timeleft(&cur_info);
+ }
+ }
}
else {
if (sonypi_read(&cur_info) != 0)
error("Cannot read sonypi information.");
}
-
+
+ /* Always calculate remaining lifetime? */
+ if (always_estimate_remaining)
+ estimate_timeleft(&cur_info);
+
/* Override the battery status? */
if ((low_pct > -1 || critical_pct > -1) &&
cur_info.ac_line_status != AC_LINE_STATUS_ON) {
--
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