2022-02-05 14:23:32 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
# Copyright (C) 2020-present Fewtarius
|
|
|
|
|
2022-10-02 00:22:43 +00:00
|
|
|
BRIGHTNESS_DEV="$(ls /sys/class/backlight | head -n 1)"
|
2022-04-17 13:10:47 +00:00
|
|
|
|
2022-09-29 20:44:45 +00:00
|
|
|
MIN=1
|
2022-08-31 11:00:57 +00:00
|
|
|
MAX=$(cat /sys/class/backlight/${BRIGHTNESS_DEV}/max_brightness)
|
2022-04-17 13:10:47 +00:00
|
|
|
if [ "${MAX}" = 255 ]
|
|
|
|
then
|
2022-09-29 20:44:45 +00:00
|
|
|
STEP=17
|
2022-04-17 13:10:47 +00:00
|
|
|
else
|
2022-09-29 20:44:45 +00:00
|
|
|
STEP=6
|
2022-04-17 13:10:47 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n "$2" ]]; then
|
|
|
|
STEP=$2
|
2022-02-05 14:23:32 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Ensure set_setting exists in all contexts
|
|
|
|
if ! type set_setting &>/dev/null
|
|
|
|
then
|
|
|
|
source /etc/profile
|
|
|
|
fi
|
|
|
|
|
2022-08-31 11:00:57 +00:00
|
|
|
if [ ! -f /sys/class/backlight/${BRIGHTNESS_DEV}/brightness ]
|
2022-02-05 14:23:32 +00:00
|
|
|
then
|
|
|
|
echo "ERROR: There is no BRIGHTNESS object to manage."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
stepUp() {
|
|
|
|
getBrightness
|
|
|
|
MYBRIGHTNESS=$?
|
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
|
2022-08-31 11:00:57 +00:00
|
|
|
echo "${NEWBRIGHTNESS}" > /sys/class/backlight/${BRIGHTNESS_DEV}/brightness
|
2022-02-05 14:23:32 +00:00
|
|
|
set_setting system.brightness ${NEWBRIGHTNESS}
|
|
|
|
}
|
|
|
|
|
|
|
|
stepDown() {
|
|
|
|
getBrightness
|
|
|
|
MYBRIGHTNESS=$?
|
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
|
2022-08-31 11:00:57 +00:00
|
|
|
echo "${NEWBRIGHTNESS}" > /sys/class/backlight/${BRIGHTNESS_DEV}/brightness
|
2022-02-05 14:23:32 +00:00
|
|
|
set_setting system.brightness ${NEWBRIGHTNESS}
|
|
|
|
}
|
|
|
|
getBrightness() {
|
2022-08-31 11:00:57 +00:00
|
|
|
local BRIGHTNESS=$(cat /sys/class/backlight/${BRIGHTNESS_DEV}/brightness)
|
2022-02-05 14:23:32 +00:00
|
|
|
return ${BRIGHTNESS}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case ${1} in
|
|
|
|
"up")
|
|
|
|
stepUp ${BRIGHTNESS}
|
|
|
|
;;
|
|
|
|
"down")
|
|
|
|
stepDown ${BRIGHTNESS}
|
|
|
|
;;
|
2022-08-31 12:30:58 +00:00
|
|
|
"device")
|
|
|
|
echo ${BRIGHTNESS_DEV}
|
|
|
|
;;
|
2022-02-05 14:23:32 +00:00
|
|
|
*)
|
|
|
|
getBrightness
|
|
|
|
echo $?
|
|
|
|
;;
|
|
|
|
esac
|