View Single Post
Old 05-18-2023, 08:10 PM   #1004
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,705
Karma: 16308824
Join Date: Sep 2022
Device: Kobo Libra 2
Quote:
Originally Posted by isarl View Post
That should work. It doesn't have to be in .adds/ in particular, but that seems like a logical place.
Success! Thanks for all the help. If anyone's interested, here's the script:

Code:
# Battery Statistics Calculator 1.0 (2023-05-18) 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)

let v_now/=1000; let v_min/=1000; let v_max/=1000 # 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%1000; let v_min/=1000 # "
let v_maxr=$v_max%1000; let v_max/=1000 # "
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

# Format and display the results

echo Capacity: $c_now mAh / $meter% / $charge%
echo Voltage: $v_min.$v_minr V / $v_now.$v_nowr V / $v_max.$v_maxr V
echo Health: $c_full mAh / $c_dfull mAh / $c_health%
Now you get lots of new inaccurate statistics! Kobo is using BusyBox with ash, so I had to do some research on how it works, but it seems to be mostly the same as bash. I've attached a picture of the output on the Kobo.

You get the current battery capacity in mAh, the current percentage that the battery icon reports, the current percentage as calculated by the current / maximum mAh, the minimum, current, and maximum battery voltage, and the battery health calculated from the maximum vs the design capacity.
Attached Thumbnails
Click image for larger version

Name:	kobo_battcalc.png
Views:	339
Size:	25.5 KB
ID:	201600  

Last edited by Aleron Ives; 05-18-2023 at 08:13 PM.
Aleron Ives is offline   Reply With Quote