summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjkim <jkim@FreeBSD.org>2015-04-06 21:51:55 +0000
committerjkim <jkim@FreeBSD.org>2015-04-06 21:51:55 +0000
commit9435c121fa6dba0bbeae6c40cf3df7623095bf5e (patch)
tree5c71616c8d787e2cc593ee4bccffce112d7da977
parent7dd288fb201ab9da74f1b991a43256f098ef5308 (diff)
downloadFreeBSD-src-9435c121fa6dba0bbeae6c40cf3df7623095bf5e.zip
FreeBSD-src-9435c121fa6dba0bbeae6c40cf3df7623095bf5e.tar.gz
Tidy up battery status information. Remove a trailing white space.
PR: 193671
-rw-r--r--usr.sbin/acpi/acpiconf/acpiconf.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/usr.sbin/acpi/acpiconf/acpiconf.c b/usr.sbin/acpi/acpiconf/acpiconf.c
index 5ca2f98..1fab4b6 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
OpenPOWER on IntegriCloud