Compare commits
26 commits
System-Ser
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
c6c858f572 | ||
|
ce98f0cc8c | ||
|
8593bbf05e | ||
|
83f9147362 | ||
|
0e6a16ae82 | ||
|
4c1a595430 | ||
|
ebd17c5d38 | ||
|
d9bf724579 | ||
|
e45c4bf0ef | ||
|
cc1d45195c | ||
|
e15c2060a6 | ||
|
031a86d73b | ||
|
b4948cf46f | ||
|
894893943c | ||
|
87152562cf | ||
|
9579c90d62 | ||
|
e86c09aad6 | ||
|
c1dcd48280 | ||
|
1a919d6299 | ||
|
e8daf94cda | ||
|
7635064471 | ||
|
1b0997474f | ||
|
be0a1c71a2 | ||
|
c526025584 | ||
|
10aa23e9fc | ||
|
abbf398f07 |
4 changed files with 138 additions and 47 deletions
|
@ -1,10 +1,10 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Mac like automatic brightness as service
|
Description=Mac-like-automatic-brightness as service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
Restart=no
|
Restart=on-failure
|
||||||
RestartSec=1
|
RestartSec=5s
|
||||||
|
|
||||||
ExecStart=/usr/local/bin/AutomaticBrightness.sh
|
ExecStart=/usr/local/bin/AutomaticBrightness.sh
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
#!/bin/bash
|
#!/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
|
LightChange=10
|
||||||
|
|
||||||
#How often it check the sensor
|
#How often it check the sensor
|
||||||
SensorDelay=1
|
SensorDelay=1
|
||||||
|
|
||||||
# Scale sesor to displas brightness range
|
# Scale sensor to display brightness range
|
||||||
SensorToDisplayScale=24
|
# 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
|
# 12 steps is the most similar on a Macbook 2017 running Arch compared to MacOS
|
||||||
LevelSteps=60
|
LevelSteps=12
|
||||||
# The is should match the LevelSteps but in the acual time each event should take to see
|
# Plays the 12 step effectively at 30 FPS 32ms
|
||||||
AnimationDelay=0.016
|
AnimationDelay=0.032
|
||||||
|
|
||||||
|
|
||||||
# Read the variable names
|
# Read the variable names
|
||||||
|
@ -20,9 +21,12 @@ 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
|
op=2
|
||||||
|
|
||||||
|
|
||||||
|
# Only look for flags -i or -d with an additional value
|
||||||
|
# AutomaticBrightness.sh -i 100
|
||||||
while getopts i:d: flag
|
while getopts i:d: flag
|
||||||
do
|
do
|
||||||
case "${flag}" in
|
case "${flag}" in
|
||||||
|
@ -33,6 +37,7 @@ do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Verify offset file exists and if so read it
|
||||||
if [[ -f /dev/shm/AB.offset ]]
|
if [[ -f /dev/shm/AB.offset ]]
|
||||||
then
|
then
|
||||||
OffSet=$(cat /dev/shm/AB.offset)
|
OffSet=$(cat /dev/shm/AB.offset)
|
||||||
|
@ -42,10 +47,10 @@ else
|
||||||
$(chmod 666 /dev/shm/AB.offset)
|
$(chmod 666 /dev/shm/AB.offset)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#if no offset or its less than 0 make 0
|
||||||
OffSet=$((OffSet < 0 ? 0 : OffSet))
|
OffSet=$((OffSet < 0 ? 0 : OffSet))
|
||||||
|
|
||||||
|
# relatively change number in Offset file and write it
|
||||||
if [[ $op -lt 2 ]]
|
if [[ $op -lt 2 ]]
|
||||||
then
|
then
|
||||||
if [[ $op -eq 1 ]]
|
if [[ $op -eq 1 ]]
|
||||||
|
@ -55,6 +60,7 @@ then
|
||||||
OffSet=$((OffSet - num))
|
OffSet=$((OffSet - num))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# verify offset is not less than 0
|
||||||
OffSet=$((OffSet < 0 ? 0 : OffSet))
|
OffSet=$((OffSet < 0 ? 0 : OffSet))
|
||||||
|
|
||||||
$(echo $OffSet > /dev/shm/AB.offset)
|
$(echo $OffSet > /dev/shm/AB.offset)
|
||||||
|
@ -69,14 +75,19 @@ priority=19 # Priority level , 0 = regular app , 19 = very much background app
|
||||||
# Set the priority of the current script, Thank you Theluga.
|
# Set the priority of the current script, Thank you Theluga.
|
||||||
renice "$priority" "$$"
|
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)
|
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")
|
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")
|
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)
|
OldLight=$(cat $LSensorPath)
|
||||||
|
|
||||||
while true
|
while true
|
||||||
|
@ -91,16 +102,14 @@ do
|
||||||
fi
|
fi
|
||||||
|
|
||||||
Light=$(cat $LSensorPath)
|
Light=$(cat $LSensorPath)
|
||||||
|
## apply offset to current light value
|
||||||
Light=$((Light + OffSet))
|
Light=$((Light + OffSet))
|
||||||
|
|
||||||
if [[ $Light -lt $LightChange ]]
|
# Set allowed range for light
|
||||||
then
|
|
||||||
MaxOld=$((OldLight + LightChange))
|
|
||||||
MinOld=$((OldLight - LightChange))
|
|
||||||
else
|
|
||||||
MaxOld=$((OldLight + OldLight/LightChange))
|
MaxOld=$((OldLight + OldLight/LightChange))
|
||||||
MinOld=$((OldLight - OldLight/LightChange))
|
MinOld=$((OldLight - OldLight/LightChange))
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $Light -gt $MaxOld ]] || [[ $Light -lt $MinOld ]]
|
if [[ $Light -gt $MaxOld ]] || [[ $Light -lt $MinOld ]]
|
||||||
then
|
then
|
||||||
|
@ -108,12 +117,15 @@ do
|
||||||
|
|
||||||
CurrentBrightness=$(cat $BLightPath)
|
CurrentBrightness=$(cat $BLightPath)
|
||||||
|
|
||||||
|
# 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 ))
|
||||||
|
|
||||||
Light=$(( $Light + $MinimumBrightness ))
|
# 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))
|
||||||
|
|
||||||
|
|
||||||
TempLight=$(($Light * $SensorToDisplayScale))
|
# Check we do not ask the screen to go brighter than it can
|
||||||
|
|
||||||
if [[ $TempLight -gt $MaxScreenBrightness ]]
|
if [[ $TempLight -gt $MaxScreenBrightness ]]
|
||||||
then
|
then
|
||||||
NewLight=$MaxScreenBrightness
|
NewLight=$MaxScreenBrightness
|
||||||
|
@ -121,26 +133,46 @@ do
|
||||||
NewLight=$TempLight
|
NewLight=$TempLight
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DiffCount=$(( ($NewLight - $CurrentBrightness)/$LevelSteps ))
|
# 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} )
|
for i in $(eval echo {1..$LevelSteps} )
|
||||||
do
|
do
|
||||||
|
|
||||||
|
# Set new relative light value
|
||||||
NewLight=$(( $DiffCount ))
|
NewLight=$(( $DiffCount ))
|
||||||
|
|
||||||
if [[ $NewLight -lt 0 ]]
|
|
||||||
|
|
||||||
|
CurrentBrightness=$(cat $BLightPath)
|
||||||
|
FakeLight=$(( $NewLight + $CurrentBrightness))
|
||||||
|
|
||||||
|
if [[ $FakeLight -gt $MaxScreenBrightness ]]
|
||||||
then
|
then
|
||||||
NewLight=$( echo "$NewLight" | awk -F "-" {'print$2'})
|
NewLight=$MaxScreenBrightness
|
||||||
NewLight=$(echo $NewLight-)
|
echo "ERROR"
|
||||||
else
|
else
|
||||||
NewLight=$(echo +$NewLight)
|
echo $FakeLight > $BLightPath
|
||||||
fi
|
fi
|
||||||
|
|
||||||
brightnessctl -q s $NewLight
|
# Format values appropriately for brightnessctl
|
||||||
|
#if [[ $NewLight -lt 0 ]]
|
||||||
|
#then
|
||||||
|
#NewLight=$( echo "$NewLight" | awk -F "-" {'print$2'})
|
||||||
|
#NewLight=$(echo $NewLight-)
|
||||||
|
#else
|
||||||
|
#NewLight=$(echo +$NewLight)
|
||||||
|
#fi
|
||||||
|
|
||||||
|
# Adjust brightness relatively
|
||||||
|
#brightnessctl -q s $NewLight
|
||||||
|
# Sleep for the screen Hz time so he effect is visible
|
||||||
sleep $AnimationDelay
|
sleep $AnimationDelay
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Store new light as old light for next comparison
|
||||||
OldLight=$Light
|
OldLight=$Light
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
27
README.md
27
README.md
|
@ -1,16 +1,27 @@
|
||||||
# Mac-like-automatic-brightness
|
# Mac-like-automatic-brightness
|
||||||
A simple script to provide a "Mac" like automatic brightness adjustemnt/ animation.
|
A simple script to provide a "Mac" like automatic brightness adjustemnt/ animation.
|
||||||
## Now as a system service
|
## 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
|
made for the FrameWork laptop
|
||||||
|
|
||||||
based on 2017 MacBook Pro
|
based on 2017 MacBook Pro
|
||||||
|
|
||||||
|
|
||||||
read ```Configuration``` for detailed informatoion about what options you have to easily customize/ adjust the bightness or animation speed
|
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
|
## Requires
|
||||||
brightnessctl
|
```bc```
|
||||||
|
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
|
||||||
|
|
||||||
## Non 12th Gen Intel Framework Owners
|
## Non 12th Gen Intel Framework Owners
|
||||||
Your sensor has a diffrent range thant the 12th Gen Intel Framework laptop sensors, please see chart bellow
|
Your sensor has a diffrent range thant the 12th Gen Intel Framework laptop sensors, please see chart bellow
|
||||||
|
@ -30,6 +41,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```
|
```/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
|
## Configuring
|
||||||
|
@ -41,14 +54,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
|
```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
|
```AnimationDelay``` Speed of the brightness animation(delay between each step), recomended screen refreshrate in seconds (0.16 of 60Hz)
|
||||||
|
|
||||||
```MaxScreenBrightness``` The highest value your screen supports, check ```/sys/class/backlight/intel_backlight/max_brightness``` on framework laptops
|
|
||||||
|
|
||||||
```MinimunBrightness``` The minimum screen brightness, recomended minumim 001 so the backlight dosn't turn off
|
```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
|
```Light``` The file where your lightsensor has its current value
|
||||||
|
|
||||||
```CurrentBirghtness``` The file where your screen stores its current brightness
|
```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
|
||||||
|
|
54
setup.sh
54
setup.sh
|
@ -1,14 +1,58 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
case $1 in
|
||||||
|
-u) echo "Updating Mac-like-automatic-brightness..."
|
||||||
|
echo "Stopping AB service..."
|
||||||
|
sudo systemctl kill AB
|
||||||
|
echo "Updating AutomaticBrightness.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..."
|
||||||
|
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 "Setting up AutomaticBrightness.sh as a service..."
|
||||||
|
|
||||||
echo "Cloning AutomaticBrighness.sh..."
|
echo "Calibrating Light Sensor Scale..."
|
||||||
sudo cp AutomaticBrightness.sh /usr/local/bin/
|
|
||||||
|
|
||||||
echo "Cloning AB.service for systemD"
|
LSensorPath=$(find -L /sys/bus/iio/devices -maxdepth 2 -name "in_illuminance_raw" 2>/dev/null | grep "in_illuminance_raw")
|
||||||
sudo cp AB.service /etc/systemd/system/
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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 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 enable AB
|
||||||
sudo systemctl start AB
|
sudo systemctl start AB
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue