From 35893dfa7012832b40216209591c2ad48b722474 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Thu, 31 Oct 2024 01:26:00 -0400 Subject: [PATCH] hvmpd.sh: add keys --- .../hvmpd-manager/files/hvmpd.sh | 63 +++++++++++++++---- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/recipes-multimedia/hvmpd-manager/files/hvmpd.sh b/recipes-multimedia/hvmpd-manager/files/hvmpd.sh index daa427b..32bf889 100644 --- a/recipes-multimedia/hvmpd-manager/files/hvmpd.sh +++ b/recipes-multimedia/hvmpd-manager/files/hvmpd.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash . /usr/bin/hvutils.sh @@ -23,23 +23,54 @@ led_off() { 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}" @@ -75,6 +106,13 @@ while true; do log_dbg "artist = ${artist}" fi fi + else + song="" + artist="" + + if [ "${station}" = "" ]; then + station="HVMPD" + fi fi station_prev="${station}" @@ -98,3 +136,6 @@ while true; do sleep 1 done + +# Kill keys_manager +kill ${pid} >/dev/null 2>&1 -- 2.20.1