Now with the notes from the debug versoin
This commit is contained in:
parent
7635064471
commit
e8daf94cda
1 changed files with 33 additions and 15 deletions
|
@ -24,6 +24,9 @@ MinimumBrightness=001
|
||||||
# 2 : Default | 1 : Add Offset | 0 : Subtract Offset, Recomended 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 aditional value
|
||||||
|
# AutomaticBrightness.sh -i 100
|
||||||
while getopts i:d: flag
|
while getopts i:d: flag
|
||||||
do
|
do
|
||||||
case "${flag}" in
|
case "${flag}" in
|
||||||
|
@ -34,6 +37,7 @@ do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
@ -43,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))
|
||||||
|
|
||||||
|
# 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 ]]
|
||||||
|
@ -56,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)
|
||||||
|
@ -72,14 +77,17 @@ renice "$priority" "$$"
|
||||||
|
|
||||||
sleep 5
|
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
|
||||||
|
@ -94,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))
|
MaxOld=$((OldLight + OldLight/LightChange))
|
||||||
MinOld=$((OldLight - LightChange))
|
MinOld=$((OldLight - OldLight/LightChange))
|
||||||
else
|
|
||||||
MaxOld=$((OldLight + OldLight/LightChange))
|
|
||||||
MinOld=$((OldLight - OldLight/LightChange))
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $Light -gt $MaxOld ]] || [[ $Light -lt $MinOld ]]
|
if [[ $Light -gt $MaxOld ]] || [[ $Light -lt $MinOld ]]
|
||||||
then
|
then
|
||||||
|
@ -111,13 +117,17 @@ do
|
||||||
|
|
||||||
CurrentBrightness=$(cat $BLightPath)
|
CurrentBrightness=$(cat $BLightPath)
|
||||||
|
|
||||||
|
# Add MinimumBrighness here to not effect comparison but the outcome
|
||||||
Light=$(( $Light + $MinimumBrightness ))
|
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)
|
TempLight=$(echo "scale=2; $Light * $SensorToDisplayScale" | bc)
|
||||||
# REmoves float for latter checks
|
# REmoves float for latter checks
|
||||||
TempLight=$(LANG=C printf "%.0f" $TempLight)
|
TempLight=$(LANG=C printf "%.0f" $TempLight)
|
||||||
|
|
||||||
|
|
||||||
|
# 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
|
||||||
|
@ -125,13 +135,18 @@ do
|
||||||
NewLight=$TempLight
|
NewLight=$TempLight
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# How diffrent should each stop be
|
||||||
DiffCount=$(( ( $NewLight - $CurrentBrightness ) / $LevelSteps ))
|
DiffCount=$(( ( $NewLight - $CurrentBrightness ) / $LevelSteps ))
|
||||||
|
|
||||||
|
# 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 ))
|
||||||
|
|
||||||
|
|
||||||
|
# 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'})
|
||||||
|
@ -140,11 +155,14 @@ do
|
||||||
NewLight=$(echo +$NewLight)
|
NewLight=$(echo +$NewLight)
|
||||||
fi
|
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
|
sleep $AnimationDelay
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Store new light as old light for next comparison
|
||||||
OldLight=$Light
|
OldLight=$Light
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue