38 lines
1 KiB
Bash
38 lines
1 KiB
Bash
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
# Copyright (C) 2022-present - The JELOS Project (https://github.com/JustEnoughLinuxOS)
|
|
|
|
. /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
|
|
|
|
HDMI=$(pactl list sinks short | grep hdmi | cut -c 0-2)
|
|
SPEAKER=$(pactl list sinks short | grep es8316 | cut -c 0-2)
|
|
|
|
# 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)
|
|
|
|
if test "${HDMI_VALUE}" != "${HDMI_NEW_VALUE}"
|
|
then
|
|
case ${HDMI_NEW_VALUE} in
|
|
"0") #HDMI plugged
|
|
pactl set-default-sink ${HDMI}
|
|
;;
|
|
"1") #HDMI unpluagged
|
|
pactl set-default-sink ${SPEAKER}
|
|
;;
|
|
esac
|
|
systemctl restart weston
|
|
|
|
HDMI_VALUE=${HDMI_NEW_VALUE}
|
|
fi
|
|
sleep 5
|
|
done
|