cmd_sens_bluetooth="khatus_sensor_bluetooth_power $dir_bin"
cmd_sens_mpd_state="khatus_sensor_mpd_state $dir_bin"
cmd_sens_net_addr_io="khatus_sensor_net_addr_io $dir_bin"
+ cmd_sens_volume="khatus_sensor_volume $dir_bin"
# TODO: Redirect each worker's stderr to a dedicated log file
pipe="$file_pipe"
fork_poller $interval_inp_weather "$pipe" "$dir_bin" "$log" "$cmd_sens_weather" 'in:WEATHER'
fork_poller $interval_inp_mpd_state "$pipe" "$dir_bin" "$log" "$cmd_sens_mpd_state" 'in:MPD_STATE'
fork_poller $interval_inp_mpd_song "$pipe" "$dir_bin" "$log" khatus_sensor_mpd_song 'in:MPD_SONG'
- fork_poller $interval_inp_volume "$pipe" "$dir_bin" "$log" khatus_sensor_volume 'in:VOLUME'
+ fork_poller $interval_inp_volume "$pipe" "$dir_bin" "$log" "$cmd_sens_volume" 'in:VOLUME'
fork_poller $interval_inp_bluetooth "$pipe" "$dir_bin" "$log" "$cmd_sens_bluetooth" 'in:BLUETOOTH_POWER'
fork_poller $interval_inp_net_wifi "$pipe" "$dir_bin" "$log" khatus_sensor_net_wifi_status 'in:NET_WIFI_STATUS'
fork_poller $interval_inp_net_io "$pipe" "$dir_bin" "$log" "$cmd_sens_net_addr_io" 'in:NET_ADDR_IO'
/^in:VOLUME/\
{
- shift()
- db["volume"] = $0
+ set_volume()
}
/^in:MPD_SONG OK +MPD/ { delete db_mpd_song; next }
output_msg_status_bar(make_status_bar())
}
+function set_volume( mute, left, right) {
+ # 0 RUNNING no 75% 75%
+ #msg_head = $1
+ #sink = $2
+ #state = $3
+ mute = $4
+ left = $5
+ right = $6
+
+ if (mute == "no") {
+ db["volume"] = sprintf("%s %s", left, right)
+ } else if (mute == "yes") {
+ db["volume"] = "X"
+ } else {
+ # TODO: Log error - unexpected mute value
+ }
+}
+
function set_mpd_song( key, val) {
key = $2
shift()
--- /dev/null
+#! /usr/bin/awk -f
+
+/^Sink \#[0-9]+$/ {
+ sub("^#", "", $2)
+ sink = $2
+ next
+}
+
+/\tState:/ {
+ state[sink] = $2
+ next
+}
+
+/\tMute:/ {
+ mute[sink] = $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] = left_parts[2]
+ vol_right[sink] = right_parts[2]
+ next
+}
+
+END {
+ for (sink in state) {
+ printf(\
+ "%s %s %s %s %s\n",
+ sink, state[sink], mute[sink], vol_left[sink], vol_right[sink] \
+ )
+ }
+}
set -e
-pactl list sinks \
-| awk '
- /^\tMute:/ {
- printf("%s,", $0);
- }
- /^\tVolume:/ {
- for (i=2; i<=NF; i++) printf(" %s", $i);
- }' \
-| awk -v RS=',' '
- /^[ \t]*Mute:/ {mute = $2}
- /^[ \t]*front-left:/ {left = $4}
- /^[ \t]*front-right:/ {right = $4}
- END {
- if (mute == "yes") {
- print("x")
- } else {
- printf("%s %s\n", left, right)
- }
- }
- '
+dir_bin="$1"
+
+pactl list sinks | "$dir_bin"/khatus_parse_pactl_list_sinks