aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/apm/apm.c
diff options
context:
space:
mode:
authorHajimu UMEMOTO <ume@FreeBSD.org>2000-08-13 17:05:27 +0000
committerHajimu UMEMOTO <ume@FreeBSD.org>2000-08-13 17:05:27 +0000
commit8ad6d022cafc90588d202d93346e5f079b89b904 (patch)
tree42884a3497eb5804efd3c64c968e373cb835c2ad /usr.sbin/apm/apm.c
parent5734912a2489bba113213bddda75f8057a7556b1 (diff)
downloadsrc-8ad6d022cafc90588d202d93346e5f079b89b904.tar.gz
src-8ad6d022cafc90588d202d93346e5f079b89b904.zip
Add output of per battery information to apm(1).
New ioctl APMIO_GETPWSTATUS is introduced. Reviewed by: -mobile and -current folks (no objection)
Notes
Notes: svn path=/head/; revision=64615
Diffstat (limited to 'usr.sbin/apm/apm.c')
-rw-r--r--usr.sbin/apm/apm.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/usr.sbin/apm/apm.c b/usr.sbin/apm/apm.c
index 6f8e09e85586..6cfd86f474f1 100644
--- a/usr.sbin/apm/apm.c
+++ b/usr.sbin/apm/apm.c
@@ -198,8 +198,60 @@ print_all_info(int fd, apm_info_t aip, int bioscall_available)
printf("Number of batteries: ");
if (aip->ai_batteries == (u_int) -1)
printf("unknown\n");
- else
+ else {
+ int i;
+ struct apm_pwstatus aps;
+
printf("%d\n", aip->ai_batteries);
+ for (i = 0; i < aip->ai_batteries; ++i) {
+ bzero(&aps, sizeof(aps));
+ aps.ap_device = PMDV_BATT0 + i;
+ if (ioctl(fd, APMIO_GETPWSTATUS, &aps) == -1)
+ continue;
+ printf("Battery %d:\n", i);
+ printf("\tBattery status: ");
+ if (aps.ap_batt_flag != 255 &&
+ (aps.ap_batt_flag & APM_BATT_NOT_PRESENT)) {
+ printf("not present\n");
+ continue;
+ }
+ if (aps.ap_batt_stat == 255)
+ printf("unknown\n");
+ else if (aps.ap_batt_stat > 3)
+ printf("invalid value (0x%x)\n",
+ aps.ap_batt_stat);
+ else {
+ char *messages[] = { "high",
+ "low",
+ "critical",
+ "charging" };
+ printf("%s\n",
+ messages[aps.ap_batt_stat]);
+ }
+ printf("\tRemaining battery life: ");
+ if (aps.ap_batt_life == 255)
+ printf("unknown\n");
+ else if (aps.ap_batt_life <= 100)
+ printf("%d%%\n", aps.ap_batt_life);
+ else
+ printf("invalid value (0x%x)\n",
+ aps.ap_batt_life);
+ printf("\tRemaining battery time: ");
+ if (aps.ap_batt_time == -1)
+ printf("unknown\n");
+ else {
+ int t, h, m, s;
+
+ t = aps.ap_batt_time;
+ s = t % 60;
+ t /= 60;
+ m = t % 60;
+ t /= 60;
+ h = t;
+ printf("%2d:%02d:%02d\n", h, m, s);
+ }
+ }
+ }
}
if (bioscall_available) {