summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authornjl <njl@FreeBSD.org>2003-09-13 20:13:01 +0000
committernjl <njl@FreeBSD.org>2003-09-13 20:13:01 +0000
commit31d2c70e5eccca6481c953a49858a632a10d7ee0 (patch)
tree348ee2e81978b81e73d170abeabcaaa99a2d993b /usr.sbin
parentb182e8a6eb2eeed761202acafe91126d5d875c95 (diff)
downloadFreeBSD-src-31d2c70e5eccca6481c953a49858a632a10d7ee0.zip
FreeBSD-src-31d2c70e5eccca6481c953a49858a632a10d7ee0.tar.gz
Add the -i flag to acpiconf(8) to retrieve battery information.
Rename a few structure elements.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/acpi/acpiconf/acpiconf.83
-rw-r--r--usr.sbin/acpi/acpiconf/acpiconf.c95
2 files changed, 69 insertions, 29 deletions
diff --git a/usr.sbin/acpi/acpiconf/acpiconf.8 b/usr.sbin/acpi/acpiconf/acpiconf.8
index 373e6d4..47f90c8 100644
--- a/usr.sbin/acpi/acpiconf/acpiconf.8
+++ b/usr.sbin/acpi/acpiconf/acpiconf.8
@@ -36,6 +36,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl deh
+.Op Fl i Ar batt
.Op Fl s Ar type
.Sh DESCRIPTION
The
@@ -50,6 +51,8 @@ Disables ACPI power management.
Enables ACPI power management.
.It Fl h
Displays a summary of available options.
+.It Fl i Ar batt
+Get design information about the specified battery.
.It Fl s Ar type
Enters the specified sleep mode.
Recognized types are
diff --git a/usr.sbin/acpi/acpiconf/acpiconf.c b/usr.sbin/acpi/acpiconf/acpiconf.c
index 86cc655..9be6ad8 100644
--- a/usr.sbin/acpi/acpiconf/acpiconf.c
+++ b/usr.sbin/acpi/acpiconf/acpiconf.c
@@ -42,22 +42,25 @@
#define ACPIDEV "/dev/acpi"
+static int acpifd;
+
static int
-acpi_enable_disable(int enable)
+acpi_init()
{
- int fd;
-
- fd = open(ACPIDEV, O_RDWR);
- if (fd == -1) {
+ acpifd = open(ACPIDEV, O_RDWR);
+ if (acpifd == -1)
err(EX_OSFILE, ACPIDEV);
- }
- if (ioctl(fd, enable, NULL) == -1) {
+}
+
+static int
+acpi_enable_disable(int enable)
+{
+ if (ioctl(acpifd, enable, NULL) == -1) {
if (enable == ACPIIO_ENABLE)
err(EX_IOERR, "enable failed");
else
err(EX_IOERR, "disable failed");
}
- close(fd);
return (0);
}
@@ -65,16 +68,43 @@ acpi_enable_disable(int enable)
static int
acpi_sleep(int sleep_type)
{
- int fd;
-
- fd = open(ACPIDEV, O_RDWR);
- if (fd == -1) {
- err(EX_OSFILE, ACPIDEV);
- }
- if (ioctl(fd, ACPIIO_SETSLPSTATE, &sleep_type) == -1) {
+ if (ioctl(acpifd, ACPIIO_SETSLPSTATE, &sleep_type) == -1)
err(EX_IOERR, "sleep type (%d) failed", sleep_type);
- }
- close(fd);
+
+ return (0);
+}
+
+static int
+acpi_battinfo(int num)
+{
+ union acpi_battery_ioctl_arg battio;
+ const char *pwr_units;
+
+ if (num < 0 || num > 64)
+ err(EX_USAGE, "invalid battery %d", num);
+
+ battio.unit = num;
+ if (ioctl(acpifd, ACPIIO_CMBAT_GET_BIF, &battio) == -1)
+ err(EX_IOERR, "get battery info (%d) failed", num);
+ printf("Battery %d information\n", num);
+ if (battio.bif.units == 0)
+ pwr_units = "mWh";
+ else
+ pwr_units = "mAh";
+
+ printf("Design capacity:\t%d %s\n", battio.bif.dcap, pwr_units);
+ printf("Last full capacity:\t%d %s\n", battio.bif.lfcap, pwr_units);
+ printf("Technology:\t\t%s\n", battio.bif.btech == 0 ?
+ "primary (non-rechargeable)" : "secondary (rechargeable)");
+ printf("Design voltage:\t\t%d mV\n", battio.bif.dvol);
+ printf("Capacity (warn):\t%d %s\n", battio.bif.wcap, pwr_units);
+ printf("Capacity (low):\t\t%d %s\n", battio.bif.lcap, pwr_units);
+ printf("Low/warn granularity:\t%d %s\n", battio.bif.gra1, pwr_units);
+ printf("Warn/full granularity:\t%d %s\n", battio.bif.gra2, pwr_units);
+ printf("Model number:\t\t%s\n", battio.bif.model);
+ printf("Serial number:\t\t%s\n", battio.bif.serial);
+ printf("Type:\t\t\t%s\n", battio.bif.type);
+ printf("OEM info:\t\t%s\n", battio.bif.oeminfo);
return (0);
}
@@ -82,7 +112,7 @@ acpi_sleep(int sleep_type)
static void
usage(const char* prog)
{
- printf("usage: %s [-deh] [-s [1|2|3|4|4b|5]]\n", prog);
+ printf("usage: %s [-deh] [-i batt] [-s 1-5]\n", prog);
exit(0);
}
@@ -93,21 +123,23 @@ main(int argc, char *argv[])
int sleep_type;
prog = argv[0];
+ if (argc < 2)
+ usage(prog);
+ /* NOTREACHED */
+
sleep_type = -1;
- while ((c = getopt(argc, argv, "dehs:")) != -1) {
+ acpi_init();
+ while ((c = getopt(argc, argv, "dehi:s:")) != -1) {
switch (c) {
+ case 'i':
+ acpi_battinfo(atoi(optarg));
+ break;
case 'd':
acpi_enable_disable(ACPIIO_DISABLE);
break;
-
case 'e':
acpi_enable_disable(ACPIIO_ENABLE);
break;
-
- case 'h':
- usage(prog);
- break;
-
case 's':
if (optarg[0] == 'S')
sleep_type = optarg[1] - '0';
@@ -115,17 +147,22 @@ main(int argc, char *argv[])
sleep_type = optarg[0] - '0';
if (sleep_type < 0 || sleep_type > 5)
errx(EX_USAGE, "invalid sleep type (%d)",
- sleep_type);
+ sleep_type);
break;
+ case 'h':
default:
- argc -= optind;
- argv += optind;
+ usage(prog);
+ /* NOTREACHED */
}
}
+ argc -= optind;
+ argv += optind;
if (sleep_type != -1) {
sleep(1); /* wait 1 sec. for key-release event */
acpi_sleep(sleep_type);
}
- return (0);
+
+ close(acpifd);
+ exit (0);
}
OpenPOWER on IntegriCloud