distribution/packages/sysutils/system-utils/sources/devices/S922X/headphone_sense
2023-10-24 13:59:09 +00:00

39 lines
1.2 KiB
Bash

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2022-present - The JELOS Project (https://github.com/JustEnoughLinuxOS)
# Source predefined functions and variables
. /etc/profile
[ -z "${DEVICE_PLAYBACK_PATH}" -o -z "${DEVICE_PLAYBACK_PATH_HP}" -o -z "${DEVICE_PLAYBACK_PATH_SPK}" ] && exit 0
### Set correct audio output device at boot.
HEADPHONE_STATE=$(cat /sys/kernel/debug/gpio | grep HEADPHONE)
if [[ "${HEADPHONE_STATE}" == *"hi"* ]]; then
amixer -c0 sset "${DEVICE_PLAYBACK_PATH}" "${DEVICE_PLAYBACK_PATH_HP}"
set_setting "audio.device" "headphone"
else
amixer -c0 sset "${DEVICE_PLAYBACK_PATH}" "${DEVICE_PLAYBACK_PATH_SPK}"
set_setting "audio.device" "speakers"
fi
# Headphone sensing
DEVICE="${DEVICE_HEADPHONE_DEV}"
HP_ON='*(SW_HEADPHONE_INSERT), value 1*'
HP_OFF='*(SW_HEADPHONE_INSERT), value 0*'
evtest "${DEVICE}" | while read line; do
case $line in
(${HP_ON})
amixer -c0 sset "${DEVICE_PLAYBACK_PATH}" "${DEVICE_PLAYBACK_PATH_HP}"
set_setting "audio.device" "headphone"
;;
(${HP_OFF})
amixer -c0 sset "${DEVICE_PLAYBACK_PATH}" "${DEVICE_PLAYBACK_PATH_SPK}"
set_setting "audio.device" "speakers"
;;
esac
done