2023-07-08 14:03:58 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
# Copyright (C) 2023-present BrooksyTech (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)
|
2023-07-09 19:52:58 +00:00
|
|
|
HP_GPIO=$(cat /sys/class/gpio/gpio${DEVICE_JACK}/value)
|
2023-07-08 14:03:58 +00:00
|
|
|
|
|
|
|
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")
|
2023-07-09 13:47:11 +00:00
|
|
|
amixer cset name='Speaker Switch' ${DEVICE_PLAYBACK_PATH_HP}
|
2023-07-08 14:03:58 +00:00
|
|
|
amixer set 'Headphone' '67%'
|
2023-07-09 13:47:11 +00:00
|
|
|
amixer set 'Playback Polarity' Normal
|
2023-07-08 14:03:58 +00:00
|
|
|
set_setting "audio.device" "headphone"
|
|
|
|
;;
|
|
|
|
*)
|
2023-07-09 13:47:11 +00:00
|
|
|
amixer cset name='Speaker Switch' ${DEVICE_PLAYBACK_PATH_SPK}
|
2023-07-08 14:03:58 +00:00
|
|
|
amixer set 'Headphone' '100%'
|
2023-07-09 13:47:11 +00:00
|
|
|
amixer set 'Playback Polarity' 'R Invert'
|
2023-07-08 14:03:58 +00:00
|
|
|
set_setting "audio.device" "speakers"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
systemctl restart weston
|
|
|
|
|
|
|
|
HDMI_VALUE=${HDMI_NEW_VALUE}
|
|
|
|
fi
|
|
|
|
sleep 5
|
|
|
|
done
|