From 7635064471aa6b0cb11d9146bf7a330cedf4a4cd Mon Sep 17 00:00:00 2001 From: steel99xl Date: Sat, 10 Feb 2024 11:10:12 -0500 Subject: [PATCH] setup.sh now automatically configures your SensorToDisplayScale and writes it to AutomaticBrightness.sh setup.sh now can update your service and script file along with restarting the service --- AB.service | 2 +- README.md | 14 +++++++++----- setup.sh | 43 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/AB.service b/AB.service index ff5d542..812aabe 100644 --- a/AB.service +++ b/AB.service @@ -1,5 +1,5 @@ [Unit] -Description=Mac like automatic brightness as service +Description=Mac-like-automatic-brightness as service [Service] Type=simple diff --git a/README.md b/README.md index b9faf48..478b5c8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Mac-like-automatic-brightness A simple script to provide a "Mac" like automatic brightness adjustemnt/ animation. ## Now as a system service -Run ```setup.sh``` to make it a service +Run ```setup.sh``` to make it a service and automaticaly set your ```SensorToDisplacScale``` made for the FrameWork laptop @@ -30,6 +30,8 @@ Your sensor has a diffrent range thant the 12th Gen Intel Framework laptop senso ```/dev/shm/AB.offset | Stores current offset for the sensor``` +* Changing the offset of your backlight while the service is running is one way you increase or decease your screen bightness but keep the automatic adjustments when the lighting changes + ## Configuring @@ -41,14 +43,16 @@ Your sensor has a diffrent range thant the 12th Gen Intel Framework laptop senso ```LevelSteps``` Sets amount of brightness steps, recomended to match refeshrate -```AnimationDelay``` Speed of the brightness animation(delay between each step), recomended screen refreshrate in seconds - -```MaxScreenBrightness``` The highest value your screen supports, check ```/sys/class/backlight/intel_backlight/max_brightness``` on framework laptops +```AnimationDelay``` Speed of the brightness animation(delay between each step), recomended screen refreshrate in seconds (0.16 of 60Hz) ```MinimunBrightness``` The minimum screen brightness, recomended minumim 001 so the backlight dosn't turn off -~~ Other things to note +### Run``` setup.sh -u``` to update the installed script and service + +~~ Other things to note but shouldn't have to adjust ```Light``` The file where your lightsensor has its current value ```CurrentBirghtness``` The file where your screen stores its current brightness + +```MaxScreenBrightness``` The highest value your screen supports, check ```/sys/class/backlight/intel_backlight/max_brightness``` on framework laptops diff --git a/setup.sh b/setup.sh index 8689d3c..4c1190d 100755 --- a/setup.sh +++ b/setup.sh @@ -1,11 +1,46 @@ #!/bin/bash +# +case $1 in + -u) echo "Updading Mac-like-automatic-brightness..." + echo "Stopping AB service..." + sudo systemctl kill AB + echo "Updating AutomaticBrightness.sh..." + echo "Cloning AutomaticBrighness.sh..." + sudo cp AutomaticBrightness.sh /usr/local/bin/AutomaticBrightness.sh + echo "Updating AB.service for systemD..." + echo "Cloning AB.service for systemD..." + sudo cp AB.service /etc/systemd/system/AB.service + echo "Restarting AB service..." + systemctl daemon-reload + sudo systemctl start AB + exit;; +esac + echo "Setting up AutomaticBrightness.sh as a service..." -echo "Cloning AutomaticBrighness.sh..." -sudo cp AutomaticBrightness.sh /usr/local/bin/ +echo "Calibrating Light Sensor Scale..." -echo "Cloning AB.service for systemD" -sudo cp AB.service /etc/systemd/system/ +LSensorPath=$(find -L /sys/bus/iio/devices -maxdepth 2 -name "in_illuminance_raw" 2>/dev/null | grep "in_illuminance_raw") + +MaxScreenBrightness=$(find -L /sys/class/backlight -maxdepth 2 -name "max_brightness" 2>/dev/null | grep "max_brightness" | xargs cat) + +echo "Put your sensor in a bright light (outside works best)" +read -p "Press Enter to continue..." + +Smax=$(cat $LSensorPath) + +Scale=$(echo "scale=2; $MaxScreenBrightness / $Smax" | bc) + +Final="SensorToDisplayScale=$Scale" + +awk -v new_phrase="$Final" '/SensorToDisplayScale/{ print new_phrase; next } 1' AutomaticBrightness.sh > temp && mv temp AutomaticBrightness.sh + + +echo "Cloning AutomaticBrighness.sh..." +sudo cp AutomaticBrightness.sh /usr/local/bin/AutomaticBrightness.sh + +echo "Cloning AB.service for systemD..." +sudo cp AB.service /etc/systemd/system/AB.service echo "Startin Service..."