From a4373a898e65604f58299c947882f50294dd813f Mon Sep 17 00:00:00 2001 From: Timmy Keller Date: Mon, 2 Sep 2024 08:44:38 -0500 Subject: various changes over time --- keyboard/bl | 2 +- keyboard/dockfanctl | 10 ++++++++++ keyboard/monctl | 38 ++++++++++++++++++++++++++++++++++++++ keyboard/shutdownprompt | 6 +++--- keyboard/sinkswitch | 15 +++++++++++++++ 5 files changed, 67 insertions(+), 4 deletions(-) create mode 100755 keyboard/dockfanctl create mode 100755 keyboard/monctl create mode 100755 keyboard/sinkswitch (limited to 'keyboard') diff --git a/keyboard/bl b/keyboard/bl index 84694e9..333d1e8 100755 --- a/keyboard/bl +++ b/keyboard/bl @@ -7,7 +7,7 @@ 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 --enable-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; } diff --git a/keyboard/dockfanctl b/keyboard/dockfanctl new file mode 100755 index 0000000..f422b3e --- /dev/null +++ b/keyboard/dockfanctl @@ -0,0 +1,10 @@ +#!/bin/sh +hub=$(doas uhubctl | grep -B3 'Port 3: .* highspeed enable connect .* Lenovo USB2.0 Hub' | grep -o -m1 '[0-9][^ ]*' | head -n1) +! [ "$hub" ] && exit 1 + +echo $hub + +case $1 in + off) doas uhubctl -a off -p 4 -l $hub ;; + on) doas uhubctl -a on -p 4 -l $hub ;; +esac diff --git a/keyboard/monctl b/keyboard/monctl new file mode 100755 index 0000000..116974f --- /dev/null +++ b/keyboard/monctl @@ -0,0 +1,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 diff --git a/keyboard/shutdownprompt b/keyboard/shutdownprompt index ce187a8..71cac3d 100755 --- a/keyboard/shutdownprompt +++ b/keyboard/shutdownprompt @@ -13,7 +13,7 @@ for process_name in $warn_process_names; do done case $option in - Suspend) launch zzz ;; - Shutdown) launch off ;; - Restart) launch res ;; + Suspend) launch zzz ;; + Shutdown) launch off ;; + Restart) launch res ;; esac diff --git a/keyboard/sinkswitch b/keyboard/sinkswitch new file mode 100755 index 0000000..3046498 --- /dev/null +++ b/keyboard/sinkswitch @@ -0,0 +1,15 @@ +#!/bin/sh +[ $(hostname) != 'T495' ] && echo "Not T495. Exiting" && exit 1 + +status="$(wpctl status)" + +headphones_sink=$(echo "$status" | grep -m1 'ThinkPad USB-C Dock Gen2 USB Audio Analog Stereo \[vol:' | grep -m1 -o '[0-9]*') +speakers_sink=$( echo "$status" | grep -m1 'Raven/Raven2/Fenghuang HDMI/DP Audio Controller Digital Stereo (HDMI 2) \[vol:' | grep -m1 -o '[0-9]*') + +selected_sink=$(echo "$status" | grep -m1 '\*\s*[0-9]*' | grep -o '[0-9]*') + +case $selected_sink in + $headphones_sink) wpctl set-default $speakers_sink && echo "Switched to speakers" ;; + $speakers_sink) wpctl set-default $headphones_sink && echo "Switched to headphones" ;; + *) echo "Cannot find correct sink. Exiting" && exit 1 ;; +esac -- cgit v1.2.3