Compare commits

..

1 commit

Author SHA1 Message Date
steel99xl
1b8e84006b
inital changes
Specific changes for the Nanote-Next UMPC
it dosent have an ambient brightness sensor
2024-04-16 20:09:32 -04:00
3 changed files with 34 additions and 36 deletions

54
AutomaticBrightness.sh Executable file → Normal file
View file

@ -1,31 +1,31 @@
#!/bin/bash #!/bin/bash
#How much light change must be seen by the sensor before it will act #How much light change must be seen by the sensor befor it will act
LightChange=10 LightChange=10
#How often it check the sensor #How often it check the sensor
SensorDelay=1 SensorDelay=1
# Scale sensor to display brightness range # Scale sesor to displas brightness range
# NOW WITH FLOAT SUPPORT # NOW WITH FLOAT SUPPORT
SensorToDisplayScale=1 SensorToDisplayScale=1
# 12 steps is the most similar on a Macbook 2017 running Arch compared to MacOS #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=12 LevelSteps=31
# Plays the 12 step effectively at 30 FPS 32ms # The is should match the LevelSteps but in the acual time each event should take to see
AnimationDelay=0.032 AnimationDelay=0.016
# Read the variable names # Read the variable names
MinimumBrightness=001 MinimumBrightness=050
# 2 : Default | 1 : Add Offset | 0 : Subtract Offset, Recommended not to change # 2 : Default | 1 : Add Offset | 0 : Subtract Offset, Recomended not to change
op=2 op=2
# Only look for flags -i or -d with an additional value # Only look for flags -i or -d with an aditional value
# AutomaticBrightness.sh -i 100 # AutomaticBrightness.sh -i 100
while getopts i:d: flag while getopts i:d: flag
do do
@ -37,7 +37,7 @@ do
esac esac
done done
# Verify offset file exists and if so read it # Verigy offset file exsits 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)
@ -50,7 +50,7 @@ fi
#if no offset or its less than 0 make 0 #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 # relativly 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 ]]
@ -84,11 +84,18 @@ 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") BLightPath=$(find -L /sys/class/backlight -maxdepth 2 -name "brightness" 2>/dev/null | grep "brightness")
# Set path to current luminance sensor # 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 #Set the current light value so we have something to compare to
OldLight=$(cat $LSensorPath) 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))
while true while true
do do
@ -101,9 +108,8 @@ do
$(chmod 666 /dev/shm/AB.offset) $(chmod 666 /dev/shm/AB.offset)
fi fi
Light=$(cat $LSensorPath)
## apply offset to current light value ## apply offset to current light value
Light=$((Light + OffSet)) Light=$((OffSet))
# Set allowed range for light # Set allowed range for light
@ -117,15 +123,15 @@ do
CurrentBrightness=$(cat $BLightPath) CurrentBrightness=$(cat $BLightPath)
# Add MinimumBrightness here to not effect comparison but the outcome # Add MinimumBrighness 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 # Gernate a TempLight value for the screen to be set to
# Float math thanks Matthias_Wachter # Float math thanks Matthias_Wachter
TempLight=$(LC_NUMERIC=C printf "%.0f" $(echo "scale=2; $Light * $SensorToDisplayScale" | bc)) TempLight=$(LANG=C printf "%.0f" $(echo "scale=2; $Light * $SensorToDisplayScale" | bc))
# Check we do not ask the screen to go brighter than it can # Check we dont ask the screen to go brighter than it can
if [[ $TempLight -gt $MaxScreenBrightness ]] if [[ $TempLight -gt $MaxScreenBrightness ]]
then then
NewLight=$MaxScreenBrightness NewLight=$MaxScreenBrightness
@ -133,8 +139,8 @@ do
NewLight=$TempLight NewLight=$TempLight
fi fi
# How different should each stop be # How diffrent should each stop be
DiffCount=$(LC_NUMERIC=C printf "%.0f" $(echo "scale=2; ( $NewLight - $CurrentBrightness ) / $LevelSteps" | bc )) DiffCount=$(LANG=C printf "%.0f" $(echo "scale=2; ( $NewLight - $CurrentBrightness ) / $LevelSteps" | bc ))
# Step once per Screen Hz to make animation # Step once per Screen Hz to make animation
for i in $(eval echo {1..$LevelSteps} ) for i in $(eval echo {1..$LevelSteps} )
@ -156,7 +162,7 @@ do
echo $FakeLight > $BLightPath echo $FakeLight > $BLightPath
fi fi
# Format values appropriately for brightnessctl # Format values apropriatly for brightnessctl
#if [[ $NewLight -lt 0 ]] #if [[ $NewLight -lt 0 ]]
#then #then
#NewLight=$( echo "$NewLight" | awk -F "-" {'print$2'}) #NewLight=$( echo "$NewLight" | awk -F "-" {'print$2'})
@ -165,7 +171,7 @@ do
#NewLight=$(echo +$NewLight) #NewLight=$(echo +$NewLight)
#fi #fi
# Adjust brightness relatively # Adjust brightness relativly
#brightnessctl -q s $NewLight #brightnessctl -q s $NewLight
# Sleep for the screen Hz time so he effect is visible # Sleep for the screen Hz time so he effect is visible
sleep $AnimationDelay sleep $AnimationDelay

View file

@ -7,15 +7,8 @@ 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
```bc``` ```bc```
For running 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

View file

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
# #
case $1 in case $1 in
-u) echo "Updating Mac-like-automatic-brightness..." -u) echo "Updading Mac-like-automatic-brightness..."
echo "Stopping AB service..." echo "Stopping AB service..."
sudo systemctl kill AB sudo systemctl kill AB
echo "Updating AutomaticBrightness.sh..." echo "Updating AutomaticBrightness.sh..."
echo "Cloning AutomaticBrightness.sh..." echo "Cloning AutomaticBrighness.sh..."
sudo cp AutomaticBrightness.sh /usr/local/bin/AutomaticBrightness.sh sudo cp AutomaticBrightness.sh /usr/local/bin/AutomaticBrightness.sh
echo "Updating AB.service for systemD..." echo "Updating AB.service for systemD..."
echo "Cloning AB.service for systemD..." echo "Cloning AB.service for systemD..."
@ -44,15 +44,14 @@ then
awk -v new_phrase="$NewStep" '/LevelSteps=/{ print new_phrase; next } 1' AutomaticBrightness.sh > temp && mv temp AutomaticBrightness.sh awk -v new_phrase="$NewStep" '/LevelSteps=/{ print new_phrase; next } 1' AutomaticBrightness.sh > temp && mv temp AutomaticBrightness.sh
fi fi
echo "Cloning AutomaticBrightness.sh..." echo "Cloning AutomaticBrighness.sh..."
sudo cp AutomaticBrightness.sh /usr/local/bin/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..." echo "Cloning AB.service for systemD..."
sudo cp AB.service /etc/systemd/system/AB.service sudo cp AB.service /etc/systemd/system/AB.service
echo "Starting Service..." echo "Startin Service..."
sudo systemctl enable AB sudo systemctl enable AB
sudo systemctl start AB sudo systemctl start AB