[Pkg-wmaker-commits] [wmbattery] 60/241: * Use the proper new-style acpi string when looking for ac adaptor status. Closes: #220039 * Remove the hack I added for my old picturebook, as it causes bad results on systems that label a fully charged battery's charging rate as unknown and state as charging. * Base battery charge calculations for ACPI on design capacity, instead of last full capacity. Some batteries may exceed previous last full on their next charging, and this also lets you see when you have a damaged battery that is not fully charging. * If acpi battery charging state is unknown, but the rate is 0, then the battery is charged and on AC power, and the unknown state can be ignored. Analysis and patch by "TeXitoi".

Doug Torrance dtorrance-guest at moszumanska.debian.org
Mon Aug 24 23:37:32 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 0ace550ce98daa617905453b8d5d4ad0f6a566cf
Author: joey <joey at a4a2c43b-8ac3-0310-8836-e0e880c912e2>
Date:   Tue Nov 18 21:42:57 2003 +0000

       * Use the proper new-style acpi string when looking for ac adaptor status.
         Closes: #220039
       * Remove the hack I added for my old picturebook, as it causes bad results
         on systems that label a fully charged battery's charging rate as
         unknown and state as charging.
       * Base battery charge calculations for ACPI on design capacity, instead of
         last full capacity. Some batteries may exceed previous last full on
         their next charging, and this also lets you see when you have a damaged
         battery that is not fully charging.
       * If acpi battery charging state is unknown, but the rate is 0,
         then the battery is charged and on AC power, and the unknown state can
         be ignored. Analysis and patch by "TeXitoi".
---
 TODO   |  3 +++
 acpi.c | 36 +++++++++++++++++-------------------
 acpi.h |  4 ++--
 3 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/TODO b/TODO
index 2682e50..ced4b6e 100644
--- a/TODO
+++ b/TODO
@@ -3,3 +3,6 @@
 * Make it load up the mask from file, not #include it.
 * Allow user-settable colors, like asclock does.
 * Improve the battery lifetime estimation algo.
+* Break the ACPI code out into a proper standalone library (already 2 other
+  programs use it), preferably with a maintainer other than me, as I
+  currently have no ACPI devices.
diff --git a/acpi.c b/acpi.c
index 02e9af7..81d85f2 100644
--- a/acpi.c
+++ b/acpi.c
@@ -39,8 +39,7 @@ char *acpi_labels_old[] = {
 	"battery",
 	"ac_adapter",
 	"on-line",
-	"unknown",
-	"Last Full Capacity:",
+	"Design Capacity:",
 	"Present:",
 	"Remaining Capacity:",
 	"Present Rate:",
@@ -48,6 +47,7 @@ char *acpi_labels_old[] = {
 #if ACPI_THERMAL
 	"thermal",
 #endif
+	"Status:",
 	NULL
 };
 
@@ -59,8 +59,7 @@ char *acpi_labels_20020214[] = {
 	"battery",
 	"ac_adapter",
 	"on-line",
-	"unknown",
-	"last full capacity:",
+	"design capacity:",
 	"present:",
 	"remaining capacity:",
 	"present rate:",
@@ -68,6 +67,7 @@ char *acpi_labels_20020214[] = {
 #if ACPI_THERMAL
 	"thermal_zone",
 #endif
+	"state:",
 	NULL
 };
 
@@ -128,10 +128,10 @@ char *get_acpi_value (const char *file, const char *key) {
 	return scan_acpi_value(buf, key);
 }
 
-/* Returns the last full capacity of a battery. */
+/* Returns the design capacity of a battery. */
 int get_acpi_batt_capacity(int battery) {
 	int cap;
-	char *caps=get_acpi_value(acpi_batt_info[battery], acpi_labels[label_last_full_capacity]);
+	char *caps=get_acpi_value(acpi_batt_info[battery], acpi_labels[label_design_capacity]);
 	if (caps == NULL)
 		cap=0; /* battery not present */
 	else
@@ -220,7 +220,7 @@ int find_thermal(void) {
 int on_ac_power (void) {
 	int i;
 	for (i = 0; i < acpi_ac_count; i++) {
-		if (strcmp(acpi_labels[label_online], get_acpi_value(acpi_ac_adapter_status[i], "Status:")) == 0)
+		if (strcmp(acpi_labels[label_online], get_acpi_value(acpi_ac_adapter_status[i], acpi_labels[label_ac_state])) == 0)
 			return 1;
 		else
 			return 0;
@@ -304,17 +304,10 @@ int acpi_read (int battery, apm_info *info) {
 				/* Time remaining unknown. */
 				info->battery_time = 0;
 			}
-			/* This is a hack for my picturebook. If
-			 * the battery is not present, ACPI still
-			 * says it is Present, but sets this to
-			 * unknown. I don't know if this is the
-			 * correct way to do it. */
-			else if (strcmp(rate_s, acpi_labels[label_unknown]) == 0) {
-				goto NOBATT;
-			}
 			else {
-				/* a zero in the file; time unknown so use
-				 * a negative one to indicate this */
+				/* a zero or unknown in the file; time 
+				 * unknown so use a negative one to
+				 * indicate this */
 				info->battery_time = -1;
 			}
 		}
@@ -340,6 +333,12 @@ int acpi_read (int battery, apm_info *info) {
 			else if (state[0] == 'c') { /* not charging, so must be critical */
 				info->battery_status = BATTERY_STATUS_CRITICAL;
 			}
+			else if (rate == 0) {
+				/* if rate is null, battery charged, on
+				 * ac power */
+				info->battery_status = BATTERY_STATUS_HIGH;
+				info->ac_line_status = 1;
+			}
 			else {
 				fprintf(stderr, "unknown battery state: %s\n", state);
 			}
@@ -359,7 +358,7 @@ int acpi_read (int battery, apm_info *info) {
 		}
 		
 		if (pcap) {
-			/* percentage = (current_capacity / last_full_capacity) * 100 */
+			/* percentage = (current_capacity / max capacity) * 100 */
 			info->battery_percentage = (float) pcap / (float) acpi_batt_capacity[battery] * 100;
 		}
 		else {
@@ -368,7 +367,6 @@ int acpi_read (int battery, apm_info *info) {
 
 	}
 	else {
-NOBATT:
 		info->battery_percentage = 0;
 		info->battery_time = 0;
 		info->battery_status = BATTERY_STATUS_ABSENT;
diff --git a/acpi.h b/acpi.h
index 133a79a..ea42e74 100644
--- a/acpi.h
+++ b/acpi.h
@@ -50,8 +50,7 @@ enum acpi_labels_items {
 	label_battery,
 	label_ac_adapter,
 	label_online,
-	label_unknown,
-	label_last_full_capacity,
+	label_design_capacity,
 	label_present,
 	label_remaining_capacity,
 	label_present_rate,
@@ -59,6 +58,7 @@ enum acpi_labels_items {
 #if ACPI_THERMAL
 	label_thermal,
 #endif
+	label_ac_state,
 };
 
 /* This is set to point to a list of strings used for the given acpi

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