aboutsummaryrefslogtreecommitdiffstats
path: root/bin/set_backlight
diff options
context:
space:
mode:
Diffstat (limited to 'bin/set_backlight')
-rwxr-xr-xbin/set_backlight56
1 files changed, 56 insertions, 0 deletions
diff --git a/bin/set_backlight b/bin/set_backlight
new file mode 100755
index 0000000..c110321
--- /dev/null
+++ b/bin/set_backlight
@@ -0,0 +1,56 @@
+#!/bin/bash
+# Script to set backlight on startup on Lenovo W540 using
+# /sys/class/backlight/intel_backlight/brightness
+# This must be run as root.
+
+# check if root
+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 $brightness_new > /sys/class/backlight/intel_backlight/brightness
+fi