From bdd782d69df442074902372937735f229b9dd5a1 Mon Sep 17 00:00:00 2001 From: steel99xl Date: Sun, 24 Sep 2023 17:22:54 -0400 Subject: [PATCH] Stop,Start,Kill Now you can Stop, Start or even Kill the script by simply putting a file in /tmp --- AutomaticBrightness.sh | 85 +++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 34 deletions(-) diff --git a/AutomaticBrightness.sh b/AutomaticBrightness.sh index 9d0e4b0..ccd18b7 100644 --- a/AutomaticBrightness.sh +++ b/AutomaticBrightness.sh @@ -9,44 +9,61 @@ MinimumBrightness=001 SensorToDisplayScale=24 -while true; do -Light=$(cat /sys/bus/iio/devices/iio\:device0/in_illuminance_raw) +touch '/tmp/AB.running' -CurrentBrightness=$(cat /sys/class/backlight/intel_backlight/brightness) - - -Light=$(( $Light + $MinimumBrightness )) - - -TempLight=$(($Light * $SensorToDisplayScale)) - -if [[ $TempLight -gt $MaxScreenBrightness ]] -then - NewLight=$MaxScreenBrightness -else - NewLight=$TempLight -fi - -DiffCount=$(( ($NewLight - $CurrentBrightness)/$LevelSteps )) - -for i in $(eval echo {1..$LevelSteps} ) +until [ -f /tmp/AB.kill ] do - - NewLight=$(( $DiffCount )) - - if [[ $NewLight -lt 0 ]] + if [[ -f /tmp/AB.stop ]] then - NewLight=$( echo "$NewLight" | awk -F "-" {'print$2'}) - NewLight=$(echo $NewLight-) + rm '/tmp/AB.stop' + rm '/tmp/AB.running' + + until [[ -f /tmp/AB.start ]] + do + sleep 10 + done + rm '/tmp/AB.start' + touch '/tmp/AB.running' else - NewLight=$(echo +$NewLight) - fi + Light=$(cat /sys/bus/iio/devices/iio\:device0/in_illuminance_raw) - brightnessctl -q s $NewLight - sleep $AnimationDelay - -done - -sleep $SensorDelay + CurrentBrightness=$(cat /sys/class/backlight/intel_backlight/brightness) + + + Light=$(( $Light + $MinimumBrightness )) + + + TempLight=$(($Light * $SensorToDisplayScale)) + + if [[ $TempLight -gt $MaxScreenBrightness ]] + then + NewLight=$MaxScreenBrightness + else + NewLight=$TempLight + fi + + DiffCount=$(( ($NewLight - $CurrentBrightness)/$LevelSteps )) + + for i in $(eval echo {1..$LevelSteps} ) + do + + NewLight=$(( $DiffCount )) + + if [[ $NewLight -lt 0 ]] + then + NewLight=$( echo "$NewLight" | awk -F "-" {'print$2'}) + NewLight=$(echo $NewLight-) + else + NewLight=$(echo +$NewLight) + fi + + brightnessctl -q s $NewLight + sleep $AnimationDelay + + done + + sleep $SensorDelay + fi done +rm '/tmp/AutoBright.kill'