Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 Jul 2005 16:40:06 +0200 (CEST)
From:      Rudolf Cejka <cejkar@fit.vutbr.cz>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/83672: acpiconf with remaining battery life and time
Message-ID:  <200507181440.j6IEe6MU004308@kazi.fit.vutbr.cz>
Resent-Message-ID: <200507181440.j6IEeYC7031602@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         83672
>Category:       bin
>Synopsis:       acpiconf with remaining battery life and time
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 18 14:40:33 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Rudolf Cejka
>Release:        FreeBSD 5.3-STABLE i386
>Organization:
FIT, Brno University of Technology, Czech Republic
>Environment:
	Patches are for -current from 15 July 2005.
>Description:
	There are four patches:

	Patch #1: Just style fix, which renames deprecated
	ACPIIO_CMBAT_GET_B* to ACPIIO_BATT_GET_B*.

	Patch #2: Just another style fix, which changes some upper letters
	to the lower letters, so all lines are printed in the same style -
	with just first upper letter.

	Patch #3: This patch adds two lines in acpiconf -i0 output after
	Remaining capacity line, so that remaining energy is printed in
	three forms: capacity in mAh/mWh and newly in percentage and in
        time form, like apm did (so I can finally switch from apm to
        acpiconf :o).

	Patch #4: Consumption rate is in mA/mW, not in mAh/mWh, so this
	patch fixes the printed unit.

>How-To-Repeat:
>Fix:

Patch #1:

--- usr.sbin/acpi/acpiconf/acpiconf.c.orig	Sun Jul 17 16:07:57 2005
+++ usr.sbin/acpi/acpiconf/acpiconf.c	Sun Jul 17 16:11:30 2005
@@ -96,7 +96,7 @@
 		err(EX_USAGE, "invalid battery %d", num);
 
 	battio.unit = num;
-	if (ioctl(acpifd, ACPIIO_CMBAT_GET_BIF, &battio) == -1)
+	if (ioctl(acpifd, ACPIIO_BATT_GET_BIF, &battio) == -1)
 		err(EX_IOERR, "get battery info (%d) failed", num);
 	printf("Battery %d information\n", num);
 	if (battio.bif.units == 0)
@@ -129,7 +129,7 @@
 	printf("OEM info:\t\t%s\n", battio.bif.oeminfo);
 
 	battio.unit = num;
-	if (ioctl(acpifd, ACPIIO_CMBAT_GET_BST, &battio) == -1)
+	if (ioctl(acpifd, ACPIIO_BATT_GET_BST, &battio) == -1)
 		err(EX_IOERR, "get battery info (%d) failed", num);
 
 	if (battio.bst.state != ACPI_BATT_STAT_NOT_PRESENT) {

Patch #2:

--- usr.sbin/acpi/acpiconf/acpiconf.c.orig	Sun Jul 17 16:12:32 2005
+++ usr.sbin/acpi/acpiconf/acpiconf.c	Sun Jul 17 16:13:19 2005
@@ -142,14 +142,14 @@
 			printf("Charging");
 		printf("\n");
 		if (battio.bst.rate == UNKNOWN_CAP)
-			printf("Present Rate:\t\tUnknown\n");
+			printf("Present rate:\t\tUnknown\n");
 		else
-			printf("Present Rate:\t\t%d %s\n", battio.bst.rate,
+			printf("Present rate:\t\t%d %s\n", battio.bst.rate,
 			    pwr_units);
 		if (battio.bst.cap == UNKNOWN_CAP)
-			printf("Remaining Capacity:\tUnknown\n");
+			printf("Remaining capacity:\tUnknown\n");
 		else
-			printf("Remaining Capacity:\t%d %s\n", battio.bst.cap,
+			printf("Remaining capacity:\t%d %s\n", battio.bst.cap,
 			    pwr_units);
 		if (battio.bst.volt == UNKNOWN_CAP)
 			printf("Volt:\t\t\tUnknown\n");

Patch #3:

--- usr.sbin/acpi/acpiconf/acpiconf.c.orig	Sun Jul 17 16:13:52 2005
+++ usr.sbin/acpi/acpiconf/acpiconf.c	Sun Jul 17 16:32:49 2005
@@ -91,6 +91,8 @@
 {
 	union acpi_battery_ioctl_arg battio;
 	const char *pwr_units;
+	u_int32_t dcap;
+	int h, m, s;
 
 	if (num < 0 || num > 64)
 		err(EX_USAGE, "invalid battery %d", num);
@@ -108,6 +110,7 @@
 		printf("Design capacity:\tUnknown\n");
 	else
 		printf("Design capacity:\t%d %s\n", battio.bif.dcap, pwr_units);
+	dcap = battio.bif.dcap;
 	if (battio.bif.lfcap == UNKNOWN_CAP)
 		printf("Last full capacity:\tUnknown\n");
 	else
@@ -151,6 +154,22 @@
 		else
 			printf("Remaining capacity:\t%d %s\n", battio.bst.cap,
 			    pwr_units);
+		if (battio.bst.cap == UNKNOWN_CAP ||
+		    dcap == UNKNOWN_CAP || dcap == 0)
+			printf("Remaining life:\t\tUnknown\n");
+		else
+			printf("Remaining life:\t\t%.1f %%\n",
+			    100.0 * battio.bst.cap / dcap);
+		h = (battio.bst.state & ACPI_BATT_STAT_DISCHARG &&
+		    battio.bst.cap != UNKNOWN_CAP &&
+		    battio.bst.rate != UNKNOWN_CAP &&
+		    battio.bst.rate != 0) ?
+		    3600 * battio.bst.cap / battio.bst.rate : 0;
+		s = h % 60;
+		h /= 60;
+		m = h % 60;
+		h /= 60;
+		printf("Remaining time:\t\t%d:%02d:%02d\n", h, m, s);
 		if (battio.bst.volt == UNKNOWN_CAP)
 			printf("Volt:\t\t\tUnknown\n");
 		else

Patch #4:

--- usr.sbin/acpi/acpiconf/acpiconf.c.orig	Sun Jul 17 16:40:29 2005
+++ usr.sbin/acpi/acpiconf/acpiconf.c	Sun Jul 17 16:41:37 2005
@@ -90,7 +90,7 @@
 acpi_battinfo(int num)
 {
 	union acpi_battery_ioctl_arg battio;
-	const char *pwr_units;
+	const char *pwr_units, *pwr_units2;
 	u_int32_t dcap;
 	int h, m, s;
 
@@ -101,10 +101,13 @@
 	if (ioctl(acpifd, ACPIIO_BATT_GET_BIF, &battio) == -1)
 		err(EX_IOERR, "get battery info (%d) failed", num);
 	printf("Battery %d information\n", num);
-	if (battio.bif.units == 0)
+	if (battio.bif.units == 0) {
 		pwr_units = "mWh";
-	else
+		pwr_units2 = "mW";
+	} else {
 		pwr_units = "mAh";
+		pwr_units2 = "mA";
+	}
 
 	if (battio.bif.dcap == UNKNOWN_CAP)
 		printf("Design capacity:\tUnknown\n");
@@ -148,7 +151,7 @@
 			printf("Present rate:\t\tUnknown\n");
 		else
 			printf("Present rate:\t\t%d %s\n", battio.bst.rate,
-			    pwr_units);
+			    pwr_units2);
 		if (battio.bst.cap == UNKNOWN_CAP)
 			printf("Remaining capacity:\tUnknown\n");
 		else
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200507181440.j6IEe6MU004308>