Pair PS Move to Bluetooth host

This commit is contained in:
Meta Vens 2026-05-31 17:57:44 +01:00
commit 17b991c182
4 changed files with 131 additions and 0 deletions

View file

@ -433,6 +433,12 @@ a named invariant that the native runtime cannot protect yet.
collection with 49-byte input/output/feature reports, plus two vendor-defined
feature-report collections. The safe `--read` path uses overlapped `ReadFile`
plus `CancelIoEx` so idle input reads time out instead of hanging the probe.
`--pair-host <bdaddr>` writes a target Bluetooth host address through the
PS Move `0x05` feature report on the `col02` collection, following PS Move
API's pairing contract. The first live controller `00:06:f5:23:e2:d1` was
assigned to Nightwing's BlueZ adapter `5c:93:a2:9c:a8:a8`; wireless
connection still needs the controller unplugged from USB and a PS-button
connection pass while Nightwing scans.
Next useful cut is report decoding and controlled LED/sphere command
provenance, then optical sphere observations from PS3 Eyes/Kiyos can enter
the same calibration-evidence path as LED spline constraints.

View file

@ -6,6 +6,7 @@ const ushort SonyVid = 0x054C;
const ushort PsMovePid = 0x03D5;
var readReports = args.Any(arg => string.Equals(arg, "--read", StringComparison.OrdinalIgnoreCase));
var pairHost = TryGetOption(args, "--pair-host");
var showAll = args.Any(arg => string.Equals(arg, "--all", StringComparison.OrdinalIgnoreCase));
if (showAll)
{
@ -37,6 +38,12 @@ foreach (var device in devices)
{
PrintDevice(device);
if (!string.IsNullOrWhiteSpace(pairHost))
{
var result = WindowsHid.TryPairHost(device, pairHost);
Console.WriteLine($" pairHost={result}");
}
if (readReports)
{
var result = await WindowsHid.TryReadInputReportAsync(device, TimeSpan.FromMilliseconds(350));
@ -61,6 +68,24 @@ static void PrintDevice(HidDeviceInfo device)
Console.WriteLine($" values in/out/feature={device.Caps.NumberInputValueCaps}/{device.Caps.NumberOutputValueCaps}/{device.Caps.NumberFeatureValueCaps}");
}
static string? TryGetOption(string[] values, string name)
{
for (var index = 0; index < values.Length; index++)
{
if (string.Equals(values[index], name, StringComparison.OrdinalIgnoreCase) && index + 1 < values.Length)
{
return values[index + 1];
}
if (values[index].StartsWith(name + "=", StringComparison.OrdinalIgnoreCase))
{
return values[index][(name.Length + 1)..];
}
}
return null;
}
internal sealed record HidDeviceInfo(
string Path,
ushort VendorId,
@ -83,6 +108,10 @@ internal static class WindowsHid
private const uint WaitObject0 = 0;
private const uint WaitTimeout = 258;
private const int HidpStatusSuccess = 0x00110000;
private const byte GetBtAddressReport = 0x04;
private const byte SetBtAddressReport = 0x05;
private const int BtAddressGetSize = 16;
private const int BtAddressSetSize = 23;
public static IEnumerable<HidDeviceInfo> Enumerate()
{
@ -197,6 +226,89 @@ internal static class WindowsHid
}
}
public static string TryPairHost(HidDeviceInfo device, string hostAddress)
{
if (device.Caps.FeatureReportByteLength < BtAddressSetSize || device.Path.IndexOf("&col02#", StringComparison.OrdinalIgnoreCase) < 0)
{
return "skipped: pairing uses the PS Move col02 feature-report collection";
}
if (!TryParseBluetoothAddress(hostAddress, out var host))
{
return $"invalid host address: {hostAddress}";
}
using var handle = CreateFile(
device.Path,
0,
FileShareRead | FileShareWrite,
IntPtr.Zero,
OpenExisting,
0,
IntPtr.Zero);
if (handle.IsInvalid)
{
return $"open failed: {new Win32Exception(Marshal.GetLastWin32Error()).Message}";
}
var before = ReadBluetoothAddresses(handle);
var report = new byte[BtAddressSetSize];
report[0] = SetBtAddressReport;
host.CopyTo(report.AsSpan(1, 6));
if (!HidD_SetFeature(handle, report, report.Length))
{
return $"HidD_SetFeature failed: {new Win32Exception(Marshal.GetLastWin32Error()).Message}";
}
var after = ReadBluetoothAddresses(handle);
var controller = after.Controller ?? before.Controller ?? "(unknown)";
var assigned = after.Host ?? FormatBluetoothAddress(host);
return $"ok controller={controller} host={assigned}";
}
private static (string? Controller, string? Host) ReadBluetoothAddresses(SafeFileHandle handle)
{
var report = new byte[BtAddressGetSize];
report[0] = GetBtAddressReport;
if (!HidD_GetFeature(handle, report, report.Length))
{
return (null, null);
}
return (FormatBluetoothAddress(report.AsSpan(1, 6)), FormatBluetoothAddress(report.AsSpan(10, 6)));
}
private static bool TryParseBluetoothAddress(string value, out byte[] bytes)
{
bytes = new byte[6];
var parts = value.Split(':', '-');
if (parts.Length != 6)
{
return false;
}
for (var index = 0; index < parts.Length; index++)
{
if (!byte.TryParse(parts[index], System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture, out var parsed))
{
return false;
}
bytes[5 - index] = parsed;
}
return true;
}
private static string FormatBluetoothAddress(ReadOnlySpan<byte> littleEndianAddress)
{
return string.Join(
":",
littleEndianAddress.ToArray().Reverse().Select(value => value.ToString("x2", System.Globalization.CultureInfo.InvariantCulture)));
}
private static string GetDevicePath(IntPtr deviceInfoSet, SpDeviceInterfaceData interfaceData)
{
SetupDiGetDeviceInterfaceDetail(deviceInfoSet, ref interfaceData, IntPtr.Zero, 0, out var requiredSize, IntPtr.Zero);
@ -329,6 +441,12 @@ internal static class WindowsHid
[DllImport("hid.dll", SetLastError = true)]
private static extern bool HidD_GetSerialNumberString(SafeFileHandle hidDeviceObject, byte[] buffer, int bufferLength);
[DllImport("hid.dll", SetLastError = true)]
private static extern bool HidD_GetFeature(SafeFileHandle hidDeviceObject, byte[] reportBuffer, int reportBufferLength);
[DllImport("hid.dll", SetLastError = true)]
private static extern bool HidD_SetFeature(SafeFileHandle hidDeviceObject, byte[] reportBuffer, int reportBufferLength);
[DllImport("setupapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern IntPtr SetupDiGetClassDevs(
ref Guid classGuid,

View file

@ -266,3 +266,4 @@
{"ts": "2026-05-31T17:02:03+01:00", "type": "decision", "status": "ok", "note": "Eve dashboard now publishes mimir.live.stats as a read-only compact telemetry surface; Odin ingests it alongside VoidBot so GUI/TUI clients lower one accepted CultMesh surface instead of scraping renderers."}
{"ts": "2026-05-31T17:20:52+01:00", "type": "implementation", "status": "ok", "note": "Added a dependency-free Mimir.PsMoveProbe for Sony PS Move VID_054C/PID_03D5 over Windows HID. Live USB probe found three collections: generic desktop gamepad with 49-byte input/output/feature reports plus two vendor-defined feature-report collections. Safe read probing now uses overlapped ReadFile/CancelIoEx and times out cleanly at idle; PS Move should be treated as an active marker/IMU witness whose glowing sphere becomes camera calibration evidence, not as a depth owner."}
{"ts": "2026-05-31T17:39:26+01:00", "type": "verification", "status": "ok", "note": "Nightwing/Odin Mimir Live Stats now surfaces sync authority: accepted passive state asio-ch1->asio-ch0 plus decode attempts for rejected/silent routes; loopback ASIO channels remain silent, so dashboard must distinguish accepted sync from failed decode evidence."}
{"ts": "2026-05-31T17:56:57+01:00", "type": "verification", "status": "partial", "note": "Nightwing BlueZ is installed/enabled with adapter 5c:93:a2:9c:a8:a8 and ClassicBondedOnly=false for PS Move-style classic HID. Mimir.PsMoveProbe --pair-host wrote that host address to the connected PS Move over USB col02 feature report 0x05; controller address read back as 00:06:f5:23:e2:d1. Wireless connection is not yet verified because Starfire still sees the controller on USB; unplug and press PS while Nightwing scans."}

View file

@ -162,6 +162,12 @@ invariants:
collections. USB report decoding should own identity/buttons/IMU and later
LED sphere control; camera observations of the sphere should enter the
existing global calibration evidence path.
`--pair-host <bdaddr>` now writes the target Bluetooth host to the
controller through feature report `0x05` on the `col02` collection. The
first live controller `00:06:f5:23:e2:d1` was written with Nightwing's
host address `5c:93:a2:9c:a8:a8`; Nightwing BlueZ is installed and
configured, but wireless connection is not verified until the controller
is unplugged from USB and observed over Bluetooth.
- PS3 Eyes now have a first sparse tracking surface instead of only cadence
proof. `MimirSparseFeatureTracker` detects Bayer/luma corner features,
links them into sensor-local tracks with clipspace position, velocity, age,