summaryrefslogtreecommitdiff
path: root/keyboard
diff options
context:
space:
mode:
Diffstat (limited to 'keyboard')
-rwxr-xr-xkeyboard/bl25
1 files changed, 25 insertions, 0 deletions
diff --git a/keyboard/bl b/keyboard/bl
new file mode 100755
index 0000000..34ea0b0
--- /dev/null
+++ b/keyboard/bl
@@ -0,0 +1,25 @@
+#!/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 --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; }
+
+case $1 in
+ set) forall ddc_set $2 ;;
+ get) forall ddc_get && echo '%' ;;
+ inc) forall ddc_inc $2 ;;
+ dec) forall ddc_dec $2 ;;
+esac