View Single Post
Old 05-30-2024, 05:19 PM   #1337
Aleron Ives
Wizard
Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.Aleron Ives ought to be getting tired of karma fortunes by now.
 
Posts: 1,698
Karma: 16307824
Join Date: Sep 2022
Device: Kobo Libra 2
I made an update for my battery statistics calculation script. It now also calculates the remaining percentage from the battery's voltage, which I've found to be a more reliable capacity indicator than either the mAh-based estimate or Nickel's built-in estimate. I removed some trailing zeroes on the voltage line to make more room for displaying the extra statistic. Here's the new script:

Code:
# Battery Statistics Calculator 1.1 (2024-05-25) by Aleron Ives
#
# This script calculates battery statistics for the Kobo Libra 2.
# Check the contents of /sys/class/power_supply/ if you use a different
# model to ensure that the statistics you want to track are available.
#
# You can use NickelMenu to invoke this script like so:
# menu_item :main :Battery :cmd_output :500 :/mnt/onboard/.adds/battcalc.sh

# Gather the necessary statistics

meter=$(cat /sys/class/power_supply/battery/capacity)
v_now=$(cat /sys/class/power_supply/battery/voltage_now)
v_min=$(cat /sys/class/power_supply/battery/voltage_min)
v_max=$(cat /sys/class/power_supply/battery/voltage_max)
c_now=$(cat /sys/class/power_supply/battery/charge_now)
c_full=$(cat /sys/class/power_supply/battery/charge_full)
c_dfull=$(cat /sys/class/power_supply/battery/charge_full_design)

# Format the statistics

let v_pct=$v_max-$v_now; let v_pct/=7000 # Calculate charge percentage from V
let v_pct=100-$v_pct                     # "
let v_now/=1000; let v_min/=10000; let v_max/=10000  # Convert to V
let c_now/=1000; let c_full/=1000; let c_dfull/=1000 # Convert to mAh
let v_nowr=$v_now%1000; let v_now/=1000 # Simulate floating-point arithmetic
let v_minr=$v_min%100; let v_min/=100   # "
let v_maxr=$v_max%100; let v_max/=100   # "
let charge=$c_now*100/$c_full     # Calculate charge percentage from mAh
let c_health=$c_full*100/$c_dfull # Calculate health percentage from mAh

# Display the results

echo Capacity: $c_now mAh / $charge% / $meter%
echo Voltage: $v_min.$v_minr V / $v_now.$v_nowr V / $v_max.$v_maxr V / $v_pct%
echo Health: $c_full mAh / $c_dfull mAh / $c_health%
If you're using the Libra Colour, you'll want to change the v_pct divisor from 7000 to 9000, since the Libra Colour charges its battery to 4.4 V, rather than 4.2 V.
Attached Thumbnails
Click image for larger version

Name:	kobo_battcalc2.png
Views:	662
Size:	26.4 KB
ID:	208591  
Aleron Ives is offline   Reply With Quote