Files
luci/modules/luci-mod-battstatus/root/usr/libexec/rpcd/luci.battstatus
Coia Prant d42dce3ea2 luci-mod-battstatus: preparing for other devices
For standard devices, we can read from `/sys/class/power_supply`

Add board checks to implement different solutions for different boards

Signed-off-by: Coia Prant <coiaprant@gmail.com>
Signed-off-by: Paul Donald <newtwen+github@gmail.com>
2025-09-29 17:40:44 +02:00

49 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
. /usr/share/libubox/jshn.sh
board=$(cat /tmp/sysinfo/board_name)
model=$(cat /tmp/sysinfo/model)
case "$1" in
list)
printf '{ "getBatteryStatus": {} }'
;;
call)
case "$2" in
getBatteryStatus)
json_init
json_add_object "$model"
case "$board" in
hootoo,ht-tm05)
if [ -f /usr/sbin/i2cset ] && [ -f /usr/sbin/i2cget ]; then
json_add_boolean valid 1
if [ $(i2cset -y 0 0x0a 0x0a 0x01 && i2cget -y 0 0x0a 0x0a) = 0x40 ]; then
json_add_boolean charging 1
else
json_add_boolean charging 0
fi
json_add_int percentage $(i2cset -y 0 0x0a 0x0a 0x10 && i2cget -y 0 0x0a 0x0a | xargs printf %d)
else
json_add_boolean valid 0
if [ ! -f /usr/sbin/i2cset ]; then
json_add_string message "Need i2cset"
else
json_add_string message "Need i2cget"
fi
fi
;;
*)
json_add_boolean valid 0
json_add_string message "Unsupported"
;;
esac
json_close_object
json_dump
;;
esac
;;
esac