From: Siraaj Khandkar Date: Mon, 25 Mar 2019 18:15:21 +0000 (-0400) Subject: Add volume sensor X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=93c067b528d520ceaef09830923aa3c951ad2e8f;p=khatus.git Add volume sensor --- diff --git a/x4/bin/khatus_x4_sensor_volume b/x4/bin/khatus_x4_sensor_volume new file mode 100755 index 0000000..379a5a2 --- /dev/null +++ b/x4/bin/khatus_x4_sensor_volume @@ -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 diff --git a/x4/sanity_check b/x4/sanity_check index 4250b5a..6c6b17b 100755 --- a/x4/sanity_check +++ b/x4/sanity_check @@ -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 }