-#!/bin/sh
+#!/bin/bash
. /usr/bin/hvutils.sh
echo 0 > /sys/class/leds/status/brightness
}
+is_mpc_playing() {
+ if mpc | grep -q "\[playing\]"; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+keys_manager() {
+ while true; do
+ # 0 -> key pressed
+ # 10 -> key NOT pressed
+ evtest --query /dev/input/event5 EV_KEY KEY_PLAYPAUSE
+ play=$?
+
+ if [ "${play_prev}" != "${play}" -a ${play} -eq 0 ]; then
+ log_info "mpc toggle"
+ mpc toggle 1> /dev/null
+ fi
+
+ play_prev=${play}
+
+ if is_mpc_playing ; then
+ led_on
+ log_dbg "[playing]"
+ else
+ led_off
+ log_dbg "[paused]"
+ fi
+
+ sleep 0.1
+ done
+}
+
lcd_init
-while true; do
- # Future bouton play/pause:
- # mpc toggle -> pause/play/pause...
+# Start function in the background
+keys_manager &
+# Save PID
+pid=$!
+
+while true; do
# mpc -f "<%name%> <%title%> <%album%>" current
current="$(mpc current)"
log_dbg "current = ${current}"
- if [ "${current}" = "" ]; then
- led_off
- song=""
- artist=""
- else
- led_on
-
+ if is_mpc_playing ; then
# | awk '{$1=$1};1' --> trim spaces before and after
station="${current}"
log_dbg "artist = ${artist}"
fi
fi
+ else
+ song=""
+ artist=""
+
+ if [ "${station}" = "" ]; then
+ station="HVMPD"
+ fi
fi
station_prev="${station}"
sleep 1
done
+
+# Kill keys_manager
+kill ${pid} >/dev/null 2>&1