View Single Post
Old 05-21-2024, 02:42 PM   #6
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 47,462
Karma: 171313058
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Played on my Libra Colour and changed battery to bd71827_bat in the shell script. I've attached the script (renamed to battcalc.sh.txt so rename back) and an image of the popup.

My first pass at the changes screwed up when I copy/pasted the script and the line endings were changed to CRLF. Used Notepad++ to change them to LF and all was happy.

Spoiler:
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.
# 
# For the Libra Colour, you need to use bd71827_bat instead of battery.
# 
# 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/bd71827_bat/capacity)
v_now=$(cat /sys/class/power_supply/bd71827_bat/voltage_now)
v_min=$(cat /sys/class/power_supply/bd71827_bat/voltage_min)
v_max=$(cat /sys/class/power_supply/bd71827_bat/voltage_max)
c_now=$(cat /sys/class/power_supply/bd71827_bat/charge_now)
c_full=$(cat /sys/class/power_supply/bd71827_bat/charge_full)
c_dfull=$(cat /sys/class/power_supply/bd71827_bat/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%
Attached Thumbnails
Click image for larger version

Name:	battery_LC.png
Views:	223
Size:	33.0 KB
ID:	208427  
Attached Files
File Type: txt battcalc.sh.txt (1.6 KB, 135 views)

Last edited by DNSB; 05-21-2024 at 02:45 PM.
DNSB is offline   Reply With Quote