Merge pull request #1888 from fewtarius/dev
Split volume from system_utils and improve its performance.
This commit is contained in:
commit
1ad56336b2
5 changed files with 43 additions and 40 deletions
|
@ -2,6 +2,9 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
# Copyright (C) 2020-present Fewtarius
|
||||
|
||||
## Load minimal distribution settings to improve
|
||||
## performance.
|
||||
. /etc/profile.d/02-distribution
|
||||
|
||||
BRIGHTNESS_DEV="$(find /sys/class/backlight/*/ -name brightness -print -quit)"
|
||||
BRIGHTNESS_PATH="${BRIGHTNESS_DEV%/brightness}"
|
||||
|
@ -10,12 +13,6 @@ MIN=0
|
|||
MAX=$(<$(find /sys/class/backlight/*/ -name max_brightness -print -quit))
|
||||
STEP="$(echo "scale=1; (${MAX} / 10)" | bc)"
|
||||
|
||||
# Ensure set_setting exists in all contexts
|
||||
if ! type set_setting &>/dev/null
|
||||
then
|
||||
source /etc/profile
|
||||
fi
|
||||
|
||||
if [ ! -f "${BRIGHTNESS_DEV}" ]
|
||||
then
|
||||
echo "ERROR: There is no BRIGHTNESS object to manage."
|
||||
|
|
38
packages/jelos/sources/scripts/volume
Normal file
38
packages/jelos/sources/scripts/volume
Normal file
|
@ -0,0 +1,38 @@
|
|||
#!/bin/sh
|
||||
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
# Copyright (C) 2023-present Fewtarius
|
||||
|
||||
|
||||
# Source minimal predefined functions and variables
|
||||
# to ensure as much performance as possible.
|
||||
. /etc/profile.d/02-distribution
|
||||
|
||||
VOLUME=$(get_setting "audio.volume")
|
||||
MAX_VOLUME=100
|
||||
MIN_VOLUME=0
|
||||
STEP=10
|
||||
|
||||
case ${1} in
|
||||
"+"|"up")
|
||||
VOLUME=$(( ${VOLUME} + ${STEP} ))
|
||||
;;
|
||||
"-"|"down")
|
||||
VOLUME=$(( ${VOLUME} - ${STEP} ))
|
||||
;;
|
||||
*)
|
||||
VOLUME=${1}
|
||||
;;
|
||||
esac
|
||||
|
||||
if (( ${VOLUME} < ${MIN_VOLUME} ))
|
||||
then
|
||||
VOLUME=${MIN_VOLUME}
|
||||
elif (( ${VOLUME} > ${MAX_VOLUME} ))
|
||||
then
|
||||
VOLUME=${MAX_VOLUME}
|
||||
fi
|
||||
|
||||
amixer set "${DEVICE_AUDIO_MIXER}" ${VOLUME}%
|
||||
alsactl store -f /storage/.config/asound.state
|
||||
set_setting "audio.volume" ${VOLUME}
|
|
@ -13,7 +13,7 @@ GPIO=$(cat /sys/class/gpio/gpio${DEVICE_JACK}/value)
|
|||
|
||||
if [ -e "/storage/.config/system/configs/system.cfg" ]; then
|
||||
/usr/bin/system_utils setaudio $(get_setting "audio.device")
|
||||
/usr/bin/system_utils vol $(get_setting "audio.volume")
|
||||
/usr/bin/volume $(get_setting "audio.volume")
|
||||
fi
|
||||
|
||||
# Headphone sensing
|
||||
|
|
|
@ -7,10 +7,6 @@
|
|||
# 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")
|
||||
|
@ -44,31 +40,3 @@ if [ "${1}" == "setaudio" ];then
|
|||
esac
|
||||
fi
|
||||
|
||||
if [ "${1}" == "vol" ];then
|
||||
CURRENTVOL=$(get_setting "audio.volume")
|
||||
MAXVOL=100
|
||||
MINVOL=0
|
||||
VOLSTEP=10
|
||||
|
||||
[ "$CURRENTVOL" -ge "$MAXVOL" ] && CURRENTVOL="$MAXVOL"
|
||||
[ "$CURRENTVOL" -le "$MINVOL" ] && CURRENTVOL="$MINVOL"
|
||||
|
||||
case ${2} in
|
||||
"+")
|
||||
STEPVOL=$(( $CURRENTVOL + $VOLSTEP ))
|
||||
;;
|
||||
"-")
|
||||
STEPVOL=$(( $CURRENTVOL - $VOLSTEP ))
|
||||
;;
|
||||
*)
|
||||
STEPVOL=${2}
|
||||
;;
|
||||
esac
|
||||
|
||||
[ "$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
|
||||
|
|
|
@ -148,7 +148,7 @@ mkcontroller 2>/dev/null ||:
|
|||
fi
|
||||
else
|
||||
# Default to 'volume' if Fn a or b is not pressed
|
||||
COMMAND="/usr/bin/system_utils vol"
|
||||
COMMAND="/usr/bin/volume"
|
||||
UP="+"
|
||||
DOWN="-"
|
||||
REPEAT_MOD=${VOLUME_REPEAT_MOD}
|
||||
|
|
Loading…
Reference in a new issue