diff --git a/cec-remote/setup.sh b/cec-remote/setup.sh index d2c531c..edf79a0 100755 --- a/cec-remote/setup.sh +++ b/cec-remote/setup.sh @@ -3,7 +3,7 @@ SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" echo $SCRIPT_DIR -cat | sudo tee /etc/systemd/system/cec-remote.service <&2 + sleep 2 + fi +done +echo "Found G435 device: $DEVICE" + +# ================================================================= +# Switch function +# ================================================================= +switch_to_sink() { + local target="$1" + pactl set-default-sink "$target" + for id in $(pactl list short sink-inputs | awk '{print $1}'); do + pactl move-sink-input "$id" "$target" 2>/dev/null + done + echo "Switched to: $target" +} + +# ================================================================= +# Event loop – grab the device exclusively +# ================================================================= +up_timestamps=() + +exec 3< <(stdbuf -oL evtest "$DEVICE") + +while read -u 3 line; do + # Volume UP press (115) + if [[ "$line" == *"code 115 (KEY_VOLUMEUP)"*"value 1"* ]]; then + now=$(date +%s) + up_timestamps+=("$now") + # prune timestamps older than window + cutoff=$((now - RAPID_WINDOW)) + new_ts=() + for ts in "${up_timestamps[@]}"; do + [ "$ts" -ge "$cutoff" ] && new_ts+=("$ts") + done + up_timestamps=("${new_ts[@]}") + count=${#up_timestamps[@]} + + if [ "$count" -gt "$RAPID_THRESHOLD" ]; then + echo "Rapid VOLUMEUP ($count presses) – switching to FALLBACK" + switch_to_sink "$SINK_FALLBACK" + else + echo "Normal VOLUMEUP – switching to G435" + switch_to_sink "$SINK_G435" + fi + + # Volume DOWN press (114) – always switch to G435 + elif [[ "$line" == *"code 114 (KEY_VOLUMEDOWN)"*"value 1"* ]]; then + echo "VOLUMEDOWN – switching to G435" + switch_to_sink "$SINK_G435" + fi +done diff --git a/g534-sink-switcher/setup.sh b/g534-sink-switcher/setup.sh new file mode 100755 index 0000000..18a51a1 --- /dev/null +++ b/g534-sink-switcher/setup.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +echo $SCRIPT_DIR + +sudo tee /home/kuba/.config/systemd/user/g435-sink-switch.service <