From owner-freebsd-bugs@FreeBSD.ORG Mon Jul 18 14:40:35 2005 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0EA6416A41C for ; Mon, 18 Jul 2005 14:40:35 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6B21A43D49 for ; Mon, 18 Jul 2005 14:40:34 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j6IEeYWi031603 for ; Mon, 18 Jul 2005 14:40:34 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j6IEeYC7031602; Mon, 18 Jul 2005 14:40:34 GMT (envelope-from gnats) Resent-Date: Mon, 18 Jul 2005 14:40:34 GMT Resent-Message-Id: <200507181440.j6IEeYC7031602@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Rudolf Cejka Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 83ACE16A41C for ; Mon, 18 Jul 2005 14:40:09 +0000 (GMT) (envelope-from cejkar@fit.vutbr.cz) Received: from kazi.fit.vutbr.cz (kazi.fit.vutbr.cz [147.229.8.12]) by mx1.FreeBSD.org (Postfix) with ESMTP id C2A6743D46 for ; Mon, 18 Jul 2005 14:40:08 +0000 (GMT) (envelope-from cejkar@fit.vutbr.cz) Received: from kazi.fit.vutbr.cz (localhost [127.0.0.1]) by kazi.fit.vutbr.cz (envelope-from cejkar@fit.vutbr.cz) (8.13.4/8.13.3) with ESMTP id j6IEe63m004309 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 18 Jul 2005 16:40:06 +0200 (CEST) Received: (from cejkar@localhost) by kazi.fit.vutbr.cz (8.13.4/8.13.1/Submit) id j6IEe6MU004308; Mon, 18 Jul 2005 16:40:06 +0200 (CEST) (envelope-from cejkar) Message-Id: <200507181440.j6IEe6MU004308@kazi.fit.vutbr.cz> Date: Mon, 18 Jul 2005 16:40:06 +0200 (CEST) From: Rudolf Cejka To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/83672: acpiconf with remaining battery life and time X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Rudolf Cejka List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Jul 2005 14:40:35 -0000 >Number: 83672 >Category: bin >Synopsis: acpiconf with remaining battery life and time >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Jul 18 14:40:33 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Rudolf Cejka >Release: FreeBSD 5.3-STABLE i386 >Organization: FIT, Brno University of Technology, Czech Republic >Environment: Patches are for -current from 15 July 2005. >Description: There are four patches: Patch #1: Just style fix, which renames deprecated ACPIIO_CMBAT_GET_B* to ACPIIO_BATT_GET_B*. Patch #2: Just another style fix, which changes some upper letters to the lower letters, so all lines are printed in the same style - with just first upper letter. Patch #3: This patch adds two lines in acpiconf -i0 output after Remaining capacity line, so that remaining energy is printed in three forms: capacity in mAh/mWh and newly in percentage and in time form, like apm did (so I can finally switch from apm to acpiconf :o). Patch #4: Consumption rate is in mA/mW, not in mAh/mWh, so this patch fixes the printed unit. >How-To-Repeat: >Fix: Patch #1: --- usr.sbin/acpi/acpiconf/acpiconf.c.orig Sun Jul 17 16:07:57 2005 +++ usr.sbin/acpi/acpiconf/acpiconf.c Sun Jul 17 16:11:30 2005 @@ -96,7 +96,7 @@ err(EX_USAGE, "invalid battery %d", num); battio.unit = num; - if (ioctl(acpifd, ACPIIO_CMBAT_GET_BIF, &battio) == -1) + if (ioctl(acpifd, ACPIIO_BATT_GET_BIF, &battio) == -1) err(EX_IOERR, "get battery info (%d) failed", num); printf("Battery %d information\n", num); if (battio.bif.units == 0) @@ -129,7 +129,7 @@ printf("OEM info:\t\t%s\n", battio.bif.oeminfo); battio.unit = num; - if (ioctl(acpifd, ACPIIO_CMBAT_GET_BST, &battio) == -1) + if (ioctl(acpifd, ACPIIO_BATT_GET_BST, &battio) == -1) err(EX_IOERR, "get battery info (%d) failed", num); if (battio.bst.state != ACPI_BATT_STAT_NOT_PRESENT) { Patch #2: --- usr.sbin/acpi/acpiconf/acpiconf.c.orig Sun Jul 17 16:12:32 2005 +++ usr.sbin/acpi/acpiconf/acpiconf.c Sun Jul 17 16:13:19 2005 @@ -142,14 +142,14 @@ printf("Charging"); printf("\n"); if (battio.bst.rate == UNKNOWN_CAP) - printf("Present Rate:\t\tUnknown\n"); + printf("Present rate:\t\tUnknown\n"); else - printf("Present Rate:\t\t%d %s\n", battio.bst.rate, + printf("Present rate:\t\t%d %s\n", battio.bst.rate, pwr_units); if (battio.bst.cap == UNKNOWN_CAP) - printf("Remaining Capacity:\tUnknown\n"); + printf("Remaining capacity:\tUnknown\n"); else - printf("Remaining Capacity:\t%d %s\n", battio.bst.cap, + printf("Remaining capacity:\t%d %s\n", battio.bst.cap, pwr_units); if (battio.bst.volt == UNKNOWN_CAP) printf("Volt:\t\t\tUnknown\n"); Patch #3: --- usr.sbin/acpi/acpiconf/acpiconf.c.orig Sun Jul 17 16:13:52 2005 +++ usr.sbin/acpi/acpiconf/acpiconf.c Sun Jul 17 16:32:49 2005 @@ -91,6 +91,8 @@ { union acpi_battery_ioctl_arg battio; const char *pwr_units; + u_int32_t dcap; + int h, m, s; if (num < 0 || num > 64) err(EX_USAGE, "invalid battery %d", num); @@ -108,6 +110,7 @@ printf("Design capacity:\tUnknown\n"); else printf("Design capacity:\t%d %s\n", battio.bif.dcap, pwr_units); + dcap = battio.bif.dcap; if (battio.bif.lfcap == UNKNOWN_CAP) printf("Last full capacity:\tUnknown\n"); else @@ -151,6 +154,22 @@ else printf("Remaining capacity:\t%d %s\n", battio.bst.cap, pwr_units); + if (battio.bst.cap == UNKNOWN_CAP || + dcap == UNKNOWN_CAP || dcap == 0) + printf("Remaining life:\t\tUnknown\n"); + else + printf("Remaining life:\t\t%.1f %%\n", + 100.0 * battio.bst.cap / dcap); + h = (battio.bst.state & ACPI_BATT_STAT_DISCHARG && + battio.bst.cap != UNKNOWN_CAP && + battio.bst.rate != UNKNOWN_CAP && + battio.bst.rate != 0) ? + 3600 * battio.bst.cap / battio.bst.rate : 0; + s = h % 60; + h /= 60; + m = h % 60; + h /= 60; + printf("Remaining time:\t\t%d:%02d:%02d\n", h, m, s); if (battio.bst.volt == UNKNOWN_CAP) printf("Volt:\t\t\tUnknown\n"); else Patch #4: --- usr.sbin/acpi/acpiconf/acpiconf.c.orig Sun Jul 17 16:40:29 2005 +++ usr.sbin/acpi/acpiconf/acpiconf.c Sun Jul 17 16:41:37 2005 @@ -90,7 +90,7 @@ acpi_battinfo(int num) { union acpi_battery_ioctl_arg battio; - const char *pwr_units; + const char *pwr_units, *pwr_units2; u_int32_t dcap; int h, m, s; @@ -101,10 +101,13 @@ if (ioctl(acpifd, ACPIIO_BATT_GET_BIF, &battio) == -1) err(EX_IOERR, "get battery info (%d) failed", num); printf("Battery %d information\n", num); - if (battio.bif.units == 0) + if (battio.bif.units == 0) { pwr_units = "mWh"; - else + pwr_units2 = "mW"; + } else { pwr_units = "mAh"; + pwr_units2 = "mA"; + } if (battio.bif.dcap == UNKNOWN_CAP) printf("Design capacity:\tUnknown\n"); @@ -148,7 +151,7 @@ printf("Present rate:\t\tUnknown\n"); else printf("Present rate:\t\t%d %s\n", battio.bst.rate, - pwr_units); + pwr_units2); if (battio.bst.cap == UNKNOWN_CAP) printf("Remaining capacity:\tUnknown\n"); else >Release-Note: >Audit-Trail: >Unformatted: