mirror of
https://github.com/smxi/inxi.git
synced 2024-11-16 16:21:39 +00:00
patch to correct possible energy/charge battery mixups, now it's explicitly
done by charge (mAh) or energy (Wh), this lets me use either variable internally so the outcome would maintain values even if one charge vaiue was missing.
This commit is contained in:
parent
eec6d6e5a8
commit
f62ab22444
41
inxi
41
inxi
|
@ -4182,9 +4182,14 @@ get_battery_data()
|
|||
voltage_min_design=""
|
||||
voltage_now=""
|
||||
power_now=""
|
||||
# charge: mAh
|
||||
charge_full_design=""
|
||||
charge_full=""
|
||||
charge_now=""
|
||||
# energy: Wh
|
||||
energy_full_design=""
|
||||
energy_full=""
|
||||
energy_now=""
|
||||
capacity=""
|
||||
capacity_level=""
|
||||
model=""
|
||||
|
@ -4225,14 +4230,14 @@ get_battery_data()
|
|||
power_now=$NF
|
||||
}
|
||||
$1 ~ /^POWER_SUPPLY_ENERGY_FULL_DESIGN$/ {
|
||||
charge_full_design = $NF / 1000000
|
||||
energy_full_design = $NF / 1000000
|
||||
}
|
||||
$1 ~ /^POWER_SUPPLY_ENERGY_FULL$/ {
|
||||
charge_full = $NF / 1000000
|
||||
energy_full = $NF / 1000000
|
||||
}
|
||||
$1 ~ /^POWER_SUPPLY_ENERGY_NOW$/ {
|
||||
charge_now = $NF / 1000000
|
||||
charge_now = sprintf( "%.1f", charge_now )
|
||||
energy_now = $NF / 1000000
|
||||
energy_now = sprintf( "%.1f", charge_now )
|
||||
}
|
||||
# note: the following 3 were off, 100000 instead of 1000000
|
||||
# why this is, I do not know. I did not document any reason for that
|
||||
|
@ -4272,34 +4277,34 @@ get_battery_data()
|
|||
# if any of these values failed, the math will be wrong, but no way to fix that
|
||||
if (b_ma == "true" && voltage_now != ""){
|
||||
if (charge_now != ""){
|
||||
charge_now=charge_now*voltage_now
|
||||
energy_now=charge_now*voltage_now
|
||||
}
|
||||
if (charge_full != ""){
|
||||
charge_full=charge_full*voltage_now
|
||||
energy_full=charge_full*voltage_now
|
||||
}
|
||||
if (charge_full_design != ""){
|
||||
charge_full_design=charge_full_design*voltage_now
|
||||
energy_full_design=charge_full_design*voltage_now
|
||||
}
|
||||
}
|
||||
if (charge_now != "" && charge_full != "" ){
|
||||
capacity = 100*charge_now/charge_full
|
||||
if (energy_now != "" && energy_full != "" ){
|
||||
capacity = 100*energy_now/energy_full
|
||||
capacity = sprintf( "%.1f%", capacity )
|
||||
}
|
||||
if (charge_full_design != "" && charge_full != "" ){
|
||||
of_orig=100*charge_full/charge_full_design
|
||||
if (energy_full_design != "" && energy_full != "" ){
|
||||
of_orig=100*energy_full/energy_full_design
|
||||
of_orig = sprintf( "%.0f%", of_orig )
|
||||
}
|
||||
if (charge_now != "" ){
|
||||
charge_now = sprintf( "%.1f", charge_now )
|
||||
if (energy_now != "" ){
|
||||
energy_now = sprintf( "%.1f", energy_now )
|
||||
}
|
||||
if (charge_full_design != "" ){
|
||||
charge_full_design = sprintf( "%.1f", charge_full_design )
|
||||
if (energy_full_design != "" ){
|
||||
energy_full_design = sprintf( "%.1f", energy_full_design )
|
||||
}
|
||||
if ( charge_full != "" ){
|
||||
charge_full = sprintf( "%.1f", charge_full )
|
||||
if ( energy_full != "" ){
|
||||
energy_full = sprintf( "%.1f", energy_full )
|
||||
}
|
||||
entry = name "," status "," present "," chemistry "," cycles "," voltage_min_design "," voltage_now ","
|
||||
entry = entry power_now "," charge_full_design "," charge_full "," charge_now "," capacity ","
|
||||
entry = entry power_now "," energy_full_design "," energy_full "," energy_now "," capacity ","
|
||||
entry = entry capacity_level "," of_orig "," model "," company "," serial "," location
|
||||
print entry
|
||||
}' < $battery_file )
|
||||
|
|
Loading…
Reference in a new issue