apm patch for kernel 2.2.12 (compute battery time left when bios didn't)

Franck SICARD (Franck.Sicard@miniruth.solsoft.fr)
Mon, 27 Sep 1999 14:42:32 +0200


hi,

at the end of this mail is a small patch to compute the time left of the
battery when the the bios don't do it, but report % of the battery.
(it look at the speed at wich the % of the battery reduce).
the time is computed in minutes.

Franck

----------------- patch ---------------

--- linux-2.2.12/arch/i386/kernel/apm.c Tue Sep 21 21:23:47 1999
+++ linux/arch/i386/kernel/apm.c Sun Sep 26 22:03:08 1999
@@ -90,6 +90,9 @@
* Use CONFIG_SMP instead of __SMP__
* Ignore BOUNCES for three seconds.
* Stephen Rothwell
+ * 1.10?:Added computing of possible time left for the battery
+ * when the bios return only the the % of the battery.
+ * Franck Sicard <Franck.Sicard@solsoft.fr>
*
* APM 1.1 Reference:
*
@@ -128,6 +131,7 @@
#include <linux/miscdevice.h>
#include <linux/apm_bios.h>
#include <linux/init.h>
+#include <linux/sched.h>

#include <asm/system.h>
#include <asm/uaccess.h>
@@ -1178,6 +1182,8 @@
return 0;
}

+static int compute_baterry_life(int battery_percentage);
+
int apm_get_info(char *buf, char **start, off_t fpos, int length, int dummy)
{
char * p;
@@ -1210,6 +1216,10 @@
time_units = dx & 0x7fff;
}
}
+ if ((percentage !=-1) && (time_units==-1)) {
+ time_units=compute_baterry_life(percentage);
+ units="min";
+ }
}
/* Arguments, with symbols from linux/apm_bios.h. Information is
from the Get Power Status (0x0a) call unless otherwise noted.
@@ -1472,4 +1482,37 @@
misc_register(&apm_device);

apm_enabled = 1;
+}
+
+/* compute time left battery for buggy
+ * APM Bios (=my gateway 3100)
+ */
+static int compute_baterry_life(int battery_percentage)
+{
+ static int old_battery_percentage=-1;
+ static int old_time=0;
+ int new_time;
+ static int time_left;
+
+ if (battery_percentage != old_battery_percentage) {
+ new_time=CURRENT_TIME;
+ if (old_battery_percentage == -1) {
+ /* first call */
+ time_left= -1;
+ } else {
+ /* computing the number of second for 1 % */
+ time_left = (new_time - old_time)/(battery_percentage-old_battery_percentage);
+ /* computing the time left */
+ if (time_left<0) {
+ time_left *=-battery_percentage;
+ } else {
+ time_left *= (100- battery_percentage);
+ }
+ }
+ time_left/=60 /* time left in minutes */;
+ old_battery_percentage = battery_percentage;
+ old_time=new_time;
+ //printk(KERN_INFO "apm: time left %d%% at %d = %ds\n",old_battery_percentage,old_time,time_left);
+ }
+ return time_left;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/