1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-01 08:27:59 +00:00

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.
This commit is contained in:
Alexander Motin 2010-08-24 18:07:59 +00:00
parent 694a0a8717
commit 9c1af42179
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=211763

View File

@ -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);
}