diff options
author | Russell Morris <rmorris@rkmorris.us> | 2020-01-22 21:10:13 -0600 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-07-18 15:28:36 +0200 |
commit | dcac704b3d6bc3c4ad2ccacb3d79fc67d900087f (patch) | |
tree | c384a20a949b737946b677e72e3b3a8d1fc84c7c /modules/luci-mod-battstatus/root/usr/libexec | |
parent | df3f62988897012b36c1f4810570a1eece65e2d5 (diff) |
luci-app-battstatus: initial release
Introduce a new package luci-app-battstatus which queries battery charge
information using i2c commands and displays a charge indicator in the
upper right notification area.
So far this package has been tested to work with the HooToo HT-TM05
travel router but might be extended to cover further models in the
future.
Signed-off-by: Russell Morris <rmorris@rkmorris.us>
[rebase on top of master, rewrite commit message, adjust copyright,
convert some ubus fields to boolean values]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-mod-battstatus/root/usr/libexec')
-rwxr-xr-x | modules/luci-mod-battstatus/root/usr/libexec/rpcd/luci.battstatus | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/modules/luci-mod-battstatus/root/usr/libexec/rpcd/luci.battstatus b/modules/luci-mod-battstatus/root/usr/libexec/rpcd/luci.battstatus new file mode 100755 index 0000000000..d3534b4f35 --- /dev/null +++ b/modules/luci-mod-battstatus/root/usr/libexec/rpcd/luci.battstatus @@ -0,0 +1,39 @@ +#!/bin/sh + +. /usr/share/libubox/jshn.sh + +case "$1" in + list) + printf '{ "getBatteryStatus": {} }' + ;; + call) + case "$2" in + getBatteryStatus) + json_init + + eval $(/bin/ubus call system board 2>/dev/null | /usr/bin/jsonfilter -e 'MODEL=@.model') + json_add_object "$MODEL" + + 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_close_object + json_dump + ;; + esac + ;; +esac |