misc/scripts/redshift-i2c

40 lines
686 B
Plaintext
Raw Normal View History

2019-01-26 18:51:26 +01:00
#!/bin/sh
# Set brightness for DDC/CI enabled monitors
export PATH="/var/setuid-wrappers:$PATH"
# monitor i2c device
device=dev:/dev/i2c-0
# brightness values
night=35
transition=45
daytime=60
deref() {
eval "echo \$$1"
}
set_brightness() {
2020-07-25 17:38:45 +02:00
sudo ddccontrol $device -r 0x10 -w > /dev/null "$1" 2>&1
2019-01-26 18:51:26 +01:00
}
fade_to() {
current=$(sudo ddccontrol $device -r 0x10 2> /dev/null | grep -oP '\+/\K[0-9]+')
2020-07-25 17:38:45 +02:00
[ "$current" -gt "$1" ] && step=-1 || step=1
for i in $(seq "$current" "$step" "$1"); do
set_brightness "$i"
2019-01-26 18:51:26 +01:00
sleep 1
done
}
2020-07-25 17:38:45 +02:00
if [ "$1" = "period-changed" ]; then
2019-01-26 18:51:26 +01:00
if ! (lsmod | grep -q "^i2c_dev"); then
sudo modprobe i2c-dev
fi
2020-07-25 17:38:45 +02:00
fade_to "$(deref "$3")"
2019-01-26 18:51:26 +01:00
fi