2022-02-05 14:23:32 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2023-10-24 16:00:57 +00:00
|
|
|
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
|
2022-02-05 14:23:32 +00:00
|
|
|
|
2023-08-06 21:04:56 +00:00
|
|
|
## Load minimal distribution settings to improve
|
|
|
|
## performance.
|
2023-09-04 10:46:11 +00:00
|
|
|
. /etc/profile.d/001-functions
|
2022-04-17 13:10:47 +00:00
|
|
|
|
2023-08-05 18:21:23 +00:00
|
|
|
BRIGHTNESS_DEV="$(find /sys/class/backlight/*/ -name brightness -print -quit)"
|
|
|
|
BRIGHTNESS_PATH="${BRIGHTNESS_DEV%/brightness}"
|
2023-10-14 11:09:38 +00:00
|
|
|
|
|
|
|
declare -a BRIGHTNESS_TABLE
|
2023-10-03 19:53:21 +00:00
|
|
|
BRIGHTNESS_TABLE=($(get_setting brightness_table))
|
2023-10-14 11:09:38 +00:00
|
|
|
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[*]}"
|
2023-10-03 19:53:21 +00:00
|
|
|
fi
|
|
|
|
NUM_STEPS=${#BRIGHTNESS_TABLE[@]}
|
2022-04-17 13:10:47 +00:00
|
|
|
|
2023-08-05 18:21:23 +00:00
|
|
|
MAX=$(<$(find /sys/class/backlight/*/ -name max_brightness -print -quit))
|
2023-10-14 11:09:38 +00:00
|
|
|
function compute() {
|
|
|
|
echo "${BRIGHTNESS_TABLE[$NEXT]} * ${MAX}" | bc -l
|
2023-10-03 19:53:21 +00:00
|
|
|
}
|
2022-02-05 14:23:32 +00:00
|
|
|
|
2023-08-05 18:21:23 +00:00
|
|
|
if [ ! -f "${BRIGHTNESS_DEV}" ]
|
2022-02-05 14:23:32 +00:00
|
|
|
then
|
|
|
|
echo "ERROR: There is no BRIGHTNESS object to manage."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-08-05 18:21:23 +00:00
|
|
|
getBrightness() {
|
|
|
|
echo $(<${BRIGHTNESS_DEV})
|
|
|
|
}
|
|
|
|
|
|
|
|
setBrightness() {
|
|
|
|
echo "${1}" > ${BRIGHTNESS_DEV}
|
2023-08-06 11:52:46 +00:00
|
|
|
set_setting system.brightness "${2}"
|
2023-08-05 18:21:23 +00:00
|
|
|
}
|
|
|
|
|
2022-02-05 14:23:32 +00:00
|
|
|
stepUp() {
|
2023-08-06 11:52:46 +00:00
|
|
|
CURRENT=$(get_setting system.brightness)
|
|
|
|
NEXT=$(( ${CURRENT} + 1 ))
|
2023-10-03 19:53:21 +00:00
|
|
|
if (( ${NEXT} >= $NUM_STEPS ))
|
2022-02-05 14:23:32 +00:00
|
|
|
then
|
2023-10-03 19:53:21 +00:00
|
|
|
NEXT=$(( $NUM_STEPS - 1 ))
|
2022-02-05 14:23:32 +00:00
|
|
|
fi
|
2023-08-06 11:52:46 +00:00
|
|
|
|
2023-10-03 19:53:21 +00:00
|
|
|
BRIGHTNESS=$(printf '%.0f' "$(compute)")
|
|
|
|
if (($BRIGHTNESS > $MAX ))
|
|
|
|
then
|
|
|
|
BRIGHTNESS=$MAX
|
|
|
|
fi
|
2023-08-06 11:52:46 +00:00
|
|
|
|
|
|
|
setBrightness ${BRIGHTNESS} ${NEXT}
|
2022-02-05 14:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stepDown() {
|
2023-08-06 11:52:46 +00:00
|
|
|
CURRENT=$(get_setting system.brightness)
|
|
|
|
NEXT=$(( ${CURRENT} - 1 ))
|
|
|
|
if (( ${NEXT} < 0 ))
|
2022-02-05 14:23:32 +00:00
|
|
|
then
|
2023-08-06 11:52:46 +00:00
|
|
|
NEXT=0
|
2022-02-05 14:23:32 +00:00
|
|
|
fi
|
2023-08-06 11:52:46 +00:00
|
|
|
|
2023-10-03 19:53:21 +00:00
|
|
|
BRIGHTNESS=$(printf '%.0f' "$(compute)")
|
2023-08-06 11:52:46 +00:00
|
|
|
|
|
|
|
setBrightness ${BRIGHTNESS} ${NEXT}
|
2022-02-05 14:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case ${1} in
|
|
|
|
"up")
|
2023-08-05 18:21:23 +00:00
|
|
|
stepUp
|
2022-02-05 14:23:32 +00:00
|
|
|
;;
|
|
|
|
"down")
|
2023-08-05 18:21:23 +00:00
|
|
|
stepDown
|
2022-02-05 14:23:32 +00:00
|
|
|
;;
|
2022-08-31 12:30:58 +00:00
|
|
|
"device")
|
|
|
|
echo ${BRIGHTNESS_DEV}
|
|
|
|
;;
|
2023-08-05 18:21:23 +00:00
|
|
|
"path")
|
|
|
|
echo ${BRIGHTNESS_PATH}
|
|
|
|
;;
|
|
|
|
"set")
|
2023-10-03 19:53:21 +00:00
|
|
|
NEXT=${2}
|
|
|
|
setBrightness "$(printf '%.0f' "$(compute)")" ${2}
|
2023-08-05 18:21:23 +00:00
|
|
|
;;
|
2022-02-05 14:23:32 +00:00
|
|
|
*)
|
2023-08-05 18:21:23 +00:00
|
|
|
echo $(getBrightness)
|
|
|
|
;;
|
2022-02-05 14:23:32 +00:00
|
|
|
esac
|