distribution/packages/sysutils/system-utils/sources/scripts/headphone_sense

50 lines
1.4 KiB
Text
Raw Normal View History

2022-08-31 01:26:25 +00:00
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2020-present Shanti Gilbert (https://github.com/shantigilbert)
# Copyright (C) 2021-present Fewtarius
2022-08-31 01:26:25 +00:00
# Source predefined functions and variables
. /etc/profile
# Switch to headphones if we have them already connected at boot
GPIO=$(cat /sys/class/gpio/gpio${DEVICE_JACK}/value)
[[ "$GPIO" == "0" ]] && set_setting "audio.device" "headphone" || set_setting "audio.device" "speakers"
### Set the default audio path, needed for some devices
if [ -z "${DEVICE_PLAYBACK_PATH}" ]
then
DEVICE_PLAYBACK_PATH="Playback Path"
fi
2023-08-06 21:17:45 +00:00
STARTUP_DEVICE=$(get_setting "audio.device")
case "${2}" in
"headphone")
2023-08-16 00:08:48 +00:00
amixer -c 0 -M cset name=${DEVICE_PLAYBACK_PATH} ${DEVICE_PLAYBACK_PATH_HP}
2023-08-06 21:17:45 +00:00
;;
"auto"|"speakers"|*)
2023-08-16 00:08:48 +00:00
amixer -c 0 -M cset name=${DEVICE_PLAYBACK_PATH} ${DEVICE_PLAYBACK_PATH_SPK}
2023-08-06 21:17:45 +00:00
;;
esac
/usr/bin/volume $(get_setting "audio.volume")
2022-08-31 01:26:25 +00:00
# Headphone sensing
DEVICE="${DEVICE_HEADPHONE_DEV}"
HP_ON='*(SW_HEADPHONE_INSERT), value 0*'
HP_OFF='*(SW_HEADPHONE_INSERT), value 1*'
evtest "${DEVICE}" | while read line; do
case $line in
(${HP_ON})
2023-08-16 00:08:48 +00:00
amixer -c 0 cset name=${DEVICE_PLAYBACK_PATH} ${DEVICE_PLAYBACK_PATH_HP}
2022-08-31 01:26:25 +00:00
set_setting "audio.device" "headphone"
;;
(${HP_OFF})
2023-08-16 00:08:48 +00:00
amixer -c 0 cset name=${DEVICE_PLAYBACK_PATH} ${DEVICE_PLAYBACK_PATH_SPK}
2022-08-31 01:26:25 +00:00
set_setting "audio.device" "speakers"
;;
esac
done