2022-02-05 14:23:32 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
# Copyright (C) 2020-present Fewtarius
|
|
|
|
|
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}"
|
2022-04-17 13:10:47 +00:00
|
|
|
|
2023-08-05 18:21:23 +00:00
|
|
|
MIN=0
|
|
|
|
MAX=$(<$(find /sys/class/backlight/*/ -name max_brightness -print -quit))
|
|
|
|
STEP=$(( ${MAX} / 10 ))
|
2022-02-05 14:23:32 +00:00
|
|
|
|
|
|
|
# Ensure set_setting exists in all contexts
|
|
|
|
if ! type set_setting &>/dev/null
|
|
|
|
then
|
|
|
|
source /etc/profile
|
|
|
|
fi
|
|
|
|
|
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}
|
|
|
|
set_setting system.brightness "$(( ${1} / ${STEP} ))"
|
|
|
|
}
|
|
|
|
|
2022-02-05 14:23:32 +00:00
|
|
|
stepUp() {
|
2023-08-05 18:21:23 +00:00
|
|
|
MYBRIGHTNESS=$(getBrightness)
|
2022-09-29 20:44:45 +00:00
|
|
|
NEWBRIGHTNESS=$((${MYBRIGHTNESS}+${STEP}))
|
2022-02-05 14:23:32 +00:00
|
|
|
if (( ${NEWBRIGHTNESS} > ${MAX} ))
|
|
|
|
then
|
|
|
|
NEWBRIGHTNESS=${MAX}
|
|
|
|
fi
|
2023-08-05 18:21:23 +00:00
|
|
|
setBrightness ${NEWBRIGHTNESS}
|
2022-02-05 14:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stepDown() {
|
2023-08-05 18:21:23 +00:00
|
|
|
MYBRIGHTNESS=$(getBrightness)
|
2022-09-29 20:44:45 +00:00
|
|
|
NEWBRIGHTNESS=$((${MYBRIGHTNESS}-${STEP}))
|
2022-02-05 14:23:32 +00:00
|
|
|
if (( ${NEWBRIGHTNESS} < ${MIN} ))
|
|
|
|
then
|
|
|
|
NEWBRIGHTNESS=${MIN}
|
|
|
|
fi
|
2023-08-05 18:21:23 +00:00
|
|
|
setBrightness ${NEWBRIGHTNESS}
|
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")
|
|
|
|
setBrightness "$(( ${STEP} * ${2} ))"
|
|
|
|
;;
|
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
|