From e2f43d1fe749a5fe9263ac4a749b84962e5a98cb Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Mon, 28 Oct 2024 18:10:59 -0400 Subject: [PATCH] Add hvmpd daemon and service --- .../images/include/image-hvmpd-common.inc | 1 + .../hvmpd-manager/files/hvmpd.service | 10 ++ .../hvmpd-manager/files/hvmpd.sh | 100 ++++++++++++++++++ .../hvmpd-manager/hvmpd-manager.bb | 31 ++++++ 4 files changed, 142 insertions(+) create mode 100644 recipes-multimedia/hvmpd-manager/files/hvmpd.service create mode 100644 recipes-multimedia/hvmpd-manager/files/hvmpd.sh create mode 100644 recipes-multimedia/hvmpd-manager/hvmpd-manager.bb diff --git a/recipes-core/images/include/image-hvmpd-common.inc b/recipes-core/images/include/image-hvmpd-common.inc index e9ade7a..d8390a0 100644 --- a/recipes-core/images/include/image-hvmpd-common.inc +++ b/recipes-core/images/include/image-hvmpd-common.inc @@ -26,6 +26,7 @@ IMAGE_INSTALL:append = " \ mpc \ ympd \ shairport-sync \ + hvmpd-manager \ " # Needed by shairport-sync: diff --git a/recipes-multimedia/hvmpd-manager/files/hvmpd.service b/recipes-multimedia/hvmpd-manager/files/hvmpd.service new file mode 100644 index 0000000..ee3b41a --- /dev/null +++ b/recipes-multimedia/hvmpd-manager/files/hvmpd.service @@ -0,0 +1,10 @@ +[Unit] +Description=HVMPD daemon +After=network.target + +[Service] +ExecStart=/usr/sbin/hvmpd.sh +Restart=no + +[Install] +WantedBy=multi-user.target diff --git a/recipes-multimedia/hvmpd-manager/files/hvmpd.sh b/recipes-multimedia/hvmpd-manager/files/hvmpd.sh new file mode 100644 index 0000000..daa427b --- /dev/null +++ b/recipes-multimedia/hvmpd-manager/files/hvmpd.sh @@ -0,0 +1,100 @@ +#!/bin/sh + +. /usr/bin/hvutils.sh + +fill=" " + +l1="HVMPD" +l2="" +l3="" +l4="" + +# Previous line variables: +l1p="" +l2p="" +l3p="" +l4p="" + +led_on() { + cat /sys/class/leds/status/max_brightness > /sys/class/leds/status/brightness +} + +led_off() { + echo 0 > /sys/class/leds/status/brightness +} + +lcd_init + +while true; do + # Future bouton play/pause: + # mpc toggle -> pause/play/pause... + + # mpc -f "<%name%> <%title%> <%album%>" current + current="$(mpc current)" + log_dbg "current = ${current}" + + if [ "${current}" = "" ]; then + led_off + song="" + artist="" + else + led_on + + # | awk '{$1=$1};1' --> trim spaces before and after + + station="${current}" + + if echo "${current}" | grep -q -e "http" ; then + station="${current}" + elif echo "${current}" | grep -q -e ":" ; then + station="$(echo ${current} | awk -F: '{print $1}' | awk '{$1=$1};1')" + fi + + song="$(echo ${current} | awk -F: '{print $2}' | awk '{$1=$1};1')" + + if [ "${station}" != "${station_prev}" -o \ + "${song}" != "${song_prev}" ]; then + + log_dbg "station = ${station}" + + l1="${station}" + + if [ "${song}" != "${station}" ]; then + log_dbg "song = ${song}" + + if echo "${song}" | grep -q -e "---" ; then + artist="$(echo ${song} | sed "s@\(^.*\)---.*@\1@")" + song="$(echo ${song} | sed "s@^.*---\(.*\)@\1@")" + elif echo "${song}" | grep -q -e " - " ; then + artist="$(echo ${song} | sed "s@\(^.*\) - .*@\1@")" + song="$(echo ${song} | sed "s@^.* - \(.*\)@\1@")" + else + artist="" + fi + + log_dbg "artist = ${artist}" + fi + fi + fi + + station_prev="${station}" + song_prev="${song}" + artist_prev="${artist}" + + l1="${station}" + + if [ "${artist}" != "" ]; then + l2="${artist}" + l4="${song}" + else + l2="${song}${fill}" + l4="$(printf "%.20s\n" "${l2:20}")" + fi + + # Bug, écran défectueux ligne 3... + l3="" + + lcd_update + + sleep 1 +done diff --git a/recipes-multimedia/hvmpd-manager/hvmpd-manager.bb b/recipes-multimedia/hvmpd-manager/hvmpd-manager.bb new file mode 100644 index 0000000..49e1cb4 --- /dev/null +++ b/recipes-multimedia/hvmpd-manager/hvmpd-manager.bb @@ -0,0 +1,31 @@ +DESCRIPTION = "hvmpd daemon" +SECTION = "multimedia" +LICENSE = "GPL-2.0-only" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0-only;md5=801f80980d171dd6425610833a22dbe6" + +PV = "0.0.1" + +SRC_URI = "\ + file://hvmpd.service \ + file://hvmpd.sh \ +" + +RDEPENDS:${PN} += "bash hvutils" + +inherit systemd + +do_install() { + install -d ${D}${sbindir} + install -m 0755 ${WORKDIR}/hvmpd.sh ${D}${sbindir} + + install -d ${D}${systemd_unitdir}/system + install -m 0644 ${WORKDIR}/hvmpd.service ${D}${systemd_unitdir}/system +} + +FILES:${PN} = " \ + ${systemd_unitdir}/system/hvmpd.service \ + ${sbindir}/hvmpd.sh \ +" + +SYSTEMD_AUTO_ENABLE = "enable" +SYSTEMD_SERVICE:${PN} = "hvmpd.service" -- 2.20.1