summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2010-08-24 18:07:59 +0000
committermav <mav@FreeBSD.org>2010-08-24 18:07:59 +0000
commit732e67582831b5dec821eba650989a312709e710 (patch)
treed5ef3f045ff1a6033fae195cc4cbdd4fe1a8c497 /usr.sbin
parente53e8421943f9039b5292b87288a893fa083cd4b (diff)
downloadFreeBSD-src-732e67582831b5dec821eba650989a312709e710.zip
FreeBSD-src-732e67582831b5dec821eba650989a312709e710.tar.gz
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.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/acpi/acpiconf/acpiconf.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/usr.sbin/acpi/acpiconf/acpiconf.c b/usr.sbin/acpi/acpiconf/acpiconf.c
index 87f1c76..5ca2f98 100644
--- a/usr.sbin/acpi/acpiconf/acpiconf.c
+++ b/usr.sbin/acpi/acpiconf/acpiconf.c
@@ -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);
}
OpenPOWER on IntegriCloud