#!/bin/bash # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (C) 2022-present - The JELOS Project (https://github.com/JustEnoughLinuxOS) (https://github.com/brooksytech) . /etc/profile # Set export GPIO for HDMI if [ ! -d "/sys/class/gpio/gpio${DEVICE_HDMI_GPIO}" ]; then echo ${DEVICE_HDMI_GPIO} > /sys/class/gpio/export echo in > /sys/class/gpio/gpio${DEVICE_HDMI_GPIO}/direction fi # Check HDMI plugged / unplugged, set audio output, restart Emulation Station HDMI_VALUE=$(cat /sys/class/gpio/gpio${DEVICE_HDMI_GPIO}/value) while true do HDMI_NEW_VALUE=$(cat /sys/class/gpio/gpio${DEVICE_HDMI_GPIO}/value) HP_GPIO=$(cat /sys/class/gpio/gpio${DEVICE_JACK}/value) if test "${HDMI_VALUE}" != "${HDMI_NEW_VALUE}" then case ${HDMI_NEW_VALUE} in "0") #HDMI plugged sed -i 's/pcm "hw:0,0"/pcm "hw:1,0"/' /storage/.config/asound.conf ;; "1") #HDMI unpluagged sed -i 's/pcm "hw:1,0"/pcm "hw:0,0"/' /storage/.config/asound.conf case ${HP_GPIO} in "1") amixer -c 0 cset name='Speaker Switch' ${DEVICE_PLAYBACK_PATH_HP} amixer -c 0 set 'Headphone' '67%' amixer -c 0 set 'Playback Polarity' Normal set_setting "audio.device" "headphone" ;; *) amixer -c 0 cset name='Speaker Switch' ${DEVICE_PLAYBACK_PATH_SPK} amixer -c 0 set 'Headphone' '100%' amixer -c 0 set 'Playback Polarity' 'R Invert' set_setting "audio.device" "speakers" ;; esac ;; esac systemctl restart weston HDMI_VALUE=${HDMI_NEW_VALUE} fi sleep 5 done