distribution/projects/Rockchip/packages/system-utils/sources/scripts/system_utils

87 lines
2.2 KiB
Text
Raw Normal View History

2022-02-05 14:23:32 +00:00
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2020-present Shanti Gilbert (https://github.com/shantigilbert)
# THESE NEEDS TO BE CLEANED UP, MAYBE WITH CASE OR FUNCTIONS
# Source predefined functions and variables
. /etc/profile
if [ "${1}" == "toggleaudio" ];then
# Toggle audio output
CURRENTAUDIO=$(get_setting "audio.device")
case "${CURRENTAUDIO}" in
"headphone")
echo "setting speakers"
amixer cset name='Playback Path' SPK
set_setting "audio.device" "speakers"
;;
"auto"|"speakers"|*)
echo "setting headphones"
amixer cset name='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 cset name='Playback Path' HP
set_setting "audio.device" "headphone"
;;
"auto"|"speakers"|*)
echo "setting speakers"
amixer cset name='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 set "${DEVICE_AUDIO_MIXER}" ${STEPVOL}%
alsactl store -f /storage/.config/asound.state
set_setting "audio.volume" ${STEPVOL}
fi
if [ "${1}" == "bright" ]; then
STEPS="5"
CURRENTBRIGHT=$(cat /sys/class/backlight/backlight/brightness)
MAXBRIGHT="100" #$(cat /sys/class/backlight/backlight/max_brightness)
MINBRIGHT="2"
if [ "${2}" == "+" ]; then
STEPBRIGHT=$(($CURRENTBRIGHT+$STEPS))
elif [ "${2}" == "-" ]; then
STEPBRIGHT=$(($CURRENTBRIGHT-$STEPS))
else
STEPBRIGHT=${2}
fi
[ "$STEPBRIGHT" -ge "$MAXBRIGHT" ] && STEPBRIGHT="$MAXBRIGHT"
[ "$STEPBRIGHT" -le "$MINBRIGHT" ] && STEPBRIGHT="$MINBRIGHT"
#echo "Setting bright to $STEPBRIGHT"
echo "${STEPBRIGHT}" > /sys/class/backlight/backlight/brightness
set_setting "system.brightness" $(cat /sys/class/backlight/backlight/brightness)
fi