From 4af02540bd6f27506ac6c0dfca955b4ae6e9bf8b Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 12 Jul 2026 20:52:44 +0100 Subject: [PATCH] Pair Nightwing Moves through PSMoveAPI --- scripts/nightwing-claim-usb-moves.sh | 4 ++++ scripts/nightwing-pair-usb-moves-root.sh | 27 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 scripts/nightwing-pair-usb-moves-root.sh diff --git a/scripts/nightwing-claim-usb-moves.sh b/scripts/nightwing-claim-usb-moves.sh index 744f178..e6b8c16 100644 --- a/scripts/nightwing-claim-usb-moves.sh +++ b/scripts/nightwing-claim-usb-moves.sh @@ -6,6 +6,10 @@ if [ -z "$host_address" ]; then host_address="$(bluetoothctl show | awk '/^Controller / { print $2; exit }')" fi +if [ -x /usr/local/sbin/muninn-pair-usb-moves ]; then + sudo -n /usr/local/sbin/muninn-pair-usb-moves +fi + python3 - "$host_address" <<'PY' import fcntl import os diff --git a/scripts/nightwing-pair-usb-moves-root.sh b/scripts/nightwing-pair-usb-moves-root.sh new file mode 100644 index 0000000..97ab8a8 --- /dev/null +++ b/scripts/nightwing-pair-usb-moves-root.sh @@ -0,0 +1,27 @@ +#!/bin/sh +set -eu + +psmove_bin=/usr/local/bin/psmove +adapter_address="$(bluetoothctl show | awk '/^Controller / { print toupper($2); exit }')" +if [ ! -x "$psmove_bin" ] || [ -z "$adapter_address" ]; then + echo "PSMoveAPI or Nightwing Bluetooth adapter unavailable" >&2 + exit 1 +fi + +missing=0 +controllers="$($psmove_bin list 2>/dev/null | grep -Eio '[0-9a-f]{2}(:[0-9a-f]{2}){5}' | sort -u)" +for controller in $controllers; do + controller_upper="$(printf '%s' "$controller" | tr '[:lower:]' '[:upper:]')" + cache="/var/lib/bluetooth/$adapter_address/cache/$controller_upper" + if [ ! -s "$cache" ] || ! grep -q '^\[ServiceRecords\]$' "$cache"; then + missing=1 + break + fi +done + +if [ "$missing" -eq 0 ]; then + echo "All USB PS Moves already have BlueZ HID SDP pairing records." + exit 0 +fi + +exec "$psmove_bin" pair