69 lines
1.7 KiB
Bash
Executable file
69 lines
1.7 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
# Copyright (C) 2020-present Shanti Gilbert (https://github.com/shantigilbert)
|
|
# Copyright (C) 2020-present Fewtarius
|
|
|
|
# Source predefined functions and variables
|
|
. /etc/profile
|
|
|
|
round() {
|
|
awk -v val=$1 'BEGIN{print int((val+5/2)/5) * 5}'
|
|
}
|
|
|
|
if [ "${1}" == "toggleaudio" ];then
|
|
# Toggle audio output
|
|
CURRENTAUDIO=$(get_setting "audio.device")
|
|
case "${CURRENTAUDIO}" in
|
|
"headphone")
|
|
echo "setting speakers"
|
|
amixer -M cset name='Playback Path' ${DEVICE_PLAYBACK_PATH_SPK}
|
|
set_setting "audio.device" "speakers"
|
|
;;
|
|
"auto"|"speakers"|*)
|
|
echo "setting headphones"
|
|
amixer -M cset name='Playback Path' ${DEVICE_PLAYBACK_PATH_HP}
|
|
set_setting "audio.device" "headphone"
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
if [ "${1}" == "setaudio" ];then
|
|
# Set audio output second parameter is either headphones or speakers
|
|
case "${2}" in
|
|
"headphone")
|
|
echo "setting headphones"
|
|
amixer -M cset name='Playback Path' ${DEVICE_PLAYBACK_PATH_HP}
|
|
set_setting "audio.device" "headphone"
|
|
;;
|
|
"auto"|"speakers"|*)
|
|
echo "setting speakers"
|
|
amixer -M cset name='Playback Path' ${DEVICE_PLAYBACK_PATH_SPK}
|
|
set_setting "audio.device" "speakers"
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
if [ "${1}" == "vol" ];then
|
|
VOLSTEP=1
|
|
if [ -n "${3}" ]; then
|
|
VOLSTEP="${3}"
|
|
fi
|
|
|
|
CURRENTVOL=$(get_setting "audio.volume")
|
|
MAXVOL=100
|
|
MINVOL=0
|
|
if [ "${2}" == "+" ]; then
|
|
STEPVOL=$(($CURRENTVOL+$VOLSTEP))
|
|
elif [ "${2}" == "-" ]; then
|
|
STEPVOL=$(($CURRENTVOL-$VOLSTEP))
|
|
else
|
|
STEPVOL=${2}
|
|
fi
|
|
[ "$STEPVOL" -ge "$MAXVOL" ] && STEPVOL="$MAXVOL"
|
|
[ "$STEPVOL" -le "$MINVOL" ] && STEPVOL="$MINVOL"
|
|
amixer -M set "${DEVICE_AUDIO_MIXER}" ${STEPVOL}%
|
|
alsactl store -f /storage/.config/asound.state
|
|
set_setting "audio.volume" ${STEPVOL}
|
|
fi
|
|
|