Add initial version
This version is semi-tuned to give reasonable brightness.
This commit is contained in:
commit
583e3447a4
89
brightness.sh
Executable file
89
brightness.sh
Executable file
@ -0,0 +1,89 @@
|
||||
#!/bin/bash
|
||||
|
||||
max=$(cat /sys/class/backlight/intel_backlight/max_brightness)
|
||||
|
||||
sensitivity=$((max/90))
|
||||
|
||||
treshold=$((max/4))
|
||||
|
||||
panOut=$((sensitivity/4))
|
||||
|
||||
min=$((max/10))
|
||||
|
||||
delay=2
|
||||
|
||||
minSensor=404334
|
||||
|
||||
|
||||
while [ 1 ]
|
||||
do
|
||||
updated=1
|
||||
while [ $updated -gt 0 ]
|
||||
do
|
||||
updated=0
|
||||
backlight=$(cat /sys/class/backlight/intel_backlight/brightness)
|
||||
sensor=$(cat /sys/bus/iio/devices/iio:device0/in_illuminance_raw)
|
||||
# Scale the sensor a bit
|
||||
sensor=$((sensor/10))
|
||||
sensor=$((5*sensor))
|
||||
target=$backlight
|
||||
|
||||
echo Current backlight: $backlight
|
||||
echo Max backlight: $max
|
||||
echo Sensitivity is: $sensitivity
|
||||
echo Threshold is: $treshold
|
||||
echo panOut is: $panOut
|
||||
echo min is: $min
|
||||
echo Current sensor reading: $sensor
|
||||
echo Target is: $backlight
|
||||
|
||||
if [ $sensor -lt $treshold ]
|
||||
then
|
||||
echo Sensor was less than backlight
|
||||
sensor=$(((sensor+panOut)+min))
|
||||
echo New sensor: $sensor
|
||||
fi
|
||||
|
||||
|
||||
|
||||
if [ $sensor -gt $((backlight+sensitivity)) ]
|
||||
then
|
||||
echo Sensor was greater than backlight+sensitivity
|
||||
updated=1
|
||||
target=$((target+(sensitivity/2)))
|
||||
echo New target: $target
|
||||
fi
|
||||
|
||||
|
||||
if [ $sensor -lt $((backlight-sensitivity)) ]
|
||||
then
|
||||
echo Sensor was less than backlight-sensitivity
|
||||
updated=1
|
||||
target=$((target-(sensitivity/2)))
|
||||
echo New target: $target
|
||||
fi
|
||||
|
||||
|
||||
if [ $target -gt $max ]
|
||||
then
|
||||
echo Target was greater than max brightness
|
||||
target=$max
|
||||
echo New target: $target
|
||||
fi
|
||||
|
||||
if [ $target -lt 1 ]
|
||||
then
|
||||
echo Target was less than 1
|
||||
target=$min
|
||||
echo New target: $target
|
||||
fi
|
||||
|
||||
if [ $updated -gt 0 ]
|
||||
then
|
||||
echo $target > /sys/class/backlight/intel_backlight/brightness
|
||||
fi
|
||||
|
||||
done
|
||||
echo Sleeping
|
||||
sleep $delay
|
||||
done
|
Loading…
Reference in New Issue
Block a user