diff --git a/usr.sbin/acpi/acpiconf/acpiconf.c b/usr.sbin/acpi/acpiconf/acpiconf.c index 5ca2f98bdf3b..1fab4b68e11e 100644 --- a/usr.sbin/acpi/acpiconf/acpiconf.c +++ b/usr.sbin/acpi/acpiconf/acpiconf.c @@ -136,16 +136,30 @@ acpi_battinfo(int num) if (ioctl(acpifd, ACPIIO_BATT_GET_BATTINFO, &battio) == -1) err(EX_IOERR, "get battery user info (%d) failed", num); if (battio.battinfo.state != ACPI_BATT_STAT_NOT_PRESENT) { - printf("State:\t\t\t"); - if (battio.battinfo.state == 0) - printf("high "); - if (battio.battinfo.state & ACPI_BATT_STAT_CRITICAL) - printf("critical "); - if (battio.battinfo.state & ACPI_BATT_STAT_DISCHARG) - printf("discharging "); - if (battio.battinfo.state & ACPI_BATT_STAT_CHARGING) - printf("charging "); - printf("\n"); + const char *state; + switch (battio.battinfo.state & ACPI_BATT_STAT_BST_MASK) { + case 0: + state = "high"; + break; + case ACPI_BATT_STAT_DISCHARG: + state = "discharging"; + break; + case ACPI_BATT_STAT_CHARGING: + state = "charging"; + break; + case ACPI_BATT_STAT_CRITICAL: + state = "critical"; + break; + case ACPI_BATT_STAT_DISCHARG | ACPI_BATT_STAT_CRITICAL: + state = "critical discharging"; + break; + case ACPI_BATT_STAT_CHARGING | ACPI_BATT_STAT_CRITICAL: + state = "critical charging"; + break; + default: + state = "invalid"; + } + printf("State:\t\t\t%s\n", state); if (battio.battinfo.cap == -1) printf("Remaining capacity:\tunknown\n"); else