From abbf398f07edb6b9612e21b425b0b0d4f4609223 Mon Sep 17 00:00:00 2001 From: steel99xl Date: Sun, 24 Dec 2023 14:43:09 -0500 Subject: [PATCH 01/21] Moved to System-Service fork --- AutomaticBrightness.service | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 AutomaticBrightness.service diff --git a/AutomaticBrightness.service b/AutomaticBrightness.service deleted file mode 100644 index cbdde28..0000000 --- a/AutomaticBrightness.service +++ /dev/null @@ -1,8 +0,0 @@ -[Unit] -Description=Mac like automatic brightness service - -[Service] -ExecStart=/path/to/AutomaticBrightness.sh - -[Install] -WantedBy=default.target From 10aa23e9fcaa6f349a205a40aa3ba35336583bb4 Mon Sep 17 00:00:00 2001 From: steel99xl Date: Sun, 24 Dec 2023 14:43:25 -0500 Subject: [PATCH 02/21] Delete autobrightness.sh --- autobrightness.sh | 169 ---------------------------------------------- 1 file changed, 169 deletions(-) delete mode 100644 autobrightness.sh diff --git a/autobrightness.sh b/autobrightness.sh deleted file mode 100644 index 4c64893..0000000 --- a/autobrightness.sh +++ /dev/null @@ -1,169 +0,0 @@ -#!/bin/bash -# Slight Alteration of AutomaticBrighness.sh (could be a dell specific fork) - -#variables to run - -#decrease cpu usage -Priority=19 # CPU limit, adjust as needed - -# How much light change must be seen by the sensor before it will act -LightChange=10 - -# How often it checks the sensor -SensorDelay=1 - -# Scale sensor to display brightness range -SensorToDisplayScale=20 - -# This should match your refresh rate otherwise it will either change the backlight more times than needed or too few for a smooth animation -LevelSteps=60 - -# The is should match the LevelSteps but in the actual time each event should take to see -AnimationDelay=0.016 - -# Read the variable names -MaxScreenBrightness=937 -MinimumBrightness=1 - -#minimum illuminance to get minimum brightness - -MinimimumIlluminance=0 - -# 2 : Default | 1 : Add Offset | 0 : Subtract Offset, Recommended not to change -op=2 - -#place where you get the brightness of the monitor being controled and the sensor of brightness -MonitorBrightness=/sys/class/backlight/intel_backlight/brightness - -#my sensor keep changing places, this way it will always be found with * if you have lots of sensors - -AnbientSensorIlluminance=`echo "$(set -- $(realpath /sys/bus/iio/devices/iio:*/in_illuminance_raw); echo "$1")"` - - -while getopts i:d: flag; do - case "${flag}" in - i) op=1 - num=${OPTARG};; - d) op=0 - num=${OPTARG};; - esac -done - -if [[ -f /tmp/AB.offset ]]; then - OffSet=$(cat /tmp/AB.offset) -else - OffSet=0 - echo $OffSet > /tmp/AB.offset - chmod 666 /tmp/AB.offset -fi - -OffSet=$((OffSet < 0 ? 0 : OffSet)) - -if [[ $op -lt 2 ]]; then - if [[ $op -eq 1 ]]; then - OffSet=$((OffSet + num)) - else - OffSet=$((OffSet - num)) - fi - - OffSet=$((OffSet < 0 ? 0 : OffSet)) - echo $OffSet > /tmp/AB.offset - chmod 666 /tmp/AB.offset - exit -fi - - -# Set the priority of the current script and says it is running -renice "$Priority" "$$" -touch '/tmp/AB.running' - - -OldLight=$(cat $AnbientSensorIlluminance) - -until [ -f /tmp/AB.kill ]; do - if [[ -f /tmp/AB.stop ]]; then - 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 - if [[ -f /tmp/AB.offset ]]; then - OffSet=$(cat /tmp/AB.offset) - else - OffSet=0 - echo $OffSet > /tmp/AB.offset - chmod 666 /tmp/AB.offset - fi - - Light=$(cat $AnbientSensorIlluminance) - RealLight=$(cat $AnbientSensorIlluminance) - Light=$((Light + OffSet)) - RealLight=$((RealLight + OffSet)) - - if [[ $Light -lt $LightChange ]]; then - MaxOld=$((OldLight + LightChange)) - MinOld=$((OldLight - LightChange)) - else - MaxOld=$((OldLight + OldLight/LightChange)) - MinOld=$((OldLight - OldLight/LightChange)) - fi - - if [[ $Light -gt $MaxOld ]] || [[ $Light -lt $MinOld ]]; then - CurrentBrightness=$(cat $MonitorBrightness) - Light=$(( $Light + $MinimumBrightness )) - TempLight=$(($Light * $SensorToDisplayScale)) - - if [[ $TempLight -gt $MaxScreenBrightness ]]; then - NewLight=$MaxScreenBrightness - LimitMaxIlluminanceReached=1 - elif [[ $RealLight -le $MinimimumIlluminance ]]; then - NewLight=$MinimumBrightness - LimitMinIlluminanceReached=1 - 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 - - if [[ $i -eq $LevelSteps ]]; then - brightnessctl -q s $NewLight - - if [[ $LimitMaxIlluminanceReached -eq 1 ]]; then - NewLight=$MaxScreenBrightness - LimitMaxIlluminanceReached=0 - fi - - if [[ $LimitMinIlluminanceReached -eq 1 ]]; then - NewLight=$MinimumBrightness - LimitMinIlluminanceReached=0 - fi - fi - - brightnessctl -q s $NewLight - sleep $AnimationDelay - done - - OldLight=$Light - fi - - sleep $SensorDelay - fi -done - -rm '/tmp/AB.running' -rm '/tmp/AB.kill' From be0a1c71a2c1d3e32b8dcdba3551cebcdf821f24 Mon Sep 17 00:00:00 2001 From: steel99xl Date: Mon, 8 Jan 2024 19:36:05 -0500 Subject: [PATCH 03/21] Fixed edge case --- AutomaticBrightness.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AutomaticBrightness.sh b/AutomaticBrightness.sh index 4e8ee3f..6a9636b 100755 --- a/AutomaticBrightness.sh +++ b/AutomaticBrightness.sh @@ -121,7 +121,7 @@ do NewLight=$TempLight fi - DiffCount=$(( ($NewLight - $CurrentBrightness)/$LevelSteps )) + DiffCount=$(( ( $NewLight - $CurrentBrightness ) / $LevelSteps )) for i in $(eval echo {1..$LevelSteps} ) do From 1b0997474fcfd711b84b48a0bd3a97d7987f34e8 Mon Sep 17 00:00:00 2001 From: steel99xl Date: Sat, 10 Feb 2024 09:33:03 -0500 Subject: [PATCH 04/21] SensorToDisplayScale now supports floats A 5 second delay was added to the startup. Dew to reports of the service starting before the system values are initalized --- AB.service | 4 ++-- AutomaticBrightness.sh | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/AB.service b/AB.service index d6aa319..ff5d542 100644 --- a/AB.service +++ b/AB.service @@ -3,8 +3,8 @@ Description=Mac like automatic brightness as service [Service] Type=simple -Restart=no -RestartSec=1 +Restart=on-failure +RestartSec=5s ExecStart=/usr/local/bin/AutomaticBrightness.sh diff --git a/AutomaticBrightness.sh b/AutomaticBrightness.sh index 6a9636b..c811c35 100755 --- a/AutomaticBrightness.sh +++ b/AutomaticBrightness.sh @@ -7,7 +7,8 @@ LightChange=10 SensorDelay=1 # Scale sesor to displas brightness range -SensorToDisplayScale=24 +# NOW WITH FLOAT SUPPORT +SensorToDisplayScale=24.09 #This should match your refesh rate other wise it will either change the back light more times than needed or too few for a smooth animation LevelSteps=60 @@ -69,6 +70,8 @@ priority=19 # Priority level , 0 = regular app , 19 = very much background app # Set the priority of the current script, Thank you Theluga. renice "$priority" "$$" +sleep 5 + MaxScreenBrightness=$(find -L /sys/class/backlight -maxdepth 2 -name "max_brightness" 2>/dev/null | grep "max_brightness" | xargs cat) BLightPath=$(find -L /sys/class/backlight -maxdepth 2 -name "brightness" 2>/dev/null | grep "brightness") @@ -111,8 +114,9 @@ do Light=$(( $Light + $MinimumBrightness )) - - TempLight=$(($Light * $SensorToDisplayScale)) + TempLight=$(echo "scale=2; $Light * $SensorToDisplayScale" | bc) + # REmoves float for latter checks + TempLight=$(LANG=C printf "%.0f" $TempLight) if [[ $TempLight -gt $MaxScreenBrightness ]] then From 7635064471aa6b0cb11d9146bf7a330cedf4a4cd Mon Sep 17 00:00:00 2001 From: steel99xl Date: Sat, 10 Feb 2024 11:10:12 -0500 Subject: [PATCH 05/21] 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..." From e8daf94cdae484eea559213e4f9084f40aaa2507 Mon Sep 17 00:00:00 2001 From: steel99xl Date: Sat, 10 Feb 2024 11:47:06 -0500 Subject: [PATCH 06/21] Now with the notes from the debug versoin --- AutomaticBrightness.sh | 48 +++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/AutomaticBrightness.sh b/AutomaticBrightness.sh index c811c35..5056a71 100755 --- a/AutomaticBrightness.sh +++ b/AutomaticBrightness.sh @@ -24,6 +24,9 @@ MinimumBrightness=001 # 2 : Default | 1 : Add Offset | 0 : Subtract Offset, Recomended not to change op=2 + +# Only look for flags -i or -d with an aditional value +# AutomaticBrightness.sh -i 100 while getopts i:d: flag do case "${flag}" in @@ -34,6 +37,7 @@ do esac done +# Verigy offset file exsits and if so read it if [[ -f /dev/shm/AB.offset ]] then OffSet=$(cat /dev/shm/AB.offset) @@ -43,10 +47,10 @@ else $(chmod 666 /dev/shm/AB.offset) fi - +#if no offset or its less than 0 make 0 OffSet=$((OffSet < 0 ? 0 : OffSet)) - +# relativly change number in Offset file and write it if [[ $op -lt 2 ]] then if [[ $op -eq 1 ]] @@ -56,6 +60,7 @@ then OffSet=$((OffSet - num)) fi + # verify offset is not less than 0 OffSet=$((OffSet < 0 ? 0 : OffSet)) $(echo $OffSet > /dev/shm/AB.offset) @@ -72,14 +77,17 @@ renice "$priority" "$$" sleep 5 +# Get screen max brightness value MaxScreenBrightness=$(find -L /sys/class/backlight -maxdepth 2 -name "max_brightness" 2>/dev/null | grep "max_brightness" | xargs cat) +# Set path to current screen brightness value BLightPath=$(find -L /sys/class/backlight -maxdepth 2 -name "brightness" 2>/dev/null | grep "brightness") +# Set path to current luminance sensor LSensorPath=$(find -L /sys/bus/iio/devices -maxdepth 2 -name "in_illuminance_raw" 2>/dev/null | grep "in_illuminance_raw") - +#Set the current light value so we have something to compare to OldLight=$(cat $LSensorPath) while true @@ -94,16 +102,14 @@ do fi Light=$(cat $LSensorPath) + ## apply offset to current light value Light=$((Light + OffSet)) - if [[ $Light -lt $LightChange ]] - then - MaxOld=$((OldLight + LightChange)) - MinOld=$((OldLight - LightChange)) - else - MaxOld=$((OldLight + OldLight/LightChange)) - MinOld=$((OldLight - OldLight/LightChange)) - fi + # Set allowed range for light + + MaxOld=$((OldLight + OldLight/LightChange)) + MinOld=$((OldLight - OldLight/LightChange)) + if [[ $Light -gt $MaxOld ]] || [[ $Light -lt $MinOld ]] then @@ -111,13 +117,17 @@ do CurrentBrightness=$(cat $BLightPath) - + # Add MinimumBrighness here to not effect comparison but the outcome Light=$(( $Light + $MinimumBrightness )) - + + # Gernate a TempLight value for the screen to be set to + # Float math thanks Matthias_Wachter TempLight=$(echo "scale=2; $Light * $SensorToDisplayScale" | bc) # REmoves float for latter checks TempLight=$(LANG=C printf "%.0f" $TempLight) + + # Check we dont ask the screen to go brighter than it can if [[ $TempLight -gt $MaxScreenBrightness ]] then NewLight=$MaxScreenBrightness @@ -125,13 +135,18 @@ do NewLight=$TempLight fi + # How diffrent should each stop be DiffCount=$(( ( $NewLight - $CurrentBrightness ) / $LevelSteps )) + # Step once per Screen Hz to make animation for i in $(eval echo {1..$LevelSteps} ) do + # Set new relative light value NewLight=$(( $DiffCount )) + + # Format values apropriatly for brightnessctl if [[ $NewLight -lt 0 ]] then NewLight=$( echo "$NewLight" | awk -F "-" {'print$2'}) @@ -139,12 +154,15 @@ do else NewLight=$(echo +$NewLight) fi - + + # Adjust brightness relativly brightnessctl -q s $NewLight + # Sleep for the screen Hz time so he effect is visible sleep $AnimationDelay done - + + # Store new light as old light for next comparison OldLight=$Light fi From 1a919d62992bf1cb5d6431d51ed1c4c8a295c76a Mon Sep 17 00:00:00 2001 From: steel99xl Date: Sun, 18 Feb 2024 22:11:43 -0500 Subject: [PATCH 07/21] Dependancyfree Now without brightnessctl dependancy --- AutomaticBrightness.sh | 30 +++++++++++++++++++++--------- README.md | 5 ++++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/AutomaticBrightness.sh b/AutomaticBrightness.sh index 5056a71..e39adb6 100755 --- a/AutomaticBrightness.sh +++ b/AutomaticBrightness.sh @@ -146,17 +146,29 @@ do NewLight=$(( $DiffCount )) + + CurrentBrightness=$(cat $BLightPath) + FakeLight=$(( $NewLight + $CurrentBrightness)) + + if [[ $FakeLight -gt $MaxScreenBrightness ]] + then + NewLight=$MaxScreenBrightness + echo "ERROR" + else + echo $FakeLight > $BLightPath + fi + # Format values apropriatly for brightnessctl - if [[ $NewLight -lt 0 ]] - then - NewLight=$( echo "$NewLight" | awk -F "-" {'print$2'}) - NewLight=$(echo $NewLight-) - else - NewLight=$(echo +$NewLight) - fi - + #if [[ $NewLight -lt 0 ]] + #then + #NewLight=$( echo "$NewLight" | awk -F "-" {'print$2'}) + #NewLight=$(echo $NewLight-) + #else + #NewLight=$(echo +$NewLight) + #fi + # Adjust brightness relativly - brightnessctl -q s $NewLight + #brightnessctl -q s $NewLight # Sleep for the screen Hz time so he effect is visible sleep $AnimationDelay diff --git a/README.md b/README.md index 478b5c8..bbba596 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,10 @@ based on 2017 MacBook Pro read ```Configuration``` for detailed informatoion about what options you have to easily customize/ adjust the bightness or animation speed ## Requires -brightnessctl +For running in as your user you need to be part of the ```vidoe``` group +```sudo usermod -a -G vido $USER``` if your not apart of the group + +If your installing as a system service your user dose not need to be apart of the group ## Non 12th Gen Intel Framework Owners Your sensor has a diffrent range thant the 12th Gen Intel Framework laptop sensors, please see chart bellow From c1dcd482801cab5ace5493693fba64b5734b9813 Mon Sep 17 00:00:00 2001 From: steel99xl Date: Sun, 18 Feb 2024 22:14:01 -0500 Subject: [PATCH 08/21] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bbba596..4aa41b1 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,8 @@ based on 2017 MacBook Pro read ```Configuration``` for detailed informatoion about what options you have to easily customize/ adjust the bightness or animation speed ## Requires -For running in as your user you need to be part of the ```vidoe``` group -```sudo usermod -a -G vido $USER``` if your not apart of the group +For running in as your user you need to be part of the ```video``` group +```sudo usermod -a -G video $USER``` if your not apart of the group If your installing as a system service your user dose not need to be apart of the group From e86c09aad618b53a2c246f25376ec84a8ea9fbb6 Mon Sep 17 00:00:00 2001 From: steel99xl Date: Sun, 18 Feb 2024 22:14:36 -0500 Subject: [PATCH 09/21] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4aa41b1..3ac1ea2 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ based on 2017 MacBook Pro read ```Configuration``` for detailed informatoion about what options you have to easily customize/ adjust the bightness or animation speed ## Requires -For running in as your user you need to be part of the ```video``` group +For running as your user you need to be part of the ```video``` group ```sudo usermod -a -G video $USER``` if your not apart of the group If your installing as a system service your user dose not need to be apart of the group From 9579c90d62cc09e5b3ca3b683d1525fa226444e8 Mon Sep 17 00:00:00 2001 From: steel99xl Date: Wed, 28 Feb 2024 13:22:40 -0500 Subject: [PATCH 10/21] Fixed setup.sh awk in setup.sh was not capturing the correct feild cleanded up floating point in AutomaticBrightness.sh --- AutomaticBrightness.sh | 6 ++---- setup.sh | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) mode change 100755 => 100644 AutomaticBrightness.sh diff --git a/AutomaticBrightness.sh b/AutomaticBrightness.sh old mode 100755 new mode 100644 index e39adb6..defea77 --- a/AutomaticBrightness.sh +++ b/AutomaticBrightness.sh @@ -122,9 +122,7 @@ do # Gernate a TempLight value for the screen to be set to # Float math thanks Matthias_Wachter - TempLight=$(echo "scale=2; $Light * $SensorToDisplayScale" | bc) - # REmoves float for latter checks - TempLight=$(LANG=C printf "%.0f" $TempLight) + TempLight=$(LANG=C printf "%.0f" $(echo "scale=2; $Light * $SensorToDisplayScale" | bc)) # Check we dont ask the screen to go brighter than it can @@ -136,7 +134,7 @@ do fi # How diffrent should each stop be - DiffCount=$(( ( $NewLight - $CurrentBrightness ) / $LevelSteps )) + DiffCount=$(LANG=C printf "%.0f" $(echo "scale=2; ( $NewLight - $CurrentBrightness ) / $LevelSteps" | bc )) # Step once per Screen Hz to make animation for i in $(eval echo {1..$LevelSteps} ) diff --git a/setup.sh b/setup.sh index 4c1190d..1bd83d2 100755 --- a/setup.sh +++ b/setup.sh @@ -33,7 +33,7 @@ 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 +awk -v new_phrase="$Final" '/SensorToDisplayScale=/{ print new_phrase; next } 1' AutomaticBrightness.sh > temp && mv temp AutomaticBrightness.sh echo "Cloning AutomaticBrighness.sh..." From 87152562cfdf38b03e50eed11e163bd6f3ac0b5b Mon Sep 17 00:00:00 2001 From: steel99xl Date: Wed, 28 Feb 2024 13:24:12 -0500 Subject: [PATCH 11/21] fixed requierments --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index bbba596..35dcd2c 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ based on 2017 MacBook Pro read ```Configuration``` for detailed informatoion about what options you have to easily customize/ adjust the bightness or animation speed ## Requires +```bc``` + For running in as your user you need to be part of the ```vidoe``` group ```sudo usermod -a -G vido $USER``` if your not apart of the group From b4948cf46f2a2d372e0c80ba73817b617b7ef287 Mon Sep 17 00:00:00 2001 From: steel99xl Date: Fri, 15 Mar 2024 23:39:09 -0400 Subject: [PATCH 12/21] LevelSetps now automaticaly configurs based on your maxbrighrness if needed (this is to keep it close to how a 2017 macbook pro behaves even with a limited range) --- setup.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/setup.sh b/setup.sh index 1bd83d2..85f7af1 100755 --- a/setup.sh +++ b/setup.sh @@ -35,6 +35,14 @@ Final="SensorToDisplayScale=$Scale" awk -v new_phrase="$Final" '/SensorToDisplayScale=/{ print new_phrase; next } 1' AutomaticBrightness.sh > temp && mv temp AutomaticBrightness.sh +TempSteps=($MaxScreenBrightness / 60) +if [[ TempSteps -lt 17 ]] +then + Steps=$($MaxScreenBrightness / 16) + NewStep="LevelSteps=$Steps" + + awk -v new_phrase="$NewStep" '/LevelSteps=/{ print new_phrase; next } 1' AutomaticBrightness.sh > temp && mv temp AutomaticBrightness.sh +fi echo "Cloning AutomaticBrighness.sh..." sudo cp AutomaticBrightness.sh /usr/local/bin/AutomaticBrightness.sh From 031a86d73b24331608a68b63055a1d1a3e640493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20Chourr=C3=A9?= Date: Thu, 18 Apr 2024 08:36:24 +0200 Subject: [PATCH 13/21] Changed printf LANG to LC_NUMERIC It was displaying an error almost every time : invalid number float --- AutomaticBrightness.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AutomaticBrightness.sh b/AutomaticBrightness.sh index defea77..559bb98 100644 --- a/AutomaticBrightness.sh +++ b/AutomaticBrightness.sh @@ -122,7 +122,7 @@ do # Gernate a TempLight value for the screen to be set to # Float math thanks Matthias_Wachter - TempLight=$(LANG=C printf "%.0f" $(echo "scale=2; $Light * $SensorToDisplayScale" | bc)) + TempLight=$(LC_NUMERIC=C printf "%.0f" $(echo "scale=2; $Light * $SensorToDisplayScale" | bc)) # Check we dont ask the screen to go brighter than it can @@ -134,7 +134,7 @@ do fi # How diffrent should each stop be - DiffCount=$(LANG=C printf "%.0f" $(echo "scale=2; ( $NewLight - $CurrentBrightness ) / $LevelSteps" | bc )) + DiffCount=$(LC_NUMERIC=C printf "%.0f" $(echo "scale=2; ( $NewLight - $CurrentBrightness ) / $LevelSteps" | bc )) # Step once per Screen Hz to make animation for i in $(eval echo {1..$LevelSteps} ) From e15c2060a6b191d6bbbaed7bc912ad4af5eb3d21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20Chourr=C3=A9?= Date: Thu, 18 Apr 2024 08:39:01 +0200 Subject: [PATCH 14/21] Add execute permission to script If the file is not executable, the service system will not load it, and will return a 203/EXEC error (file not found). --- setup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.sh b/setup.sh index 85f7af1..8921b11 100755 --- a/setup.sh +++ b/setup.sh @@ -46,6 +46,7 @@ fi echo "Cloning AutomaticBrighness.sh..." sudo cp AutomaticBrightness.sh /usr/local/bin/AutomaticBrightness.sh +sudo chmod u+x /usr/local/bin/AutomaticBrightness.sh echo "Cloning AB.service for systemD..." sudo cp AB.service /etc/systemd/system/AB.service From e45c4bf0efc1cc6a5f1a76b6004b39861d11d41a Mon Sep 17 00:00:00 2001 From: steel99xl Date: Tue, 6 Aug 2024 15:22:59 -0400 Subject: [PATCH 15/21] MinimumBrightness is now closer to representing the % of brightness still to be improved, but currently no good way to get the max sensor brightness wightout saving it during the calibration --- AutomaticBrightness.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 AutomaticBrightness.sh diff --git a/AutomaticBrightness.sh b/AutomaticBrightness.sh old mode 100644 new mode 100755 index defea77..48737ca --- a/AutomaticBrightness.sh +++ b/AutomaticBrightness.sh @@ -118,7 +118,7 @@ do CurrentBrightness=$(cat $BLightPath) # Add MinimumBrighness here to not effect comparison but the outcome - Light=$(( $Light + $MinimumBrightness )) + Light=$(LANG=C printf "%.0f" $(echo "scale=2; $Light + ( $MinimumBrightness * $SensorToDisplayScale ) " | bc )) # Gernate a TempLight value for the screen to be set to # Float math thanks Matthias_Wachter From ebd17c5d38325e512a70a231860260887dbb157a Mon Sep 17 00:00:00 2001 From: steel99xl Date: Tue, 6 Aug 2024 15:35:19 -0400 Subject: [PATCH 16/21] Update README.md Now with information on how to easily update the script and service with a new version or one your have modified --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 21870d8..5fe392f 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,15 @@ made for the FrameWork laptop based on 2017 MacBook Pro + read ```Configuration``` for detailed informatoion about what options you have to easily customize/ adjust the bightness or animation speed +## Updating +Run ```git pull``` to download the latest version + +Then run ```./setup -u``` to update the the service and script running on your system with newly downloaded / modifyed versions + + ## Requires ```bc``` For running as your user you need to be part of the ```video``` group From 4c1a595430414ad1e198f11487df1c69930e7f8d Mon Sep 17 00:00:00 2001 From: steel99xl Date: Tue, 6 Aug 2024 15:58:00 -0400 Subject: [PATCH 17/21] Fixed Error --- AutomaticBrightness.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AutomaticBrightness.sh b/AutomaticBrightness.sh index 2f27e80..ee728e3 100755 --- a/AutomaticBrightness.sh +++ b/AutomaticBrightness.sh @@ -118,7 +118,7 @@ do CurrentBrightness=$(cat $BLightPath) # Add MinimumBrighness here to not effect comparison but the outcome - Light=$(LANG=C printf "%.0f" $(echo "scale=2; $Light + ( $MinimumBrightness * $SensorToDisplayScale ) " | bc )) + Light=$(LANG=C printf "%.0f" $(echo "scale=2; $Light + ( ($MaxScreenBrightness * ( $MinimumBrightness / 100 )) / $SensorToDisplayScale ) " | bc )) # Gernate a TempLight value for the screen to be set to # Float math thanks Matthias_Wachter From 0e6a16ae82ac5029ddbc9ebf710e599c5d54b363 Mon Sep 17 00:00:00 2001 From: steel99xl Date: Tue, 6 Aug 2024 16:02:09 -0400 Subject: [PATCH 18/21] forgot to use LC_NUMERIC --- AutomaticBrightness.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AutomaticBrightness.sh b/AutomaticBrightness.sh index ee728e3..d0d0054 100755 --- a/AutomaticBrightness.sh +++ b/AutomaticBrightness.sh @@ -118,7 +118,7 @@ do CurrentBrightness=$(cat $BLightPath) # Add MinimumBrighness here to not effect comparison but the outcome - Light=$(LANG=C printf "%.0f" $(echo "scale=2; $Light + ( ($MaxScreenBrightness * ( $MinimumBrightness / 100 )) / $SensorToDisplayScale ) " | bc )) + Light=$(LC_NUMERIC=C printf "%.0f" $(echo "scale=2; $Light + ( ($MaxScreenBrightness * ( $MinimumBrightness / 100 )) / $SensorToDisplayScale ) " | bc )) # Gernate a TempLight value for the screen to be set to # Float math thanks Matthias_Wachter From 83f9147362a6deaeeb00ddfe6a4cf669a5c80fb7 Mon Sep 17 00:00:00 2001 From: steel99xl Date: Mon, 6 Jan 2025 19:46:33 -0500 Subject: [PATCH 19/21] Improved Range Improved the effective amount of distinct brightness levels by 5x *You can lower LevelSteps to get more distinct levels but you will need to change the AnimationDelay to compensate --- AutomaticBrightness.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AutomaticBrightness.sh b/AutomaticBrightness.sh index d0d0054..7dc08c1 100755 --- a/AutomaticBrightness.sh +++ b/AutomaticBrightness.sh @@ -10,10 +10,10 @@ SensorDelay=1 # NOW WITH FLOAT SUPPORT SensorToDisplayScale=24.09 -#This should match your refesh rate other wise it will either change the back light more times than needed or too few for a smooth animation -LevelSteps=60 -# The is should match the LevelSteps but in the acual time each event should take to see -AnimationDelay=0.016 +# 12 steps is the most similar on a Macbook 2017 running Arch compared to MacOS +LevelSteps=12 +# Playes the 12 stesp effectivly at 30 FPS 32ms +AnimationDelay=0.032 # Read the variable names From 8593bbf05e22f0002e02dd55f2188cdcba2719a4 Mon Sep 17 00:00:00 2001 From: Ishaaq Date: Mon, 17 Mar 2025 20:20:13 +0000 Subject: [PATCH 20/21] Fix some english typos --- AutomaticBrightness.sh | 26 +++++++++++++------------- setup.sh | 8 ++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/AutomaticBrightness.sh b/AutomaticBrightness.sh index 7dc08c1..e209f15 100755 --- a/AutomaticBrightness.sh +++ b/AutomaticBrightness.sh @@ -1,18 +1,18 @@ #!/bin/bash -#How much light change must be seen by the sensor befor it will act +#How much light change must be seen by the sensor before it will act LightChange=10 #How often it check the sensor SensorDelay=1 -# Scale sesor to displas brightness range +# Scale sensor to display brightness range # NOW WITH FLOAT SUPPORT SensorToDisplayScale=24.09 # 12 steps is the most similar on a Macbook 2017 running Arch compared to MacOS LevelSteps=12 -# Playes the 12 stesp effectivly at 30 FPS 32ms +# Plays the 12 step effectively at 30 FPS 32ms AnimationDelay=0.032 @@ -21,11 +21,11 @@ MinimumBrightness=001 -# 2 : Default | 1 : Add Offset | 0 : Subtract Offset, Recomended not to change +# 2 : Default | 1 : Add Offset | 0 : Subtract Offset, Recommended not to change op=2 -# Only look for flags -i or -d with an aditional value +# Only look for flags -i or -d with an additional value # AutomaticBrightness.sh -i 100 while getopts i:d: flag do @@ -37,7 +37,7 @@ do esac done -# Verigy offset file exsits and if so read it +# Verify offset file exists and if so read it if [[ -f /dev/shm/AB.offset ]] then OffSet=$(cat /dev/shm/AB.offset) @@ -50,7 +50,7 @@ fi #if no offset or its less than 0 make 0 OffSet=$((OffSet < 0 ? 0 : OffSet)) -# relativly change number in Offset file and write it +# relatively change number in Offset file and write it if [[ $op -lt 2 ]] then if [[ $op -eq 1 ]] @@ -117,15 +117,15 @@ do CurrentBrightness=$(cat $BLightPath) - # Add MinimumBrighness here to not effect comparison but the outcome + # Add MinimumBrightness here to not effect comparison but the outcome Light=$(LC_NUMERIC=C printf "%.0f" $(echo "scale=2; $Light + ( ($MaxScreenBrightness * ( $MinimumBrightness / 100 )) / $SensorToDisplayScale ) " | bc )) - # Gernate a TempLight value for the screen to be set to + # Generate a TempLight value for the screen to be set to # Float math thanks Matthias_Wachter TempLight=$(LC_NUMERIC=C printf "%.0f" $(echo "scale=2; $Light * $SensorToDisplayScale" | bc)) - # Check we dont ask the screen to go brighter than it can + # Check we do not ask the screen to go brighter than it can if [[ $TempLight -gt $MaxScreenBrightness ]] then NewLight=$MaxScreenBrightness @@ -133,7 +133,7 @@ do NewLight=$TempLight fi - # How diffrent should each stop be + # How different should each stop be DiffCount=$(LC_NUMERIC=C printf "%.0f" $(echo "scale=2; ( $NewLight - $CurrentBrightness ) / $LevelSteps" | bc )) # Step once per Screen Hz to make animation @@ -156,7 +156,7 @@ do echo $FakeLight > $BLightPath fi - # Format values apropriatly for brightnessctl + # Format values appropriately for brightnessctl #if [[ $NewLight -lt 0 ]] #then #NewLight=$( echo "$NewLight" | awk -F "-" {'print$2'}) @@ -165,7 +165,7 @@ do #NewLight=$(echo +$NewLight) #fi - # Adjust brightness relativly + # Adjust brightness relatively #brightnessctl -q s $NewLight # Sleep for the screen Hz time so he effect is visible sleep $AnimationDelay diff --git a/setup.sh b/setup.sh index 8921b11..628a942 100755 --- a/setup.sh +++ b/setup.sh @@ -1,11 +1,11 @@ #!/bin/bash # case $1 in - -u) echo "Updading Mac-like-automatic-brightness..." + -u) echo "Updating Mac-like-automatic-brightness..." echo "Stopping AB service..." sudo systemctl kill AB echo "Updating AutomaticBrightness.sh..." - echo "Cloning AutomaticBrighness.sh..." + echo "Cloning AutomaticBrightness.sh..." sudo cp AutomaticBrightness.sh /usr/local/bin/AutomaticBrightness.sh echo "Updating AB.service for systemD..." echo "Cloning AB.service for systemD..." @@ -44,7 +44,7 @@ then awk -v new_phrase="$NewStep" '/LevelSteps=/{ print new_phrase; next } 1' AutomaticBrightness.sh > temp && mv temp AutomaticBrightness.sh fi -echo "Cloning AutomaticBrighness.sh..." +echo "Cloning AutomaticBrightness.sh..." sudo cp AutomaticBrightness.sh /usr/local/bin/AutomaticBrightness.sh sudo chmod u+x /usr/local/bin/AutomaticBrightness.sh @@ -52,7 +52,7 @@ echo "Cloning AB.service for systemD..." sudo cp AB.service /etc/systemd/system/AB.service -echo "Startin Service..." +echo "Starting Service..." sudo systemctl enable AB sudo systemctl start AB From c6c858f572cad4754fe62e1f8744408e6a83a133 Mon Sep 17 00:00:00 2001 From: willifan Date: Wed, 7 May 2025 17:47:45 +0200 Subject: [PATCH 21/21] adjusted SensorToDisplayScale for amd framework --- AutomaticBrightness.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AutomaticBrightness.sh b/AutomaticBrightness.sh index e209f15..23c8eb7 100755 --- a/AutomaticBrightness.sh +++ b/AutomaticBrightness.sh @@ -8,7 +8,7 @@ SensorDelay=1 # Scale sensor to display brightness range # NOW WITH FLOAT SUPPORT -SensorToDisplayScale=24.09 +SensorToDisplayScale=1 # 12 steps is the most similar on a Macbook 2017 running Arch compared to MacOS LevelSteps=12