From owner-svn-src-all@FreeBSD.ORG Tue Aug 24 18:08:00 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1B0E710656A4; Tue, 24 Aug 2010 18:08:00 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E439A8FC16; Tue, 24 Aug 2010 18:07:59 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o7OI7xAe083814; Tue, 24 Aug 2010 18:07:59 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o7OI7xHF083812; Tue, 24 Aug 2010 18:07:59 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <201008241807.o7OI7xHF083812@svn.freebsd.org> From: Alexander Motin Date: Tue, 24 Aug 2010 18:07:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r211763 - head/usr.sbin/acpi/acpiconf X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Aug 2010 18:08:00 -0000 Author: mav Date: Tue Aug 24 18:07:59 2010 New Revision: 211763 URL: http://svn.freebsd.org/changeset/base/211763 Log: 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. Modified: head/usr.sbin/acpi/acpiconf/acpiconf.c Modified: head/usr.sbin/acpi/acpiconf/acpiconf.c ============================================================================== --- head/usr.sbin/acpi/acpiconf/acpiconf.c Tue Aug 24 17:48:22 2010 (r211762) +++ head/usr.sbin/acpi/acpiconf/acpiconf.c Tue Aug 24 18:07:59 2010 (r211763) @@ -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); }