Add volume sensor
authorSiraaj Khandkar <siraaj@khandkar.net>
Mon, 25 Mar 2019 18:15:21 +0000 (14:15 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Mon, 25 Mar 2019 18:15:21 +0000 (14:15 -0400)
x4/bin/khatus_x4_sensor_volume [new file with mode: 0755]
x4/sanity_check

diff --git a/x4/bin/khatus_x4_sensor_volume b/x4/bin/khatus_x4_sensor_volume
new file mode 100755 (executable)
index 0000000..379a5a2
--- /dev/null
@@ -0,0 +1,63 @@
+#! /bin/sh
+
+set -e
+
+bin_dir="$(dirname $(realpath $0))"
+
+. "$bin_dir/khatus_x4_lib_common_sensor.sh"
+
+sensor() {
+    def_sink=$(pactl info | awk '/^Default Sink:/ {print $3}')
+
+    pactl list sinks | awk -v def_sink="$def_sink" '
+        /^Sink \#[0-9]+$/ {
+            sub("^#", "", $2)
+            sink_number = $2
+            next
+        }
+
+        /\tState:/ {
+            state[sink_number] = $2
+            next
+        }
+
+        /\tName:/ {
+            name[sink_number] = $2
+            next
+        }
+
+        /\tMute:/ {
+            mute[sink_number] = $2
+            next
+        }
+
+        # Volume: front-left: 45732 /  70% / -9.38 dB,   front-right: 45732 /  70% / -9.38 dB
+        /\tVolume:/ {
+            delete vol_parts
+            delete left_parts
+            delete right_parts
+            sub("^\t+Volume: +", "")
+            split($0, vol_parts, ", +")
+            sub("^front-left: +", "", vol_parts[1])
+            sub("^front-right: +", "", vol_parts[2])
+            split(vol_parts[1], left_parts, " +/ +")
+            split(vol_parts[2], right_parts, " +/ +")
+            vol_left[sink_number] = left_parts[2]
+            vol_right[sink_number] = right_parts[2]
+            next
+        }
+
+        END {
+            for (sink_number in name) {
+                if (name[sink_number] == def_sink) {
+                    print("state"    , state[sink_number])
+                    print("mute"     , mute[sink_number])
+                    print("vol_left" , vol_left[sink_number])
+                    print("vol_right", vol_right[sink_number])
+                }
+            }
+        }
+    '
+}
+
+run_as_poller
index 4250b5a..6c6b17b 100755 (executable)
@@ -24,6 +24,7 @@ sensors_fork_all() {
     ./bin/khatus_x4_sensor_loadavg   -d -i 1
     ./bin/khatus_x4_sensor_temp      -d -i 1 -- -z 0
     ./bin/khatus_x4_sensor_disk      -d -i 1 -- -f /
+    ./bin/khatus_x4_sensor_volume    -d -i 1
 }
 
 sensor_read_one() {
@@ -48,7 +49,11 @@ sensors_read_all() {
         load="$(sensor_read_one ${dir}/khatus_x4_sensor_loadavg/out/load_avg_1min)"
         temp="$(sensor_read_one ${dir}/khatus_x4_sensor_temp/out/thermal_zone0)"
         disk="$(sensor_read_one ${dir}/khatus_x4_sensor_disk/out/disk_usage_percentage)"
-        echo "E[${battery_state} ${battery_percentage}] M:${mem}% L:${load} T:${temp}°C D:${disk}% [${mpd}] [$bluetooth_controllers $bluetooth_devices] ${datetime}"
+        vol_left="$(sensor_read_one ${dir}/khatus_x4_sensor_volume/out/vol_left)"
+        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}"
         sleep 1
     done
 }
This page took 0.031156 seconds and 4 git commands to generate.