Created
April 11, 2016 17:30
-
-
Save nickabal/0a3faaa45b76a53bfad76a748e27b58f to your computer and use it in GitHub Desktop.
Set brightness via radeon_bl0 when redshift status changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set brightness via radeon_bl0 when redshift status changes (amdgpu,radeon) | |
### Set brihtness via xbrightness when redshift status changes | |
# Set brightness values for each status. | |
# Range from 1 to 255 is valid | |
brightness_day="255" | |
brightness_transition="120" | |
brightness_night="30" | |
# Set fade time for changes to one minute | |
fadetime=60 | |
old_brightness_v=\$brightness_${2} | |
new_brightness_v=\$brightness_${3} | |
old_brightness=`eval echo $old_brightness_v` | |
new_brightness=`eval echo $new_brightness_v` | |
case $1 in | |
period-changed) | |
if [[ $old_brightness -gt $new_brightness ]]; then | |
while [[ $old_brightness -gt $new_brightness ]]; do | |
echo $old_brightness > /sys/class/backlight/radeon_bl0/brightness | |
sleep $fadetime | |
((old_brightness -= 1)) | |
done & | |
fi | |
if [[ $old_brightness -lt $new_brightness ]]; then | |
while [[ $old_brightness -lt $new_brightness ]]; do | |
echo $old_brightness > /sys/class/backlight/radeon_bl0/brightness | |
sleep $fadetime | |
((old_brightness += 1)) | |
done & | |
fi | |
;; | |
esac |
You may also want to look at the file max_brightness
instead of assuming that the maximum value is 255, it seldom is. Some user's may want to test setting the brightness to their value on brightness_night
and then reset the brightness, before putting this in production; some drives will get locked until reboot when the brightness is too low.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
[ ... ]
instead of[[ ... ]]
, ortest ...
as I would prefer. If you then useexpr
instead of(( ))
, the script should run nicely in POSIXsh
on any system. To improve performance (assuming usingsh
instead ofbash
) but lose portability, you can usefor
andseq
instead of the counter.