svn commit: r211763 - head/usr.sbin/acpi/acpiconf
Alexander Motin
mav at FreeBSD.org
Tue Aug 24 18:08:00 UTC 2010
Author: mav
Date: Tue Aug 24 18:07:59 2010
New Revision: 211763
URL: http://svn.freebsd.org/changeset/base/211763
Log:
When ACPI reports current battery consumption rate in mAmps, print it also
in mWatts. Values in mAmps are not always suitable, because they depend on
battery voltage, which depends on battery type and charge level.
Modified:
head/usr.sbin/acpi/acpiconf/acpiconf.c
Modified: head/usr.sbin/acpi/acpiconf/acpiconf.c
==============================================================================
--- head/usr.sbin/acpi/acpiconf/acpiconf.c Tue Aug 24 17:48:22 2010 (r211762)
+++ head/usr.sbin/acpi/acpiconf/acpiconf.c Tue Aug 24 18:07:59 2010 (r211763)
@@ -86,7 +86,8 @@ acpi_battinfo(int num)
{
union acpi_battery_ioctl_arg battio;
const char *pwr_units;
- int hours, min;
+ int hours, min, amp;
+ uint32_t volt;
if (num < 0 || num > 64)
err(EX_USAGE, "invalid battery %d", num);
@@ -95,11 +96,8 @@ acpi_battinfo(int num)
battio.unit = num;
if (ioctl(acpifd, ACPIIO_BATT_GET_BIF, &battio) == -1)
err(EX_IOERR, "get battery info (%d) failed", num);
- if (battio.bif.units == 0)
- pwr_units = "mW";
- else
- pwr_units = "mA";
-
+ amp = battio.bif.units;
+ pwr_units = amp ? "mA" : "mW";
if (battio.bif.dcap == UNKNOWN_CAP)
printf("Design capacity:\tunknown\n");
else
@@ -125,6 +123,14 @@ acpi_battinfo(int num)
printf("Type:\t\t\t%s\n", battio.bif.type);
printf("OEM info:\t\t%s\n", battio.bif.oeminfo);
+ /* Fetch battery voltage information. */
+ volt = UNKNOWN_VOLTAGE;
+ battio.unit = num;
+ if (ioctl(acpifd, ACPIIO_BATT_GET_BST, &battio) == -1)
+ err(EX_IOERR, "get battery status (%d) failed", num);
+ if (battio.bst.state != ACPI_BATT_STAT_NOT_PRESENT)
+ volt = battio.bst.volt;
+
/* Print current battery state information. */
battio.unit = num;
if (ioctl(acpifd, ACPIIO_BATT_GET_BATTINFO, &battio) == -1)
@@ -154,22 +160,21 @@ acpi_battinfo(int num)
}
if (battio.battinfo.rate == -1)
printf("Present rate:\t\tunknown\n");
- else
+ else if (amp && volt != UNKNOWN_VOLTAGE) {
+ printf("Present rate:\t\t%d mA (%d mW)\n",
+ battio.battinfo.rate,
+ battio.battinfo.rate * volt / 1000);
+ } else
printf("Present rate:\t\t%d %s\n",
battio.battinfo.rate, pwr_units);
} else
printf("State:\t\t\tnot present\n");
/* Print battery voltage information. */
- battio.unit = num;
- if (ioctl(acpifd, ACPIIO_BATT_GET_BST, &battio) == -1)
- err(EX_IOERR, "get battery status (%d) failed", num);
- if (battio.bst.state != ACPI_BATT_STAT_NOT_PRESENT) {
- if (battio.bst.volt == UNKNOWN_VOLTAGE)
- printf("Voltage:\t\tunknown\n");
- else
- printf("Voltage:\t\t%d mV\n", battio.bst.volt);
- }
+ if (volt == UNKNOWN_VOLTAGE)
+ printf("Present voltage:\tunknown\n");
+ else
+ printf("Present voltage:\t%d mV\n", volt);
return (0);
}
More information about the svn-src-head
mailing list