Add an alternative energy sensor, via poll
authorSiraaj Khandkar <siraaj@khandkar.net>
Mon, 25 Mar 2019 18:30:29 +0000 (14:30 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Mon, 25 Mar 2019 18:30:29 +0000 (14:30 -0400)
x4/bin/khatus_x4_sensor_energy_poller [new file with mode: 0755]
x4/sanity_check

diff --git a/x4/bin/khatus_x4_sensor_energy_poller b/x4/bin/khatus_x4_sensor_energy_poller
new file mode 100755 (executable)
index 0000000..536ef92
--- /dev/null
@@ -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
index 6c6b17b..8210828 100755 (executable)
@@ -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
 }
This page took 0.020431 seconds and 4 git commands to generate.