From 7e73518ee8993d322ed9a261710d652446949070 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Mon, 25 Mar 2019 14:30:29 -0400 Subject: [PATCH] Add an alternative energy sensor, via poll --- x4/bin/khatus_x4_sensor_energy_poller | 16 ++++++++++++++++ x4/sanity_check | 7 +++++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100755 x4/bin/khatus_x4_sensor_energy_poller diff --git a/x4/bin/khatus_x4_sensor_energy_poller b/x4/bin/khatus_x4_sensor_energy_poller new file mode 100755 index 0000000..536ef92 --- /dev/null +++ b/x4/bin/khatus_x4_sensor_energy_poller @@ -0,0 +1,16 @@ +#! /bin/sh + +set -e + +bin_dir="$(dirname $(realpath $0))" + +. "$bin_dir/khatus_x4_lib_common_sensor.sh" + +sensor() { + upower --show-info /org/freedesktop/UPower/devices/DisplayDevice | awk ' + /percentage:/ {print "battery_percentage", int($2)} + /state:/ {print "battery_state" , $2} + ' +} + +run_as_poller diff --git a/x4/sanity_check b/x4/sanity_check index 6c6b17b..8210828 100755 --- a/x4/sanity_check +++ b/x4/sanity_check @@ -19,7 +19,8 @@ sensors_fork_all() { ./bin/khatus_x4_sensor_datetime -d -i 1 ./bin/khatus_x4_sensor_bluetooth -d -i 1 ./bin/khatus_x4_sensor_mpd -d -i 1 - ./bin/khatus_x4_sensor_energy -d -i 1 + ./bin/khatus_x4_sensor_energy -d + ./bin/khatus_x4_sensor_energy_poller -d -i 1 ./bin/khatus_x4_sensor_memory -d -i 1 ./bin/khatus_x4_sensor_loadavg -d -i 1 ./bin/khatus_x4_sensor_temp -d -i 1 -- -z 0 @@ -40,7 +41,9 @@ sensors_read_all() { while : do battery_state="$(sensor_read_one ${dir}/khatus_x4_sensor_energy/out/battery_state)" + battery_state_poll="$(sensor_read_one ${dir}/khatus_x4_sensor_energy_poller/out/battery_state)" battery_percentage="$(sensor_read_one ${dir}/khatus_x4_sensor_energy/out/battery_percentage)" + battery_percentage_poll="$(sensor_read_one ${dir}/khatus_x4_sensor_energy_poller/out/battery_percentage)" bluetooth_controllers="$(sensor_read_one ${dir}/khatus_x4_sensor_bluetooth/out/count_powered_controllers)" bluetooth_devices="$(sensor_read_one ${dir}/khatus_x4_sensor_bluetooth/out/count_connected_devices)" datetime="$(sensor_read_one ${dir}/khatus_x4_sensor_datetime/out/datetime)" @@ -53,7 +56,7 @@ sensors_read_all() { vol_right="$(sensor_read_one ${dir}/khatus_x4_sensor_volume/out/vol_right)" vol_state="$(sensor_read_one ${dir}/khatus_x4_sensor_volume/out/state)" vol_mute="$(sensor_read_one ${dir}/khatus_x4_sensor_volume/out/mute)" - echo "E[${battery_state} ${battery_percentage}] M:${mem}% L:${load} T:${temp}°C D:${disk}% [${mpd}] [$bluetooth_controllers $bluetooth_devices] V:${vol_state}:${vol_left}:${vol_right}:${vol_mute} ${datetime}" + echo "E[${battery_state} ${battery_percentage} | ${battery_state} ${battery_percentage_poll}] M:${mem}% L:${load} T:${temp}°C D:${disk}% [${mpd}] [$bluetooth_controllers $bluetooth_devices] V:${vol_state}:${vol_left}:${vol_right}:${vol_mute} ${datetime}" sleep 1 done } -- 2.20.1