#!/bin/sh # Config sleep_multiplier=.1 # Set this as low as you can get away with bl_vcp=0x10 # 0x10 is the standard VCP for controlling the backlight bl_min=0 bl_max=100 # DDC/CI stuff ddcutil="ddcutil --sleep-less --noverify --sleep-multiplier $sleep_multiplier" # Make sure user is in group i2c #ddcutil="ddcutil --sleep-less --noverify --enable-capabilities-cache --sleep-multiplier $sleep_multiplier" # Make sure user is in group i2c max() { [ $1 -gt $2 ] && echo $1 || echo $2; } min() { [ $1 -lt $2 ] && echo $1 || echo $2; } ddc_set() { $ddcutil --display $2 setvcp $bl_vcp $1; } ddc_get() { $ddcutil --display $2 getvcp $bl_vcp | grep -o "current value =\s*[0-9]*" | tr -cd '[0-9]'; } ddc_inc() { ddc_set $(min $(( `ddc_get` + $1 )) $bl_max) $2; } ddc_dec() { ddc_set $(max $(( `ddc_get` - $1 )) $bl_min) $2; } forall() { for d in $(seq `xrandr | grep ' connected' | wc -l`); do ($1 $2 $d); done; } i2c_group() { sudo=${SUDO:-sudo} ! $sudo -n true && echo "Please try again with root permissions!" && exit grep '^i2c' /etc/groups && echo "i2c group already exists!" && exit $sudo groupadd --system i2c && \ $sudo cp /usr/share/ddcutil/data/45-ddcutil-i2c.rules /etc/udev/rules.d && \ echo "i2c group successfully added! Now add your user to it" } case $1 in set) forall ddc_set $2 ;; get) forall ddc_get && echo '%' ;; inc) forall ddc_inc $2 ;; dec) forall ddc_dec $2 ;; i2c-groupadd) i2c_group ;; esac