90 lines
1.9 KiB
Bash
Executable file
90 lines
1.9 KiB
Bash
Executable file
#!/bin/bash
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
|
|
|
|
## Load minimal distribution settings to improve
|
|
## performance.
|
|
. /etc/profile.d/001-functions
|
|
|
|
BRIGHTNESS_DEV="$(find /sys/class/backlight/*/ -name brightness -print -quit)"
|
|
BRIGHTNESS_PATH="${BRIGHTNESS_DEV%/brightness}"
|
|
|
|
declare -a BRIGHTNESS_TABLE
|
|
BRIGHTNESS_TABLE=($(get_setting brightness_table))
|
|
if [ -z ${BRIGHTNESS_TABLE} ]; then
|
|
BRIGHTNESS_TABLE=(0 0.04 0.08 0.13 0.19 0.25 0.33 0.42 0.54 0.71 1)
|
|
set_setting brightness_table "${BRIGHTNESS_TABLE[*]}"
|
|
fi
|
|
NUM_STEPS=${#BRIGHTNESS_TABLE[@]}
|
|
|
|
MAX=$(<$(find /sys/class/backlight/*/ -name max_brightness -print -quit))
|
|
function compute() {
|
|
echo "${BRIGHTNESS_TABLE[$NEXT]} * ${MAX}" | bc -l
|
|
}
|
|
|
|
if [ ! -f "${BRIGHTNESS_DEV}" ]
|
|
then
|
|
echo "ERROR: There is no BRIGHTNESS object to manage."
|
|
exit 1
|
|
fi
|
|
|
|
getBrightness() {
|
|
echo $(<${BRIGHTNESS_DEV})
|
|
}
|
|
|
|
setBrightness() {
|
|
echo "${1}" > ${BRIGHTNESS_DEV}
|
|
set_setting system.brightness "${2}"
|
|
}
|
|
|
|
stepUp() {
|
|
CURRENT=$(get_setting system.brightness)
|
|
NEXT=$(( ${CURRENT} + 1 ))
|
|
if (( ${NEXT} >= $NUM_STEPS ))
|
|
then
|
|
NEXT=$(( $NUM_STEPS - 1 ))
|
|
fi
|
|
|
|
BRIGHTNESS=$(printf '%.0f' "$(compute)")
|
|
if (($BRIGHTNESS > $MAX ))
|
|
then
|
|
BRIGHTNESS=$MAX
|
|
fi
|
|
|
|
setBrightness ${BRIGHTNESS} ${NEXT}
|
|
}
|
|
|
|
stepDown() {
|
|
CURRENT=$(get_setting system.brightness)
|
|
NEXT=$(( ${CURRENT} - 1 ))
|
|
if (( ${NEXT} < 0 ))
|
|
then
|
|
NEXT=0
|
|
fi
|
|
|
|
BRIGHTNESS=$(printf '%.0f' "$(compute)")
|
|
|
|
setBrightness ${BRIGHTNESS} ${NEXT}
|
|
}
|
|
|
|
case ${1} in
|
|
"up")
|
|
stepUp
|
|
;;
|
|
"down")
|
|
stepDown
|
|
;;
|
|
"device")
|
|
echo ${BRIGHTNESS_DEV}
|
|
;;
|
|
"path")
|
|
echo ${BRIGHTNESS_PATH}
|
|
;;
|
|
"set")
|
|
NEXT=${2}
|
|
setBrightness "$(printf '%.0f' "$(compute)")" ${2}
|
|
;;
|
|
*)
|
|
echo $(getBrightness)
|
|
;;
|
|
esac
|