FreeBSD Bugzilla – Attachment 195185 Details for
Bug 229818
apm(8) The total battery percentage is incorrect for multiple batteries
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Produce the total battery percentage from the capacity totals rather than the other percentages
patch-sys_dev_acpica_acpi__battery.c (text/plain), 2.38 KB, created by
kd-dev
on 2018-07-17 01:53:10 UTC
(
hide
)
Description:
Produce the total battery percentage from the capacity totals rather than the other percentages
Filename:
MIME Type:
Creator:
kd-dev
Created:
2018-07-17 01:53:10 UTC
Size:
2.38 KB
patch
obsolete
>Index: sys/dev/acpica/acpi_battery.c >=================================================================== >--- sys/dev/acpica/acpi_battery.c (revision 336075) >+++ sys/dev/acpica/acpi_battery.c (working copy) >@@ -119,7 +119,7 @@ > acpi_battery_get_battinfo(device_t dev, struct acpi_battinfo *battinfo) > { > int batt_stat, devcount, dev_idx, error, i; >- int total_cap, total_min, valid_rate, valid_units; >+ int total_cap, total_lfcap, total_min, valid_rate, valid_units; > devclass_t batt_dc; > device_t batt_dev; > struct acpi_bst *bst; >@@ -152,6 +152,7 @@ > */ > dev_idx = -1; > batt_stat = valid_rate = valid_units = 0; >+ total_cap = total_lfcap = 0; > for (i = 0; i < devcount; i++) { > /* Default info for every battery is "not present". */ > acpi_reset_battinfo(&bi[i]); >@@ -213,17 +214,23 @@ > if (!acpi_battery_bif_valid(bif)) > continue; > >- /* Calculate percent capacity remaining. */ >- bi[i].cap = (100 * bst[i].cap) / bif->lfcap; >- > /* > * Some laptops report the "design-capacity" instead of the > * "real-capacity" when the battery is fully charged. That breaks > * the above arithmetic as it needs to be 100% maximum. > */ >- if (bi[i].cap > 100) >- bi[i].cap = 100; >+ if (bst[i].cap > bif->lfcap) >+ bst[i].cap = bif->lfcap; > >+ /* Calculate percent capacity remaining. */ >+ bi[i].cap = (100 * bst[i].cap) / bif->lfcap; >+ >+ /* If this battery is not present, don't use its capacity. */ >+ if (bi[i].cap != -1) { >+ total_cap += bst[i].cap; >+ total_lfcap += bif->lfcap; >+ } >+ > /* > * On systems with more than one battery, they may get used > * sequentially, thus bst.rate may only signify the one currently >@@ -244,7 +251,7 @@ > } > > /* Pass 2: calculate capacity and remaining time for all batteries. */ >- total_cap = total_min = 0; >+ total_min = 0; > for (i = 0; i < devcount; i++) { > /* > * If any batteries are discharging, use the sum of the bst.rate >@@ -256,10 +263,6 @@ > else > bi[i].min = 0; > total_min += bi[i].min; >- >- /* If this battery is not present, don't use its capacity. */ >- if (bi[i].cap != -1) >- total_cap += bi[i].cap; > } > > /* >@@ -268,7 +271,7 @@ > */ > if (valid_units > 0) { > if (dev == NULL) { >- battinfo->cap = total_cap / valid_units; >+ battinfo->cap = (total_cap * 100) / total_lfcap; > battinfo->min = total_min; > battinfo->state = batt_stat; > battinfo->rate = valid_rate;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 229818
: 195185