#!/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' SPK set_setting "audio.device" "speakers" ;; "auto"|"speakers"|*) echo "setting headphones" amixer -M 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 -M cset name='Playback Path' HP set_setting "audio.device" "headphone" ;; "auto"|"speakers"|*) echo "setting speakers" amixer -M 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 -M set "${DEVICE_AUDIO_MIXER}" ${STEPVOL}% alsactl store -f /storage/.config/asound.state set_setting "audio.volume" ${STEPVOL} fi if [ "${1}" == "bright" ]; then STEPS="5" BRIGHTNESS_DEV="$(ls /sys/class/backlight)" CURRENTBRIGHT=$(cat /sys/class/backlight/${BRIGHTNESS_DEV}/brightness) MAXBRIGHT="100" #$(cat /sys/class/backlight/${BRIGHTNESS_DEV}/max_brightness) MINBRIGHT="2" if [ "${2}" == "+" ]; then STEPBRIGHT=$(($CURRENTBRIGHT+$(round $STEPS))) elif [ "${2}" == "-" ]; then STEPBRIGHT=$(($CURRENTBRIGHT-$(round $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/${BRIGHTNESS_DEV}/brightness set_setting "system.brightness" $(cat /sys/class/backlight/${BRIGHTNESS_DEV}/brightness) fi