From 28e418c8e73e35b46bb7428b007866a360e34629 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 25 Feb 2014 23:57:40 +0100 Subject: Rewrite of script to be called from acpi handler (listening to brightness up/down keys) --- bin/set_backlight | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/set_backlight b/bin/set_backlight index 00a6d8f..c110321 100755 --- a/bin/set_backlight +++ b/bin/set_backlight @@ -7,6 +7,50 @@ if [[ $EUID -ne 0 ]];then echo "This must be run as root." else + # get current and maximum brightness, set maximum steps allowed + brightness_current=$(cat /sys/class/backlight/intel_backlight/brightness) + brightness_max=$(cat /sys/class/backlight/intel_backlight/max_brightness) + brightness_max=$(($brightness_max-1000)) + brightness_steps=20 + brightness_steps_width=$(($brightness_max/$brightness_steps)) + brightness_new=0 + # if first parameter to this script is a number + re='^[0-9]+$' + if [[ $1 =~ $re ]]; then + echo "Direct step called" + if [[ $1 -gt brightness_steps && $1 -ne 0 ]];then + brightness_new=$(($1*brightness_steps_width)) + fi + elif [[ $1 == "up" || $1 == "down" ]];then + brightness_calc=$(($brightness_current / $brightness_steps_width)) + case $1 in + "up" ) + brightness_calc=$((($brightness_calc+1) * $brightness_steps_width)) + echo "brightness_calc: $brightness_calc" + echo "brightness_max: $brightness_max" + if [[ $brightness_max -gt $brightness_calc ]];then + echo "true" + brightness_new=$brightness_calc + else + echo "false" + brightness_new=$brightness_current + fi + ;; + "down" ) + brightness_calc=$((($brightness_calc-1) * $brightness_steps_width)) + echo "brightness_calc: $brightness_calc" + if [[ $brightness_calc -gt 0 ]];then + brightness_new=$brightness_calc + else + brightness_new=$brightness_current + fi + ;; + esac + echo "Step called with: $1" + fi + echo $brightness_current + echo $brightness_new # set to 234 (around 4th step) - echo 234 > /sys/class/backlight/intel_backlight/brightness + #echo 234 > /sys/class/backlight/intel_backlight/brightness + echo $brightness_new > /sys/class/backlight/intel_backlight/brightness fi -- cgit v1.2.3-70-g09d2