summaryrefslogtreecommitdiff
path: root/keyboard/monctl
blob: 116974f36f8f5c6f13ad3309627e9d57e7408180 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh

display=$2
input_vcp=0x60
input_local=0x11
input_other=0x0f
power_vcp=0xD6
power_on=0x01
power_off=0x05
sleep_multiplier=.1  # Set this as low as you can get away with

# DDC/CI stuff
ddcutil="ddcutil --noverify --sleep-multiplier $sleep_multiplier --display $display"  # Make sure user is in group i2c

getstate() { $ddcutil getvcp $1 | grep -o '0x[0-9a-f]*' | tail -n1 ; }

in_other() { $ddcutil setvcp $input_vcp $input_other ; }
in_local() { $ddcutil setvcp $input_vcp $input_local ; }
pw_on()    { $ddcutil setvcp $power_vcp $power_on    ; }
pw_off()   { $ddcutil setvcp $power_vcp $power_off   ; }

in_toggle() { [ `getstate $input_vcp` = $input_local ] && in_other || in_local ; }  # Default to input_local
pw_toggle() { [ `getstate $power_vcp` = $pw_on       ] && pw_off   || pw_on    ; }  # Default to power_on

case $1 in
	inputother)  in_other  ;;
	inputlocal)  in_local  ;;
	inputtoggle) in_toggle ;;
	poweron)     pw_on     ;;
	poweroff)    pw_off    ;;
	powertoggle) pw_toggle ;;
	getinput)    getstate $input_vcp ;;
	getpower)    getstate $power_vcp ;;
	*)
		echo "'$1' is not a recognized option"
		echo "$(basename "$0") [inputother|inputlocal|inputtoggle|poweron|poweroff|powertoggle] display_num"
	;;
esac