cmd_sens_temperature="khatus_sensor_temperature $thermal_zone"
cmd_sens_fan="khatus_sensor_fan $fan_path"
cmd_sens_bluetooth="khatus_sensor_bluetooth_power $dir_bin"
+ cmd_sens_mpd_state="khatus_sensor_mpd_state $dir_bin"
# TODO: Redirect each worker's stderr to a dedicated log file
pipe="$file_pipe"
fork_poller $interval_inp_datetime "$pipe" "$dir_bin" "$log" khatus_sensor_datetime 'in:DATE_TIME'
fork_poller $interval_inp_brightness "$pipe" "$dir_bin" "$log" "$cmd_sens_screen_brightness" 'in:SCREEN_BRIGHTNESS'
fork_poller $interval_inp_weather "$pipe" "$dir_bin" "$log" "$cmd_sens_weather" 'in:WEATHER'
- fork_poller $interval_inp_mpd_state "$pipe" "$dir_bin" "$log" khatus_sensor_mpd_state 'in:MPD_STATE'
+ 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_bluetooth "$pipe" "$dir_bin" "$log" "$cmd_sens_bluetooth" 'in:BLUETOOTH_POWER'
--- /dev/null
+#! /usr/bin/awk -f
+
+# Msg BEGINs
+/^OK MPD / { delete status; next}
+
+# Msg ENDs
+/^OK$/ {
+ split(status["time"], time, ":")
+ seconds_current = time[1]
+ seconds_total = time[2]
+
+ hours = int(seconds_current / 60 / 60);
+ secs_beyond_hours = seconds_current - (hours * 60 * 60);
+ mins = int(secs_beyond_hours / 60);
+ secs = secs_beyond_hours - (mins * 60);
+
+ if (hours > 0) {
+ current_time = sprintf("%d:%.2d:%.2d", hours, mins, secs)
+ } else {
+ current_time = sprintf("%.2d:%.2d", mins, secs)
+ }
+
+ if (seconds_total > 0) {
+ time_percentage = (seconds_current / seconds_total) * 100
+ current_percentage = sprintf("%d%%", time_percentage)
+ } else {
+ current_percentage = "~"
+ }
+
+ printf("%s %s %s\n", status["state"], current_time, current_percentage)
+ next
+}
+
+# Msg content
+/^[a-z]+: / {
+ sub(":$", "", $1)
+ status[$1] = $2
+ next
+}
set -e
+dir_bin="$1"
+
echo 'status' \
| nc 127.0.0.1 6600 \
-| awk '
- {
- status[$1] = $2
- }
-
- /^time: +[0-9]+:[0-9]+$/ {
- split($2, time, ":")
- seconds_current = time[1]
- seconds_total = time[2]
-
- hours = int(seconds_current / 60 / 60);
- secs_beyond_hours = seconds_current - (hours * 60 * 60);
- mins = int(secs_beyond_hours / 60);
- secs = secs_beyond_hours - (mins * 60);
- if (hours > 0) {
- current_time = sprintf("%d:%.2d:%.2d", hours, mins, secs)
- } else {
- current_time = sprintf("%.2d:%.2d", mins, secs)
- }
-
- if (seconds_total > 0) {
- time_percentage = (seconds_current / seconds_total) * 100
- current_percentage = sprintf("%d%%", time_percentage)
- } else {
- current_percentage = "~"
- }
- }
-
- END {
- printf(\
- "%s %s %s\n",
- status["state:"], current_time, current_percentage\
- )
- }
- '
+| "$dir_bin"/khatus_parse_mpd_status