Merge pull request #7 from steel99xl/System-Service
System service support
This commit is contained in:
commit
c526025584
4 changed files with 52 additions and 42 deletions
12
AB.service
Normal file
12
AB.service
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Mac like automatic brightness as service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
Restart=no
|
||||||
|
RestartSec=1
|
||||||
|
|
||||||
|
ExecStart=/usr/local/bin/AutomaticBrightness.sh
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
53
AutomaticBrightness.sh
Normal file → Executable file
53
AutomaticBrightness.sh
Normal file → Executable file
|
@ -16,8 +16,6 @@ AnimationDelay=0.016
|
||||||
|
|
||||||
|
|
||||||
# Read the variable names
|
# Read the variable names
|
||||||
MaxScreenBrightness=96000
|
|
||||||
|
|
||||||
MinimumBrightness=001
|
MinimumBrightness=001
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,14 +32,17 @@ do
|
||||||
num=${OPTARG};;
|
num=${OPTARG};;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
if [[ -f /tmp/AB.offset ]]
|
|
||||||
|
if [[ -f /dev/shm/AB.offset ]]
|
||||||
then
|
then
|
||||||
OffSet=$(cat /tmp/AB.offset)
|
OffSet=$(cat /dev/shm/AB.offset)
|
||||||
else
|
else
|
||||||
OffSet=0
|
OffSet=0
|
||||||
$(echo $OffSet > /tmp/AB.offset)
|
$(echo $OffSet > /dev/shm/AB.offset)
|
||||||
|
$(chmod 666 /dev/shm/AB.offset)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
OffSet=$((OffSet < 0 ? 0 : OffSet))
|
OffSet=$((OffSet < 0 ? 0 : OffSet))
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,7 +57,7 @@ then
|
||||||
|
|
||||||
OffSet=$((OffSet < 0 ? 0 : OffSet))
|
OffSet=$((OffSet < 0 ? 0 : OffSet))
|
||||||
|
|
||||||
$(echo $OffSet > /tmp/AB.offset)
|
$(echo $OffSet > /dev/shm/AB.offset)
|
||||||
|
|
||||||
exit
|
exit
|
||||||
|
|
||||||
|
@ -68,36 +69,28 @@ 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" "$$"
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
LSensorPath=$(find -L /sys/bus/iio/devices -maxdepth 2 -name "in_illuminance_raw" 2>/dev/null | grep "in_illuminance_raw")
|
||||||
|
|
||||||
|
|
||||||
touch '/tmp/AB.running'
|
|
||||||
|
|
||||||
OldLight=$(cat /sys/bus/iio/devices/iio\:device0/in_illuminance_raw)
|
OldLight=$(cat $LSensorPath)
|
||||||
|
|
||||||
until [ -f /tmp/AB.kill ]
|
while true
|
||||||
do
|
do
|
||||||
if [[ -f /tmp/AB.stop ]]
|
if [[ -f /dev/shm/AB.offset ]]
|
||||||
then
|
then
|
||||||
rm '/tmp/AB.stop'
|
OffSet=$(cat /dev/shm/AB.offset)
|
||||||
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
|
else
|
||||||
OffSet=0
|
OffSet=0
|
||||||
$(echo $OffSet > /tmp/AB.offset)
|
$(echo $OffSet > /dev/shm/AB.offset)
|
||||||
|
$(chmod 666 /dev/shm/AB.offset)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
Light=$(cat /sys/bus/iio/devices/iio\:device0/in_illuminance_raw)
|
Light=$(cat $LSensorPath)
|
||||||
Light=$((Light + OffSet))
|
Light=$((Light + OffSet))
|
||||||
|
|
||||||
if [[ $Light -lt $LightChange ]]
|
if [[ $Light -lt $LightChange ]]
|
||||||
|
@ -113,7 +106,7 @@ do
|
||||||
then
|
then
|
||||||
|
|
||||||
|
|
||||||
CurrentBrightness=$(cat /sys/class/backlight/intel_backlight/brightness)
|
CurrentBrightness=$(cat $BLightPath)
|
||||||
|
|
||||||
|
|
||||||
Light=$(( $Light + $MinimumBrightness ))
|
Light=$(( $Light + $MinimumBrightness ))
|
||||||
|
@ -152,13 +145,7 @@ do
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sleep $SensorDelay
|
sleep $SensorDelay
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
rm '/tmp/AB.running'
|
|
||||||
rm '/tmp/AB.kill'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
13
README.md
13
README.md
|
@ -1,5 +1,7 @@
|
||||||
# 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
|
||||||
|
Run ```setup.sh``` to make it a service
|
||||||
|
|
||||||
made for the FrameWork laptop
|
made for the FrameWork laptop
|
||||||
|
|
||||||
|
@ -26,15 +28,8 @@ Your sensor has a diffrent range thant the 12th Gen Intel Framework laptop senso
|
||||||
|
|
||||||
```./AutomaticBrightness.sh -d [NUMBER] | Decrease the offset your brightness sensors raw reading ```
|
```./AutomaticBrightness.sh -d [NUMBER] | Decrease the offset your brightness sensors raw reading ```
|
||||||
|
|
||||||
```/tmp/AB.offset | Stores current offset for the sensor```
|
```/dev/shm/AB.offset | Stores current offset for the sensor```
|
||||||
|
|
||||||
```/tmp/AB.stop | Stops AutomaticBrightness.sh```
|
|
||||||
|
|
||||||
```/tmp/AB.start | Starts stopped AutomaticBrightness.sh```
|
|
||||||
|
|
||||||
```/tmp/AB.kill | Kills AutomaticBrightness.sh```
|
|
||||||
|
|
||||||
when running you will see a ```AB.running``` file and ```AB.offset``` in ```/tmp```
|
|
||||||
|
|
||||||
|
|
||||||
## Configuring
|
## Configuring
|
||||||
|
|
16
setup.sh
Executable file
16
setup.sh
Executable file
|
@ -0,0 +1,16 @@
|
||||||
|
#!/bin/bash
|
||||||
|
echo "Setting up AutomaticBrightness.sh as a service..."
|
||||||
|
|
||||||
|
echo "Cloning AutomaticBrighness.sh..."
|
||||||
|
sudo cp AutomaticBrightness.sh /usr/local/bin/
|
||||||
|
|
||||||
|
echo "Cloning AB.service for systemD"
|
||||||
|
sudo cp AB.service /etc/systemd/system/
|
||||||
|
|
||||||
|
|
||||||
|
echo "Startin Service..."
|
||||||
|
sudo systemctl enable AB
|
||||||
|
sudo systemctl start AB
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue