Compare commits

..

12 commits

Author SHA1 Message Date
willifan
c6c858f572 adjusted SensorToDisplayScale for amd framework 2025-05-07 17:47:45 +02:00
steel99xl
ce98f0cc8c
Merge pull request #11 from ESHARK22/refact_typos
Fix some english typos
2025-03-17 17:27:22 -04:00
Ishaaq
8593bbf05e Fix some english typos 2025-03-17 20:20:13 +00:00
steel99xl
83f9147362
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
2025-01-06 19:46:33 -05:00
steel99xl
0e6a16ae82 forgot to use LC_NUMERIC 2024-08-06 16:02:09 -04:00
steel99xl
4c1a595430 Fixed Error 2024-08-06 15:58:00 -04:00
steel99xl
ebd17c5d38
Update README.md
Now with information on how to easily update the script and service with a new version or one your have modified
2024-08-06 15:35:19 -04:00
steel99xl
d9bf724579 Merge branch 'main' of github.com:steel99xl/Mac-like-automatic-brightness 2024-08-06 15:26:06 -04:00
steel99xl
e45c4bf0ef 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
2024-08-06 15:22:59 -04:00
steel99xl
cc1d45195c
Merge pull request #9 from Harfeur/main
Fixed two issues: printf float and execute permission
2024-04-19 15:35:25 -04:00
Maxime Chourré
e15c2060a6
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).
2024-04-18 08:39:01 +02:00
Maxime Chourré
031a86d73b
Changed printf LANG to LC_NUMERIC
It was displaying an error almost every time : invalid number float
2024-04-18 08:36:24 +02:00
3 changed files with 36 additions and 34 deletions

54
AutomaticBrightness.sh Normal file → Executable file
View file

@ -1,31 +1,31 @@
#!/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=1
#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=31
# 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
# Plays the 12 step effectively at 30 FPS 32ms
AnimationDelay=0.032
# Read the variable names
MinimumBrightness=050
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 ]]
@ -84,18 +84,11 @@ MaxScreenBrightness=$(find -L /sys/class/backlight -maxdepth 2 -name "max_bright
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
if [[ -f /dev/shm/AB.offset ]]
then
OffSet=$(cat /dev/shm/AB.offset)
else
OffSet=0
$(echo $OffSet > /dev/shm/AB.offset)
$(chmod 666 /dev/shm/AB.offset)
fi
OldLight=$(($OffSet))
OldLight=$(cat $LSensorPath)
while true
do
@ -108,8 +101,9 @@ do
$(chmod 666 /dev/shm/AB.offset)
fi
Light=$(cat $LSensorPath)
## apply offset to current light value
Light=$((OffSet))
Light=$((Light + OffSet))
# Set allowed range for light
@ -123,15 +117,15 @@ do
CurrentBrightness=$(cat $BLightPath)
# Add MinimumBrighness here to not effect comparison but the outcome
Light=$(( $Light + $MinimumBrightness ))
# 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=$(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
# Check we do not ask the screen to go brighter than it can
if [[ $TempLight -gt $MaxScreenBrightness ]]
then
NewLight=$MaxScreenBrightness
@ -139,8 +133,8 @@ do
NewLight=$TempLight
fi
# How diffrent should each stop be
DiffCount=$(LANG=C printf "%.0f" $(echo "scale=2; ( $NewLight - $CurrentBrightness ) / $LevelSteps" | bc ))
# 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
for i in $(eval echo {1..$LevelSteps} )
@ -162,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'})
@ -171,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

View file

@ -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

View file

@ -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,14 +44,15 @@ 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
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