From 305707b335219d5fda0db0492609ba0366fbbe6b Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 17 Jun 2026 08:31:13 +0100 Subject: [PATCH 01/12] Reconcile Muninn Move identity rosters --- crates/muninn-daemon/src/main.rs | 140 ++++++++++++++++++++----------- 1 file changed, 90 insertions(+), 50 deletions(-) diff --git a/crates/muninn-daemon/src/main.rs b/crates/muninn-daemon/src/main.rs index ffdf7f5..3100bf4 100644 --- a/crates/muninn-daemon/src/main.rs +++ b/crates/muninn-daemon/src/main.rs @@ -218,8 +218,7 @@ fn serve(options: Options) -> Result<()> { sync_active_move_state_sources(&mut active_move_states, live_move_sources.clone()); { let mut node = open_node(&options, "muninn-daemon")?; - publish_move_identity_records(&mut node, &options, &live_move_sources)?; - publish_bluetooth_move_identity_records(&mut node, &options, &active_move_states)?; + reconcile_move_identity_records(&mut node, &options, &live_move_sources, &active_move_states)?; register_move_light_commands(&mut node, &options, &mut active_move_lights)?; tick_move_light_commands(&mut node, &mut active_move_lights, &mut HidMoveLightWriter)?; tick_default_move_light_pulse( @@ -318,6 +317,32 @@ fn publish_move_identity_records( Ok(()) } +fn reconcile_move_identity_records( + node: &mut cultmesh_rs::CultMeshNode, + options: &Options, + sources: &[MoveStateSource], + active: &[ActiveMoveStateSource], +) -> Result<()> { + publish_move_identity_records(node, options, sources)?; + publish_bluetooth_move_identity_records(node, options, active)?; + + let current_ids = current_move_identity_records_from_sources(options, sources)? + .into_iter() + .map(|identity| identity.identity_id) + .collect::>(); + let existing = node.cache().get_all::()?; + for identity in existing { + if identity.host_id == options.host_id + && !current_ids + .iter() + .any(|current| current == &identity.identity_id) + { + node.delete::(&identity.identity_id)?; + } + } + Ok(()) +} + #[cfg(unix)] fn publish_bluetooth_move_identity_records( node: &mut cultmesh_rs::CultMeshNode, @@ -3569,26 +3594,10 @@ fn move_source_status(options: Options) -> Result<()> { } fn move_identity_status(options: Options) -> Result<()> { - let node = open_node(&options, "muninn-move-identity-status")?; - let mut identities = node.cache().get_all::()?; - identities.extend(current_move_identity_records(&options)?); - identities.retain(|identity| identity.host_id == options.host_id); + let mut identities = current_move_identity_records(&options)?; if let Some(move_filter) = options.move_filter.as_deref() { identities.retain(|identity| identity.move_id == move_filter); } - for move_id in live_move_identity_ids(&options) { - if options - .move_filter - .as_deref() - .is_some_and(|move_filter| move_id != move_filter) - { - continue; - } - let key = format!("{}:{}:move-identity", options.host_id, move_id); - if let Some(identity) = node.get::(&key)? { - identities.push(identity); - } - } identities.sort_by(|a, b| { a.identity_id.cmp(&b.identity_id).then( unix_timestamp_sort_key(&b.observed_at).cmp(&unix_timestamp_sort_key(&a.observed_at)), @@ -3618,15 +3627,23 @@ fn move_identity_status(options: Options) -> Result<()> { } fn current_move_identity_records(options: &Options) -> Result> { + let sources = live_move_state_sources(options); + current_move_identity_records_from_sources(options, &sources) +} + +fn current_move_identity_records_from_sources( + options: &Options, + sources: &[MoveStateSource], +) -> Result> { let observed_at = timestamp()?; let bluetooth_host_address = move_host_address_for_claim(options).unwrap_or_default(); - let mut identities = live_move_state_sources(options) - .into_iter() + let mut identities = sources + .iter() .map(|source| MuninnMoveIdentityRecord { identity_id: format!("{}:{}:move-identity", options.host_id, source.move_id), host_id: options.host_id.clone(), - move_id: source.move_id, - source_path: source.hidraw_path, + move_id: source.move_id.clone(), + source_path: source.hidraw_path.clone(), bluetooth_host_address: bluetooth_host_address.clone(), state: "usb-visible".to_string(), detail: "Muninn currently sees this PS Move on a local USB/HID input path.".to_string(), @@ -3671,33 +3688,6 @@ fn current_bluetooth_move_identity_records( Vec::new() } -fn live_move_identity_ids(options: &Options) -> Vec { - let mut move_ids = live_move_state_sources(options) - .into_iter() - .map(|source| source.move_id) - .collect::>(); - for move_id in platform_bluetooth_move_identity_ids() { - if !move_ids.iter().any(|known| known.eq_ignore_ascii_case(&move_id)) { - move_ids.push(move_id); - } - } - move_ids -} - -#[cfg(unix)] -fn platform_bluetooth_move_identity_ids() -> Vec { - bluetoothctl_motion_controller_devices() - .unwrap_or_default() - .into_iter() - .filter_map(|device| bluetooth_address_move_id(&device.address)) - .collect() -} - -#[cfg(not(unix))] -fn platform_bluetooth_move_identity_ids() -> Vec { - Vec::new() -} - fn claim_move_host(options: Options) -> Result<()> { let host = options .move_host_address @@ -4906,6 +4896,56 @@ Device 00:07:04:A8:00:D0 (public) let _ = fs::remove_file(store_path); } + #[test] + fn move_identity_reconcile_deletes_stale_host_records() { + let store_path = std::env::temp_dir().join(format!( + "muninn-move-identity-reconcile-{}.cc", + timestamp_ns().unwrap() + )); + let options = Options::parse( + [ + "serve", + "--host", + "starfire", + "--store", + store_path.to_str().unwrap(), + "--move-host", + "5C:93:A2:9C:A8:A8", + ] + .into_iter() + .map(String::from), + ) + .unwrap(); + let mut node = open_node(&options, "muninn-move-identity-reconcile-test").unwrap(); + let stale = MuninnMoveIdentityRecord { + identity_id: "starfire:move-0006f523e2d1:move-identity".to_string(), + host_id: "starfire".to_string(), + move_id: "move-0006f523e2d1".to_string(), + source_path: "windows-psmove://stale".to_string(), + bluetooth_host_address: "5C:93:A2:9C:A8:A8".to_string(), + state: "usb-visible".to_string(), + detail: "stale test record".to_string(), + observed_at: "unix-1".to_string(), + }; + node.put(&stale.identity_id, &stale).unwrap(); + let current = vec![MoveStateSource { + move_id: "move-000704a800d0".to_string(), + hidraw_path: "windows-psmove://current".to_string(), + }]; + + reconcile_move_identity_records(&mut node, &options, ¤t, &[]).unwrap(); + + assert!(node + .get::("starfire:move-0006f523e2d1:move-identity") + .unwrap() + .is_none()); + let current_record = node + .get_required::("starfire:move-000704a800d0:move-identity") + .unwrap(); + assert_eq!(current_record.source_path, "windows-psmove://current"); + let _ = fs::remove_file(store_path); + } + #[test] fn joystick_move_state_publishes_fresh_record_without_new_events() { let store_path = std::env::temp_dir().join(format!( From 60d047c1dbe78510894faa86a606d6c2c8a4a6d8 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 17 Jun 2026 08:53:34 +0100 Subject: [PATCH 02/12] Back off Muninn Bluetooth Move pickup attempts --- crates/muninn-daemon/src/main.rs | 126 ++++++++++++++++++++++++------- 1 file changed, 99 insertions(+), 27 deletions(-) diff --git a/crates/muninn-daemon/src/main.rs b/crates/muninn-daemon/src/main.rs index 3100bf4..0fa3ad4 100644 --- a/crates/muninn-daemon/src/main.rs +++ b/crates/muninn-daemon/src/main.rs @@ -137,6 +137,12 @@ struct ActiveMoveStateSource { light_hidraw_path: Option, } +#[derive(Clone, Debug)] +struct BluetoothPickupAttempt { + address: String, + attempted_at: Instant, +} + #[derive(Clone, Debug, PartialEq, Eq)] struct DefaultMoveLightTarget { path: String, @@ -210,7 +216,7 @@ fn serve(options: Options) -> Result<()> { let mut last_default_move_light_write_at = None; let mut last_idunn_health_publish_attempt_at = None; let mut last_move_host_claim_attempt_at = None; - let mut last_move_bluetooth_pickup_attempt_at = None; + let mut bluetooth_pickup_attempts = Vec::new(); let mut active_move_states = active_move_state_sources(live_move_state_sources(&options)); loop { @@ -239,10 +245,7 @@ fn serve(options: Options) -> Result<()> { publish_runtime_boundary_records(&mut node, &options, "idle", &[])?; } claim_move_host_if_due(&options, &mut last_move_host_claim_attempt_at); - pickup_bluetooth_moves_if_due( - &active_move_states, - &mut last_move_bluetooth_pickup_attempt_at, - ); + pickup_bluetooth_moves_if_due(&active_move_states, &mut bluetooth_pickup_attempts); publish_daemon_health_if_configured( &options, &mut last_idunn_health_publish_attempt_at, @@ -463,18 +466,9 @@ fn claim_move_host_if_due(options: &Options, last_attempt_at: &mut Option, + attempts: &mut Vec, ) { - let cadence = Duration::from_secs(5); - if last_attempt_at - .as_ref() - .is_some_and(|instant| instant.elapsed() < cadence) - { - return; - } - *last_attempt_at = Some(Instant::now()); - - if let Err(error) = pickup_bluetooth_moves(active) { + if let Err(error) = pickup_bluetooth_moves(active, attempts) { eprintln!("Muninn could not attempt PS Move Bluetooth pickup: {error:#}"); } } @@ -506,7 +500,11 @@ fn prepare_move_bluetooth_host_for_claim() -> Result<()> { } #[cfg(unix)] -fn pickup_bluetooth_moves(active: &[ActiveMoveStateSource]) -> Result<()> { +fn pickup_bluetooth_moves( + active: &[ActiveMoveStateSource], + attempts: &mut Vec, +) -> Result<()> { + let cadence = Duration::from_secs(30); let devices = bluetoothctl_motion_controller_devices()?; for device in devices { if device.connected @@ -515,12 +513,19 @@ fn pickup_bluetooth_moves(active: &[ActiveMoveStateSource]) -> Result<()> { { continue; } + if bluetooth_pickup_recently_attempted(attempts, &device.address, cadence) { + continue; + } + record_bluetooth_pickup_attempt(attempts, &device.address); match bluetoothctl_connect_device(&device.address) { - Ok(true) => println!( - "bluetooth_move_pickup address={} state=connected", - device.address + Ok(outcome) if outcome.connected => println!( + "bluetooth_move_pickup address={} state=connected detail={}", + device.address, outcome.detail + ), + Ok(outcome) => println!( + "bluetooth_move_pickup address={} state=waiting detail={}", + device.address, outcome.detail ), - Ok(false) => {} Err(error) => eprintln!( "bluetooth_move_pickup address={} state=failed error={error:#}", device.address @@ -531,10 +536,31 @@ fn pickup_bluetooth_moves(active: &[ActiveMoveStateSource]) -> Result<()> { } #[cfg(not(unix))] -fn pickup_bluetooth_moves(_active: &[ActiveMoveStateSource]) -> Result<()> { +fn pickup_bluetooth_moves( + _active: &[ActiveMoveStateSource], + _attempts: &mut Vec, +) -> Result<()> { Ok(()) } +fn bluetooth_pickup_recently_attempted( + attempts: &[BluetoothPickupAttempt], + address: &str, + cadence: Duration, +) -> bool { + attempts.iter().any(|attempt| { + attempt.address.eq_ignore_ascii_case(address) && attempt.attempted_at.elapsed() < cadence + }) +} + +fn record_bluetooth_pickup_attempt(attempts: &mut Vec, address: &str) { + attempts.retain(|attempt| !attempt.address.eq_ignore_ascii_case(address)); + attempts.push(BluetoothPickupAttempt { + address: address.to_string(), + attempted_at: Instant::now(), + }); +} + #[cfg(unix)] fn active_move_source_has_bluetooth_address( active: &[ActiveMoveStateSource], @@ -562,6 +588,12 @@ fn bluetooth_address_move_id(address: &str) -> Option { }) } +#[derive(Clone, Debug, PartialEq, Eq)] +struct BluetoothConnectOutcome { + connected: bool, + detail: String, +} + fn move_host_address_for_claim(options: &Options) -> Option { if let Some(host) = options.move_host_address.as_deref() { if !host.trim().is_empty() { @@ -2031,10 +2063,10 @@ fn bluetoothctl_info_flag(text: &str, name: &str) -> bool { } #[cfg(unix)] -fn bluetoothctl_connect_device(address: &str) -> Result { +fn bluetoothctl_connect_device(address: &str) -> Result { let mut child = Command::new("bluetoothctl") .args(["connect", address]) - .stdout(Stdio::null()) + .stdout(Stdio::piped()) .stderr(Stdio::piped()) .spawn() .with_context(|| format!("bluetoothctl connect {address} could not start"))?; @@ -2044,17 +2076,57 @@ fn bluetoothctl_connect_device(address: &str) -> Result { .try_wait() .with_context(|| format!("waiting for bluetoothctl connect {address}"))? { - return Ok(status.success()); + let output = child + .wait_with_output() + .with_context(|| format!("collecting bluetoothctl connect {address} output"))?; + let detail = bluetoothctl_output_detail(&output.stdout, &output.stderr); + return Ok(BluetoothConnectOutcome { + connected: status.success(), + detail, + }); } if Instant::now() >= deadline { let _ = child.kill(); - let _ = child.wait(); - return Ok(false); + let output = child + .wait_with_output() + .with_context(|| format!("collecting timed-out bluetoothctl connect {address} output"))?; + let detail = bluetoothctl_output_detail(&output.stdout, &output.stderr); + return Ok(BluetoothConnectOutcome { + connected: false, + detail: if detail.is_empty() { + "timeout".to_string() + } else { + format!("timeout; {detail}") + }, + }); } thread::sleep(Duration::from_millis(50)); } } +#[cfg(unix)] +fn bluetoothctl_output_detail(stdout: &[u8], stderr: &[u8]) -> String { + let mut detail = String::new(); + for text in [stdout, stderr] { + let text = String::from_utf8_lossy(text); + for line in text.lines() { + let line = line.trim(); + if line.is_empty() || line.starts_with("Attempting to connect") { + continue; + } + if !detail.is_empty() { + detail.push_str("; "); + } + detail.push_str(line); + } + } + if detail.is_empty() { + "no bluetoothctl detail".to_string() + } else { + detail + } +} + #[cfg(not(unix))] fn platform_default_bluetooth_host_address() -> Option { None From ac3b64b6d8afd483cd4c5370b5680c656b44ffff Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 17 Jun 2026 09:30:14 +0100 Subject: [PATCH 03/12] Classify Bluetooth Move input sources --- crates/muninn-daemon/src/main.rs | 108 +++++++++++++++++++++++++++---- 1 file changed, 97 insertions(+), 11 deletions(-) diff --git a/crates/muninn-daemon/src/main.rs b/crates/muninn-daemon/src/main.rs index 0fa3ad4..af7da31 100644 --- a/crates/muninn-daemon/src/main.rs +++ b/crates/muninn-daemon/src/main.rs @@ -305,14 +305,15 @@ fn publish_move_identity_records( let observed_at = timestamp()?; let bluetooth_host_address = options.move_host_address.clone().unwrap_or_default(); for source in sources { + let (state, detail) = move_identity_source_state_and_detail(&source.hidraw_path); let record = MuninnMoveIdentityRecord { identity_id: format!("{}:{}:move-identity", options.host_id, source.move_id), host_id: options.host_id.clone(), move_id: source.move_id.clone(), source_path: source.hidraw_path.clone(), bluetooth_host_address: bluetooth_host_address.clone(), - state: "usb-visible".to_string(), - detail: "Muninn discovered this PS Move on a local USB/HID input path; controller-state records may be absent when the platform HID input collection is silent.".to_string(), + state, + detail, observed_at: observed_at.clone(), }; node.put(&record.identity_id, &record)?; @@ -320,6 +321,64 @@ fn publish_move_identity_records( Ok(()) } +fn move_identity_source_state_and_detail(source_path: &str) -> (String, String) { + if is_bluetooth_move_source_path(source_path) { + return ( + "bluetooth-connected".to_string(), + "Muninn currently sees this PS Move through a local Bluetooth input path.".to_string(), + ); + } + ( + "usb-visible".to_string(), + "Muninn discovered this PS Move on a local USB/HID input path; controller-state records may be absent when the platform HID input collection is silent.".to_string(), + ) +} + +#[cfg(unix)] +fn is_bluetooth_move_source_path(source_path: &str) -> bool { + if is_joystick_path(source_path) { + let Some(name) = Path::new(source_path).file_name().and_then(|name| name.to_str()) else { + return false; + }; + let Some(sysfs_device) = + fs::canonicalize(format!("/sys/class/input/{name}/device")).ok() + else { + return false; + }; + return is_bluetooth_move_uevent(&read_move_uevent_chain(&sysfs_device)); + } + + if source_path.contains("/dev/hidraw") { + let Some(name) = Path::new(source_path).file_name().and_then(|name| name.to_str()) else { + return false; + }; + let Ok(uevent) = + fs::read_to_string(format!("/sys/class/hidraw/{name}/device/uevent")) + else { + return false; + }; + return is_bluetooth_move_uevent(&uevent); + } + + source_path + .strip_prefix("bluetooth:") + .is_some_and(|address| bluetooth_address_move_id(address).is_some()) +} + +#[cfg(not(unix))] +fn is_bluetooth_move_source_path(source_path: &str) -> bool { + source_path + .strip_prefix("bluetooth:") + .is_some_and(|address| bluetooth_address_move_id(address).is_some()) +} + +fn is_bluetooth_move_uevent(uevent: &str) -> bool { + uevent.contains("PRODUCT=5/54c/3d5") + || uevent.contains("HID_ID=0005:0000054C:000003D5") + || uevent.contains("MODALIAS=input:b0005v054Cp03D5") + || uevent.contains("MODALIAS=hid:b0005") +} + fn reconcile_move_identity_records( node: &mut cultmesh_rs::CultMeshNode, options: &Options, @@ -3711,15 +3770,18 @@ fn current_move_identity_records_from_sources( let bluetooth_host_address = move_host_address_for_claim(options).unwrap_or_default(); let mut identities = sources .iter() - .map(|source| MuninnMoveIdentityRecord { - identity_id: format!("{}:{}:move-identity", options.host_id, source.move_id), - host_id: options.host_id.clone(), - move_id: source.move_id.clone(), - source_path: source.hidraw_path.clone(), - bluetooth_host_address: bluetooth_host_address.clone(), - state: "usb-visible".to_string(), - detail: "Muninn currently sees this PS Move on a local USB/HID input path.".to_string(), - observed_at: observed_at.clone(), + .map(|source| { + let (state, detail) = move_identity_source_state_and_detail(&source.hidraw_path); + MuninnMoveIdentityRecord { + identity_id: format!("{}:{}:move-identity", options.host_id, source.move_id), + host_id: options.host_id.clone(), + move_id: source.move_id.clone(), + source_path: source.hidraw_path.clone(), + bluetooth_host_address: bluetooth_host_address.clone(), + state, + detail, + observed_at: observed_at.clone(), + } }) .collect::>(); identities.extend(current_bluetooth_move_identity_records(options, &observed_at)); @@ -4722,6 +4784,30 @@ Device 00:07:04:A8:00:D0 (public) assert_eq!(record.state, "bluetooth-waiting"); } + #[test] + fn move_identity_source_transport_distinguishes_usb_and_bluetooth() { + let usb = r#" +PRODUCT=3/54c/3d5/110 +NAME="Sony Computer Entertainment Motion Controller" +PHYS="usb-0000:00:14.0-3/input0" +MODALIAS=input:b0003v054Cp03D5e0110 +"#; + let bluetooth = r#" +PRODUCT=5/54c/3d5/220 +NAME="Motion Controller" +PHYS="5c:93:a2:9c:a8:a8" +UNIQ="00:06:f5:23:e2:d1" +MODALIAS=input:b0005v054Cp03D5e0220 +"#; + + assert!(!is_bluetooth_move_uevent(usb)); + assert!(is_bluetooth_move_uevent(bluetooth)); + assert_eq!( + move_identity_source_state_and_detail("bluetooth:00:06:F5:23:E2:D1").0, + "bluetooth-connected" + ); + } + #[cfg(windows)] #[test] fn windows_ps_move_source_token_preserves_concrete_hid_path() { From 201920bde3aae91bbf266f543dbf3dbdbdb78f11 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 17 Jun 2026 10:26:27 +0100 Subject: [PATCH 04/12] Let Bluetooth Move pickup report slow failures --- crates/muninn-daemon/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/muninn-daemon/src/main.rs b/crates/muninn-daemon/src/main.rs index af7da31..a766f3c 100644 --- a/crates/muninn-daemon/src/main.rs +++ b/crates/muninn-daemon/src/main.rs @@ -2129,7 +2129,7 @@ fn bluetoothctl_connect_device(address: &str) -> Result .stderr(Stdio::piped()) .spawn() .with_context(|| format!("bluetoothctl connect {address} could not start"))?; - let deadline = Instant::now() + Duration::from_secs(3); + let deadline = Instant::now() + Duration::from_secs(15); loop { if let Some(status) = child .try_wait() From 33942d7cfad4a8be0bbf0e3a0fa472f75a19dacf Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 17 Jun 2026 10:57:20 +0100 Subject: [PATCH 05/12] Publish Bluetooth Move pickup detail --- crates/muninn-daemon/src/main.rs | 110 ++++++++++++++++++++++++++----- 1 file changed, 95 insertions(+), 15 deletions(-) diff --git a/crates/muninn-daemon/src/main.rs b/crates/muninn-daemon/src/main.rs index a766f3c..769248f 100644 --- a/crates/muninn-daemon/src/main.rs +++ b/crates/muninn-daemon/src/main.rs @@ -141,6 +141,7 @@ struct ActiveMoveStateSource { struct BluetoothPickupAttempt { address: String, attempted_at: Instant, + detail: String, } #[derive(Clone, Debug, PartialEq, Eq)] @@ -222,9 +223,16 @@ fn serve(options: Options) -> Result<()> { loop { let live_move_sources = live_move_state_sources(&options); sync_active_move_state_sources(&mut active_move_states, live_move_sources.clone()); + pickup_bluetooth_moves_if_due(&active_move_states, &mut bluetooth_pickup_attempts); { let mut node = open_node(&options, "muninn-daemon")?; - reconcile_move_identity_records(&mut node, &options, &live_move_sources, &active_move_states)?; + reconcile_move_identity_records( + &mut node, + &options, + &live_move_sources, + &active_move_states, + &bluetooth_pickup_attempts, + )?; register_move_light_commands(&mut node, &options, &mut active_move_lights)?; tick_move_light_commands(&mut node, &mut active_move_lights, &mut HidMoveLightWriter)?; tick_default_move_light_pulse( @@ -245,7 +253,6 @@ fn serve(options: Options) -> Result<()> { publish_runtime_boundary_records(&mut node, &options, "idle", &[])?; } claim_move_host_if_due(&options, &mut last_move_host_claim_attempt_at); - pickup_bluetooth_moves_if_due(&active_move_states, &mut bluetooth_pickup_attempts); publish_daemon_health_if_configured( &options, &mut last_idunn_health_publish_attempt_at, @@ -384,9 +391,10 @@ fn reconcile_move_identity_records( options: &Options, sources: &[MoveStateSource], active: &[ActiveMoveStateSource], + bluetooth_pickup_attempts: &[BluetoothPickupAttempt], ) -> Result<()> { publish_move_identity_records(node, options, sources)?; - publish_bluetooth_move_identity_records(node, options, active)?; + publish_bluetooth_move_identity_records(node, options, active, bluetooth_pickup_attempts)?; let current_ids = current_move_identity_records_from_sources(options, sources)? .into_iter() @@ -410,6 +418,7 @@ fn publish_bluetooth_move_identity_records( node: &mut cultmesh_rs::CultMeshNode, options: &Options, active: &[ActiveMoveStateSource], + bluetooth_pickup_attempts: &[BluetoothPickupAttempt], ) -> Result<()> { let observed_at = timestamp()?; let bluetooth_host_address = platform_default_bluetooth_host_address().unwrap_or_default(); @@ -429,6 +438,7 @@ fn publish_bluetooth_move_identity_records( &device, bluetooth_host_address.clone(), observed_at.clone(), + bluetooth_pickup_detail(bluetooth_pickup_attempts, &device.address), ) else { continue; }; @@ -442,6 +452,7 @@ fn build_bluetooth_move_identity_record( device: &BluetoothMoveDevice, bluetooth_host_address: String, observed_at: String, + pickup_detail: Option, ) -> Option { let move_id = bluetooth_address_move_id(&device.address)?; let state = if device.connected { @@ -451,13 +462,18 @@ fn build_bluetooth_move_identity_record( } else { "bluetooth-known" }; - let detail = if device.connected { + let mut detail = if device.connected { "Muninn sees this PS Move connected through BlueZ." } else if device.trusted { "Muninn sees this trusted PS Move in BlueZ and will attempt bounded pickup while disconnected." } else { "Muninn sees this PS Move in BlueZ, but it is not trusted for automatic pickup." - }; + } + .to_string(); + if let Some(pickup_detail) = pickup_detail.filter(|detail| !detail.trim().is_empty()) { + detail.push_str(" Last pickup attempt: "); + detail.push_str(pickup_detail.trim()); + } Some(MuninnMoveIdentityRecord { identity_id: format!("{}:{}:move-identity", options.host_id, move_id), host_id: options.host_id.clone(), @@ -465,7 +481,7 @@ fn build_bluetooth_move_identity_record( source_path: format!("bluetooth:{}", device.address), bluetooth_host_address, state: state.to_string(), - detail: detail.to_string(), + detail, observed_at, }) } @@ -475,6 +491,7 @@ fn publish_bluetooth_move_identity_records( _node: &mut cultmesh_rs::CultMeshNode, _options: &Options, _active: &[ActiveMoveStateSource], + _bluetooth_pickup_attempts: &[BluetoothPickupAttempt], ) -> Result<()> { Ok(()) } @@ -577,14 +594,20 @@ fn pickup_bluetooth_moves( } record_bluetooth_pickup_attempt(attempts, &device.address); match bluetoothctl_connect_device(&device.address) { - Ok(outcome) if outcome.connected => println!( - "bluetooth_move_pickup address={} state=connected detail={}", - device.address, outcome.detail - ), - Ok(outcome) => println!( - "bluetooth_move_pickup address={} state=waiting detail={}", - device.address, outcome.detail - ), + Ok(outcome) if outcome.connected => { + record_bluetooth_pickup_detail(attempts, &device.address, &outcome.detail); + println!( + "bluetooth_move_pickup address={} state=connected detail={}", + device.address, outcome.detail + ); + } + Ok(outcome) => { + record_bluetooth_pickup_detail(attempts, &device.address, &outcome.detail); + println!( + "bluetooth_move_pickup address={} state=waiting detail={}", + device.address, outcome.detail + ); + } Err(error) => eprintln!( "bluetooth_move_pickup address={} state=failed error={error:#}", device.address @@ -617,9 +640,33 @@ fn record_bluetooth_pickup_attempt(attempts: &mut Vec, a attempts.push(BluetoothPickupAttempt { address: address.to_string(), attempted_at: Instant::now(), + detail: "attempt in progress".to_string(), }); } +fn record_bluetooth_pickup_detail( + attempts: &mut [BluetoothPickupAttempt], + address: &str, + detail: &str, +) { + if let Some(attempt) = attempts + .iter_mut() + .find(|attempt| attempt.address.eq_ignore_ascii_case(address)) + { + attempt.detail = detail.trim().to_string(); + } +} + +fn bluetooth_pickup_detail( + attempts: &[BluetoothPickupAttempt], + address: &str, +) -> Option { + attempts + .iter() + .find(|attempt| attempt.address.eq_ignore_ascii_case(address)) + .map(|attempt| attempt.detail.clone()) +} + #[cfg(unix)] fn active_move_source_has_bluetooth_address( active: &[ActiveMoveStateSource], @@ -3809,6 +3856,7 @@ fn current_bluetooth_move_identity_records( &device, bluetooth_host_address.clone(), observed_at.to_string(), + None, ) }) .collect() @@ -4772,6 +4820,7 @@ Device 00:07:04:A8:00:D0 (public) &device, "5C:93:A2:9C:A8:A8".to_string(), "unix-1781667000".to_string(), + None, ) .unwrap(); @@ -4784,6 +4833,37 @@ Device 00:07:04:A8:00:D0 (public) assert_eq!(record.state, "bluetooth-waiting"); } + #[test] + fn bluetooth_move_identity_record_includes_last_pickup_detail() { + let options = Options::parse( + ["serve", "--host", "nightwing"] + .into_iter() + .map(String::from), + ) + .unwrap(); + let device = BluetoothMoveDevice { + address: "00:07:04:A6:BE:5F".to_string(), + trusted: true, + connected: false, + }; + + let record = build_bluetooth_move_identity_record( + &options, + &device, + "5C:93:A2:9C:A8:A8".to_string(), + "unix-1781667000".to_string(), + Some( + "Failed to connect: org.bluez.Error.Failed br-connection-create-socket" + .to_string(), + ), + ) + .unwrap(); + + assert_eq!(record.state, "bluetooth-waiting"); + assert!(record.detail.contains("Last pickup attempt: Failed to connect")); + assert!(record.detail.contains("br-connection-create-socket")); + } + #[test] fn move_identity_source_transport_distinguishes_usb_and_bluetooth() { let usb = r#" @@ -5091,7 +5171,7 @@ MODALIAS=input:b0005v054Cp03D5e0220 hidraw_path: "windows-psmove://current".to_string(), }]; - reconcile_move_identity_records(&mut node, &options, ¤t, &[]).unwrap(); + reconcile_move_identity_records(&mut node, &options, ¤t, &[], &[]).unwrap(); assert!(node .get::("starfire:move-0006f523e2d1:move-identity") From 960a1f6181df7bb0d75a8cc70d54e10a4d101917 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 17 Jun 2026 11:13:23 +0100 Subject: [PATCH 06/12] Keep Muninn Move pickup detail in identity state --- crates/muninn-daemon/src/main.rs | 13 +++++++- scripts/restart-nightwing-muninn.ps1 | 47 ++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/crates/muninn-daemon/src/main.rs b/crates/muninn-daemon/src/main.rs index 769248f..574a2d9 100644 --- a/crates/muninn-daemon/src/main.rs +++ b/crates/muninn-daemon/src/main.rs @@ -3772,7 +3772,18 @@ fn move_source_status(options: Options) -> Result<()> { } fn move_identity_status(options: Options) -> Result<()> { - let mut identities = current_move_identity_records(&options)?; + let node = open_node(&options, "muninn-move-identity-status")?; + let mut identities = node.cache().get_all::()?; + identities.retain(|identity| identity.host_id == options.host_id); + let current = current_move_identity_records(&options)?; + for identity in current { + if !identities + .iter() + .any(|existing| existing.identity_id == identity.identity_id) + { + identities.push(identity); + } + } if let Some(move_filter) = options.move_filter.as_deref() { identities.retain(|identity| identity.move_id == move_filter); } diff --git a/scripts/restart-nightwing-muninn.ps1 b/scripts/restart-nightwing-muninn.ps1 index c95d1dc..22f00f4 100644 --- a/scripts/restart-nightwing-muninn.ps1 +++ b/scripts/restart-nightwing-muninn.ps1 @@ -4,6 +4,7 @@ param( [string] $StorePath = "/home/metacrat/.local/state/gamecult/muninn/muninn.telemetry.cc", [string] $LogRoot = "/home/metacrat/.local/state/gamecult/muninn", [string[]] $MoveState = @(), + [string] $MoveHost = "5C:93:A2:9C:A8:A8", [string] $MoveEvidenceStream = "muninn:nightwing:move-evidence", [int] $IntervalSeconds = 15, [string] $IdunnRudpHealth = "10.77.0.2:17870", @@ -17,6 +18,46 @@ function Quote-ShSingle([string] $Value) { return "'" + ($Value -replace "'", "'\''") + "'" } +function Set-AsciiFile { + param( + [Parameter(Mandatory = $true)] [string] $Path, + [Parameter(Mandatory = $true)] [string] $Content + ) + + [System.IO.File]::WriteAllText($Path, ($Content -replace "`r?`n", "`n"), [System.Text.Encoding]::ASCII) +} + +function Invoke-UploadedShell { + param( + [Parameter(Mandatory = $true)] [string] $SshTarget, + [Parameter(Mandatory = $true)] [string] $RemoteScriptContent + ) + + $uploadId = [guid]::NewGuid().ToString("N") + $localTempRoot = Join-Path $env:TEMP "odin-nightwing-muninn-restart-$uploadId" + $localRemoteScript = Join-Path $localTempRoot "restart-nightwing-muninn-$uploadId.sh" + $localSftpBatch = Join-Path $localTempRoot "restart-nightwing-muninn-$uploadId.sftp" + $remoteScriptPath = "/tmp/restart-nightwing-muninn-$uploadId.sh" + + try { + New-Item -ItemType Directory -Force -Path $localTempRoot | Out-Null + Set-AsciiFile -Path $localRemoteScript -Content $RemoteScriptContent + Set-AsciiFile -Path $localSftpBatch -Content ('put "{0}" "{1}"' -f $localRemoteScript, $remoteScriptPath) + + & sftp.exe -b $localSftpBatch $SshTarget + if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE + } + + & ssh.exe -o BatchMode=yes -o ConnectTimeout=10 $SshTarget "chmod +x '$remoteScriptPath' && bash '$remoteScriptPath'" + $remoteExit = $LASTEXITCODE + & ssh.exe -o BatchMode=yes -o ConnectTimeout=10 $SshTarget "rm -f '$remoteScriptPath'" + exit $remoteExit + } finally { + Remove-Item -LiteralPath $localTempRoot -Recurse -Force -ErrorAction SilentlyContinue + } +} + $moveStateSpecs = @($MoveState | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }) if ($moveStateSpecs.Count -eq 0) { $claimScript = Join-Path $PSScriptRoot "claim-nightwing-usb-moves.ps1" @@ -46,7 +87,8 @@ done set -- serve \ --store '$StorePath' \ --log-root '$LogRoot' \ - --host nightwing + --host nightwing \ + --move-host '$MoveHost' $moveStateSetLines set -- "`$@" \ --move-evidence-stream '$MoveEvidenceStream' \ @@ -67,5 +109,4 @@ if ! pgrep -af '[m]uninn serve .*--host nightwing' | grep -F -- '--idunn-rudp-he fi "@ -ssh.exe -o BatchMode=yes -o ConnectTimeout=5 $SshTarget $remoteScript -exit $LASTEXITCODE +Invoke-UploadedShell -SshTarget $SshTarget -RemoteScriptContent $remoteScript From 162c67ad80d8f2f0944b4bde92a08bc2942665f6 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 17 Jun 2026 11:27:33 +0100 Subject: [PATCH 07/12] Preserve USB Move identity during Bluetooth pickup --- crates/muninn-daemon/src/main.rs | 35 ++++++++++++++++++++++++---- scripts/restart-nightwing-muninn.ps1 | 6 +++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/crates/muninn-daemon/src/main.rs b/crates/muninn-daemon/src/main.rs index 574a2d9..65afec2 100644 --- a/crates/muninn-daemon/src/main.rs +++ b/crates/muninn-daemon/src/main.rs @@ -427,10 +427,7 @@ fn publish_bluetooth_move_identity_records( let Some(move_id) = bluetooth_address_move_id(&device.address) else { continue; }; - if active.iter().any(|state| { - state.source.move_id.eq_ignore_ascii_case(&move_id) - && !is_joystick_path(&state.source.hidraw_path) - }) { + if active_usb_move_source_has_move_id(active, &move_id) { continue; } let Some(record) = build_bluetooth_move_identity_record( @@ -679,6 +676,13 @@ fn active_move_source_has_bluetooth_address( }) } +fn active_usb_move_source_has_move_id(active: &[ActiveMoveStateSource], move_id: &str) -> bool { + active.iter().any(|state| { + state.source.move_id.eq_ignore_ascii_case(move_id) + && move_identity_source_state_and_detail(&state.source.hidraw_path).0 == "usb-visible" + }) +} + fn bluetooth_address_move_id(address: &str) -> Option { parse_bluetooth_address_little_endian(address) .ok() @@ -4899,6 +4903,29 @@ MODALIAS=input:b0005v054Cp03D5e0220 ); } + #[test] + fn usb_visible_active_move_blocks_bluetooth_identity_overwrite() { + let active = vec![ActiveMoveStateSource { + source: MoveStateSource { + move_id: "move-000704a39772".to_string(), + hidraw_path: "/dev/input/js0".to_string(), + }, + sequence: 0, + joystick_axes: [0; 16], + joystick_buttons: [false; 32], + light_hidraw_path: None, + }]; + + assert!(active_usb_move_source_has_move_id( + &active, + "move-000704a39772" + )); + assert!(!active_usb_move_source_has_move_id( + &active, + "move-000704a800d0" + )); + } + #[cfg(windows)] #[test] fn windows_ps_move_source_token_preserves_concrete_hid_path() { diff --git a/scripts/restart-nightwing-muninn.ps1 b/scripts/restart-nightwing-muninn.ps1 index 22f00f4..70940b8 100644 --- a/scripts/restart-nightwing-muninn.ps1 +++ b/scripts/restart-nightwing-muninn.ps1 @@ -62,8 +62,14 @@ $moveStateSpecs = @($MoveState | Where-Object { -not [string]::IsNullOrWhiteSpac if ($moveStateSpecs.Count -eq 0) { $claimScript = Join-Path $PSScriptRoot "claim-nightwing-usb-moves.ps1" & powershell.exe -NoProfile -ExecutionPolicy Bypass -File $claimScript -SshTarget $SshTarget + if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE + } $sourceScript = Join-Path $PSScriptRoot "get-nightwing-move-state-sources.ps1" $moveStateSpecs = @(& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $sourceScript -SshTarget $SshTarget) + if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE + } } $moveStateSetLines = ($moveStateSpecs | ForEach-Object { From de998945ba2454cda601f74e3be8fc107e142d88 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 17 Jun 2026 11:54:28 +0100 Subject: [PATCH 08/12] Classify unreachable Bluetooth Moves --- crates/muninn-daemon/src/main.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/muninn-daemon/src/main.rs b/crates/muninn-daemon/src/main.rs index 65afec2..43ff48a 100644 --- a/crates/muninn-daemon/src/main.rs +++ b/crates/muninn-daemon/src/main.rs @@ -452,8 +452,13 @@ fn build_bluetooth_move_identity_record( pickup_detail: Option, ) -> Option { let move_id = bluetooth_address_move_id(&device.address)?; + let pickup_unreachable = pickup_detail + .as_deref() + .is_some_and(bluetooth_pickup_detail_is_unreachable); let state = if device.connected { "bluetooth-connected" + } else if device.trusted && pickup_unreachable { + "bluetooth-unreachable" } else if device.trusted { "bluetooth-waiting" } else { @@ -664,6 +669,12 @@ fn bluetooth_pickup_detail( .map(|attempt| attempt.detail.clone()) } +fn bluetooth_pickup_detail_is_unreachable(detail: &str) -> bool { + let normalized = detail.to_ascii_lowercase(); + normalized.contains("br-connection-create-socket") + || normalized.contains("host is down") +} + #[cfg(unix)] fn active_move_source_has_bluetooth_address( active: &[ActiveMoveStateSource], @@ -4874,7 +4885,7 @@ Device 00:07:04:A8:00:D0 (public) ) .unwrap(); - assert_eq!(record.state, "bluetooth-waiting"); + assert_eq!(record.state, "bluetooth-unreachable"); assert!(record.detail.contains("Last pickup attempt: Failed to connect")); assert!(record.detail.contains("br-connection-create-socket")); } From f17fc6f0ffb65addb640b15f32a7a904d53b8628 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 17 Jun 2026 12:10:15 +0100 Subject: [PATCH 09/12] Explain unreachable Move wake requirement --- crates/muninn-daemon/src/main.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/muninn-daemon/src/main.rs b/crates/muninn-daemon/src/main.rs index 43ff48a..655ff77 100644 --- a/crates/muninn-daemon/src/main.rs +++ b/crates/muninn-daemon/src/main.rs @@ -475,6 +475,11 @@ fn build_bluetooth_move_identity_record( if let Some(pickup_detail) = pickup_detail.filter(|detail| !detail.trim().is_empty()) { detail.push_str(" Last pickup attempt: "); detail.push_str(pickup_detail.trim()); + if pickup_unreachable { + detail.push_str( + "; BlueZ reports the controller host is down, so the Move is likely asleep/off-air. Wake the controller with the PS button or reattach USB for Muninn to refresh the host claim.", + ); + } } Some(MuninnMoveIdentityRecord { identity_id: format!("{}:{}:move-identity", options.host_id, move_id), @@ -4888,6 +4893,8 @@ Device 00:07:04:A8:00:D0 (public) assert_eq!(record.state, "bluetooth-unreachable"); assert!(record.detail.contains("Last pickup attempt: Failed to connect")); assert!(record.detail.contains("br-connection-create-socket")); + assert!(record.detail.contains("Wake the controller with the PS button")); + assert!(record.detail.contains("reattach USB")); } #[test] From 78b16d2a7464185cbb42185e23d14a828c51284f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 17 Jun 2026 12:29:41 +0100 Subject: [PATCH 10/12] Pickup released USB Moves immediately --- crates/muninn-daemon/src/main.rs | 261 +++++++++++++++++++++++-------- 1 file changed, 192 insertions(+), 69 deletions(-) diff --git a/crates/muninn-daemon/src/main.rs b/crates/muninn-daemon/src/main.rs index 655ff77..5cf089f 100644 --- a/crates/muninn-daemon/src/main.rs +++ b/crates/muninn-daemon/src/main.rs @@ -1,12 +1,12 @@ -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use cultmesh_rs::{ CultMesh, CultMeshNodeOptions, CultMeshSharedMemoryFrameRing, CultMeshStreamBodyTransport, CultMeshStreamCatalog, CultMeshStreamClock, CultMeshStreamDescriptor, CultMeshStreamKind, }; use cultnet_rs::{ - encode_cultnet_message_to_vec, CultNetMessage, CultNetRawDocumentRecord, - CultNetRawPayloadEncoding, CultNetRudpSocketTransportConnection, - CultNetRudpSocketTransportOptions, CultNetWireContract, + CultNetMessage, CultNetRawDocumentRecord, CultNetRawPayloadEncoding, + CultNetRudpSocketTransportConnection, CultNetRudpSocketTransportOptions, CultNetWireContract, + encode_cultnet_message_to_vec, }; use odin_core::{ EveProviderAdvertisementCompatRecord, IdunnDaemonHealthRecord, MuninnCaptureStreamRecord, @@ -222,7 +222,12 @@ fn serve(options: Options) -> Result<()> { loop { let live_move_sources = live_move_state_sources(&options); - sync_active_move_state_sources(&mut active_move_states, live_move_sources.clone()); + let released_usb_moves = + sync_active_move_state_sources(&mut active_move_states, live_move_sources.clone()); + clear_bluetooth_pickup_attempts_for_released_usb_moves( + &mut bluetooth_pickup_attempts, + &released_usb_moves, + ); pickup_bluetooth_moves_if_due(&active_move_states, &mut bluetooth_pickup_attempts); { let mut node = open_node(&options, "muninn-daemon")?; @@ -253,10 +258,7 @@ fn serve(options: Options) -> Result<()> { publish_runtime_boundary_records(&mut node, &options, "idle", &[])?; } claim_move_host_if_due(&options, &mut last_move_host_claim_attempt_at); - publish_daemon_health_if_configured( - &options, - &mut last_idunn_health_publish_attempt_at, - )?; + publish_daemon_health_if_configured(&options, &mut last_idunn_health_publish_attempt_at)?; let has_platform_default_move_lights = platform_default_move_lights_enabled(); if options.interval_seconds.is_none() && active_move_lights.is_empty() @@ -294,7 +296,16 @@ fn active_move_state_source(source: MoveStateSource) -> ActiveMoveStateSource { fn sync_active_move_state_sources( active: &mut Vec, desired: Vec, -) { +) -> Vec { + let released_usb_moves = active + .iter() + .filter(|state| { + !desired.iter().any(|source| source == &state.source) + && move_identity_source_state_and_detail(&state.source.hidraw_path).0 + == "usb-visible" + }) + .map(|state| state.source.move_id.clone()) + .collect(); active.retain(|state| desired.iter().any(|source| source == &state.source)); for source in desired { if active.iter().any(|state| state.source == source) { @@ -302,6 +313,7 @@ fn sync_active_move_state_sources( } active.push(active_move_state_source(source)); } + released_usb_moves } fn publish_move_identity_records( @@ -344,11 +356,13 @@ fn move_identity_source_state_and_detail(source_path: &str) -> (String, String) #[cfg(unix)] fn is_bluetooth_move_source_path(source_path: &str) -> bool { if is_joystick_path(source_path) { - let Some(name) = Path::new(source_path).file_name().and_then(|name| name.to_str()) else { + let Some(name) = Path::new(source_path) + .file_name() + .and_then(|name| name.to_str()) + else { return false; }; - let Some(sysfs_device) = - fs::canonicalize(format!("/sys/class/input/{name}/device")).ok() + let Some(sysfs_device) = fs::canonicalize(format!("/sys/class/input/{name}/device")).ok() else { return false; }; @@ -356,11 +370,13 @@ fn is_bluetooth_move_source_path(source_path: &str) -> bool { } if source_path.contains("/dev/hidraw") { - let Some(name) = Path::new(source_path).file_name().and_then(|name| name.to_str()) else { + let Some(name) = Path::new(source_path) + .file_name() + .and_then(|name| name.to_str()) + else { return false; }; - let Ok(uevent) = - fs::read_to_string(format!("/sys/class/hidraw/{name}/device/uevent")) + let Ok(uevent) = fs::read_to_string(format!("/sys/class/hidraw/{name}/device/uevent")) else { return false; }; @@ -642,6 +658,21 @@ fn bluetooth_pickup_recently_attempted( }) } +fn clear_bluetooth_pickup_attempts_for_released_usb_moves( + attempts: &mut Vec, + move_ids: &[String], +) { + for move_id in move_ids { + if let Some(address) = move_id_bluetooth_address(move_id) { + clear_bluetooth_pickup_attempt(attempts, &address); + } + } +} + +fn clear_bluetooth_pickup_attempt(attempts: &mut Vec, address: &str) { + attempts.retain(|attempt| !attempt.address.eq_ignore_ascii_case(address)); +} + fn record_bluetooth_pickup_attempt(attempts: &mut Vec, address: &str) { attempts.retain(|attempt| !attempt.address.eq_ignore_ascii_case(address)); attempts.push(BluetoothPickupAttempt { @@ -664,10 +695,7 @@ fn record_bluetooth_pickup_detail( } } -fn bluetooth_pickup_detail( - attempts: &[BluetoothPickupAttempt], - address: &str, -) -> Option { +fn bluetooth_pickup_detail(attempts: &[BluetoothPickupAttempt], address: &str) -> Option { attempts .iter() .find(|attempt| attempt.address.eq_ignore_ascii_case(address)) @@ -676,8 +704,7 @@ fn bluetooth_pickup_detail( fn bluetooth_pickup_detail_is_unreachable(detail: &str) -> bool { let normalized = detail.to_ascii_lowercase(); - normalized.contains("br-connection-create-socket") - || normalized.contains("host is down") + normalized.contains("br-connection-create-socket") || normalized.contains("host is down") } #[cfg(unix)] @@ -714,6 +741,18 @@ fn bluetooth_address_move_id(address: &str) -> Option { }) } +fn move_id_bluetooth_address(move_id: &str) -> Option { + let hex = move_id.strip_prefix("move-")?; + if hex.len() != 12 || !hex.as_bytes().iter().all(|byte| byte.is_ascii_hexdigit()) { + return None; + } + let mut parts = Vec::new(); + for index in (0..hex.len()).step_by(2) { + parts.push(hex[index..index + 2].to_ascii_uppercase()); + } + Some(parts.join(":")) +} + #[derive(Clone, Debug, PartialEq, Eq)] struct BluetoothConnectOutcome { connected: bool, @@ -2213,9 +2252,9 @@ fn bluetoothctl_connect_device(address: &str) -> Result } if Instant::now() >= deadline { let _ = child.kill(); - let output = child - .wait_with_output() - .with_context(|| format!("collecting timed-out bluetoothctl connect {address} output"))?; + let output = child.wait_with_output().with_context(|| { + format!("collecting timed-out bluetoothctl connect {address} output") + })?; let detail = bluetoothctl_output_detail(&output.stdout, &output.stderr); return Ok(BluetoothConnectOutcome { connected: false, @@ -2383,12 +2422,12 @@ fn platform_default_move_lights_enabled() -> bool { #[cfg(windows)] fn windows_ps_move_light_paths() -> Result> { use windows_sys::Win32::Devices::DeviceAndDriverInstallation::{ - SetupDiDestroyDeviceInfoList, SetupDiEnumDeviceInterfaces, SetupDiGetClassDevsW, DIGCF_DEVICEINTERFACE, DIGCF_PRESENT, SP_DEVICE_INTERFACE_DATA, + SetupDiDestroyDeviceInfoList, SetupDiEnumDeviceInterfaces, SetupDiGetClassDevsW, }; use windows_sys::Win32::Devices::HumanInterfaceDevice::{ - HidD_FreePreparsedData, HidD_GetAttributes, HidD_GetHidGuid, HidD_GetPreparsedData, - HidP_GetCaps, HIDD_ATTRIBUTES, HIDP_CAPS, HIDP_STATUS_SUCCESS, + HIDD_ATTRIBUTES, HIDP_CAPS, HIDP_STATUS_SUCCESS, HidD_FreePreparsedData, + HidD_GetAttributes, HidD_GetHidGuid, HidD_GetPreparsedData, HidP_GetCaps, }; use windows_sys::Win32::Foundation::{CloseHandle, INVALID_HANDLE_VALUE}; use windows_sys::Win32::Storage::FileSystem::{ @@ -2493,12 +2532,12 @@ fn windows_ps_move_light_paths() -> Result> { #[cfg(windows)] fn windows_ps_move_state_paths() -> Result> { use windows_sys::Win32::Devices::DeviceAndDriverInstallation::{ - SetupDiDestroyDeviceInfoList, SetupDiEnumDeviceInterfaces, SetupDiGetClassDevsW, DIGCF_DEVICEINTERFACE, DIGCF_PRESENT, SP_DEVICE_INTERFACE_DATA, + SetupDiDestroyDeviceInfoList, SetupDiEnumDeviceInterfaces, SetupDiGetClassDevsW, }; use windows_sys::Win32::Devices::HumanInterfaceDevice::{ - HidD_FreePreparsedData, HidD_GetAttributes, HidD_GetHidGuid, HidD_GetPreparsedData, - HidP_GetCaps, HIDD_ATTRIBUTES, HIDP_CAPS, HIDP_STATUS_SUCCESS, + HIDD_ATTRIBUTES, HIDP_CAPS, HIDP_STATUS_SUCCESS, HidD_FreePreparsedData, + HidD_GetAttributes, HidD_GetHidGuid, HidD_GetPreparsedData, HidP_GetCaps, }; use windows_sys::Win32::Foundation::{CloseHandle, INVALID_HANDLE_VALUE}; use windows_sys::Win32::Storage::FileSystem::{ @@ -2604,11 +2643,11 @@ fn windows_ps_move_state_paths() -> Result> { #[cfg(windows)] fn windows_ps_move_identity_by_physical_key() -> Result> { use windows_sys::Win32::Devices::DeviceAndDriverInstallation::{ - SetupDiDestroyDeviceInfoList, SetupDiEnumDeviceInterfaces, SetupDiGetClassDevsW, DIGCF_DEVICEINTERFACE, DIGCF_PRESENT, SP_DEVICE_INTERFACE_DATA, + SetupDiDestroyDeviceInfoList, SetupDiEnumDeviceInterfaces, SetupDiGetClassDevsW, }; use windows_sys::Win32::Devices::HumanInterfaceDevice::{ - HidD_GetAttributes, HidD_GetHidGuid, HIDD_ATTRIBUTES, + HIDD_ATTRIBUTES, HidD_GetAttributes, HidD_GetHidGuid, }; use windows_sys::Win32::Foundation::{CloseHandle, INVALID_HANDLE_VALUE}; use windows_sys::Win32::Storage::FileSystem::{ @@ -2784,12 +2823,12 @@ fn windows_ps_move_bluetooth_addresses(handle: *mut std::ffi::c_void) -> Option< #[cfg(windows)] fn windows_claim_ps_move_host(host: &[u8; 6]) -> Result { use windows_sys::Win32::Devices::DeviceAndDriverInstallation::{ - SetupDiDestroyDeviceInfoList, SetupDiEnumDeviceInterfaces, SetupDiGetClassDevsW, DIGCF_DEVICEINTERFACE, DIGCF_PRESENT, SP_DEVICE_INTERFACE_DATA, + SetupDiDestroyDeviceInfoList, SetupDiEnumDeviceInterfaces, SetupDiGetClassDevsW, }; use windows_sys::Win32::Devices::HumanInterfaceDevice::{ - HidD_FreePreparsedData, HidD_GetAttributes, HidD_GetHidGuid, HidD_GetPreparsedData, - HidD_SetFeature, HidP_GetCaps, HIDD_ATTRIBUTES, HIDP_CAPS, HIDP_STATUS_SUCCESS, + HIDD_ATTRIBUTES, HIDP_CAPS, HIDP_STATUS_SUCCESS, HidD_FreePreparsedData, + HidD_GetAttributes, HidD_GetHidGuid, HidD_GetPreparsedData, HidD_SetFeature, HidP_GetCaps, }; use windows_sys::Win32::Foundation::{CloseHandle, INVALID_HANDLE_VALUE}; use windows_sys::Win32::Storage::FileSystem::{ @@ -2930,8 +2969,8 @@ fn windows_claim_ps_move_host(host: &[u8; 6]) -> Result { #[cfg(windows)] fn windows_ps_move_input_report(source: &str) -> Result>> { use windows_sys::Win32::Devices::HumanInterfaceDevice::{ - HidD_FreePreparsedData, HidD_GetInputReport, HidD_GetPreparsedData, HidP_GetCaps, - HIDP_CAPS, HIDP_STATUS_SUCCESS, + HIDP_CAPS, HIDP_STATUS_SUCCESS, HidD_FreePreparsedData, HidD_GetInputReport, + HidD_GetPreparsedData, HidP_GetCaps, }; use windows_sys::Win32::Foundation::{CloseHandle, GENERIC_READ, INVALID_HANDLE_VALUE}; use windows_sys::Win32::Storage::FileSystem::{ @@ -3022,8 +3061,8 @@ fn windows_read_hid_interrupt_report( WAIT_OBJECT_0, WAIT_TIMEOUT, }; use windows_sys::Win32::Storage::FileSystem::ReadFile; - use windows_sys::Win32::System::Threading::{CreateEventW, WaitForSingleObject}; use windows_sys::Win32::System::IO::{CancelIoEx, GetOverlappedResult, OVERLAPPED}; + use windows_sys::Win32::System::Threading::{CreateEventW, WaitForSingleObject}; let event = unsafe { CreateEventW(std::ptr::null(), 1, 0, std::ptr::null()) }; if event.is_null() { @@ -3109,7 +3148,7 @@ unsafe fn windows_hid_interface_path( interface_data: &mut windows_sys::Win32::Devices::DeviceAndDriverInstallation::SP_DEVICE_INTERFACE_DATA, ) -> Option { use windows_sys::Win32::Devices::DeviceAndDriverInstallation::{ - SetupDiGetDeviceInterfaceDetailW, SP_DEVICE_INTERFACE_DETAIL_DATA_W, + SP_DEVICE_INTERFACE_DETAIL_DATA_W, SetupDiGetDeviceInterfaceDetailW, }; let mut required_size = 0; @@ -3166,8 +3205,8 @@ unsafe fn windows_hid_interface_path( fn write_windows_hid_report(path: &str, report: &[u8]) -> Result<()> { use windows_sys::Win32::Foundation::{CloseHandle, GENERIC_WRITE, INVALID_HANDLE_VALUE}; use windows_sys::Win32::Storage::FileSystem::{ - CreateFileW, WriteFile, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, FILE_SHARE_WRITE, - OPEN_EXISTING, + CreateFileW, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, FILE_SHARE_WRITE, OPEN_EXISTING, + WriteFile, }; let wide = wide_null(path); @@ -3720,7 +3759,10 @@ fn move_state_status(options: Options) -> Result<()> { { continue; } - let key = format!("{}:{}:move-controller-state", options.host_id, source.move_id); + let key = format!( + "{}:{}:move-controller-state", + options.host_id, source.move_id + ); if let Some(state) = node.get::(&key)? { states.push(state); } @@ -3734,7 +3776,9 @@ fn move_state_status(options: Options) -> Result<()> { ) .then(a.sequence.cmp(&b.sequence)) }); - states.dedup_by(|left, right| left.stream_id == right.stream_id && left.sequence == right.sequence); + states.dedup_by(|left, right| { + left.stream_id == right.stream_id && left.sequence == right.sequence + }); if states.is_empty() { println!( "No Muninn Move controller state records found for host {}.", @@ -3862,7 +3906,10 @@ fn current_move_identity_records_from_sources( } }) .collect::>(); - identities.extend(current_bluetooth_move_identity_records(options, &observed_at)); + identities.extend(current_bluetooth_move_identity_records( + options, + &observed_at, + )); identities.sort_by(|a, b| { a.identity_id.cmp(&b.identity_id).then( unix_timestamp_sort_key(&b.observed_at).cmp(&unix_timestamp_sort_key(&a.observed_at)), @@ -4599,9 +4646,11 @@ mod tests { let sources = available_sources(&options); assert!(sources.iter().any(|source| source.starts_with("screen:"))); - assert!(sources - .iter() - .any(|source| source.starts_with("audio-loopback:"))); + assert!( + sources + .iter() + .any(|source| source.starts_with("audio-loopback:")) + ); } #[test] @@ -4804,10 +4853,10 @@ mod tests { .as_deref(), Some("00:07:04:A8:00:D0") ); - assert!(parse_bluetoothctl_motion_controller_device_line( - "Device 00:11:22:33:44:55 Keyboard" - ) - .is_none()); + assert!( + parse_bluetoothctl_motion_controller_device_line("Device 00:11:22:33:44:55 Keyboard") + .is_none() + ); } #[test] @@ -4832,6 +4881,19 @@ Device 00:07:04:A8:00:D0 (public) ); } + #[test] + fn move_id_maps_to_bluetooth_address() { + assert_eq!( + move_id_bluetooth_address("move-000704a39772").as_deref(), + Some("00:07:04:A3:97:72") + ); + assert_eq!( + move_id_bluetooth_address("move-000704a800d0").as_deref(), + Some("00:07:04:A8:00:D0") + ); + assert!(move_id_bluetooth_address("move-not-a-controller").is_none()); + } + #[test] fn bluetooth_move_identity_record_describes_waiting_pickup() { let options = Options::parse( @@ -4884,16 +4946,23 @@ Device 00:07:04:A8:00:D0 (public) "5C:93:A2:9C:A8:A8".to_string(), "unix-1781667000".to_string(), Some( - "Failed to connect: org.bluez.Error.Failed br-connection-create-socket" - .to_string(), + "Failed to connect: org.bluez.Error.Failed br-connection-create-socket".to_string(), ), ) .unwrap(); assert_eq!(record.state, "bluetooth-unreachable"); - assert!(record.detail.contains("Last pickup attempt: Failed to connect")); + assert!( + record + .detail + .contains("Last pickup attempt: Failed to connect") + ); assert!(record.detail.contains("br-connection-create-socket")); - assert!(record.detail.contains("Wake the controller with the PS button")); + assert!( + record + .detail + .contains("Wake the controller with the PS button") + ); assert!(record.detail.contains("reattach USB")); } @@ -5229,10 +5298,11 @@ MODALIAS=input:b0005v054Cp03D5e0220 reconcile_move_identity_records(&mut node, &options, ¤t, &[], &[]).unwrap(); - assert!(node - .get::("starfire:move-0006f523e2d1:move-identity") - .unwrap() - .is_none()); + assert!( + node.get::("starfire:move-0006f523e2d1:move-identity") + .unwrap() + .is_none() + ); let current_record = node .get_required::("starfire:move-000704a800d0:move-identity") .unwrap(); @@ -5321,11 +5391,12 @@ MODALIAS=input:b0005v054Cp03D5e0220 publish_move_controller_states(&mut node, &options, &mut active, &mut reader, None) .unwrap(); - assert!(node - .get_required::( + assert!( + node.get_required::( "nightwing:missing:move-controller-state" ) - .is_err()); + .is_err() + ); let record = node .get_required::( "nightwing:present:move-controller-state", @@ -5357,13 +5428,65 @@ MODALIAS=input:b0005v054Cp03D5e0220 ); assert_eq!(active.len(), 2); - assert!(active - .iter() - .any(|state| state.source.move_id == "move-new")); + assert!( + active + .iter() + .any(|state| state.source.move_id == "move-new") + ); assert!(active.iter().any(|state| state.source.move_id == "move-bt")); - assert!(!active - .iter() - .any(|state| state.source.move_id == "move-old")); + assert!( + !active + .iter() + .any(|state| state.source.move_id == "move-old") + ); + } + + #[test] + fn active_move_state_sync_reports_released_usb_moves() { + let mut active = active_move_state_sources(vec![ + MoveStateSource { + move_id: "move-000704a39772".to_string(), + hidraw_path: "/dev/input/js0".to_string(), + }, + MoveStateSource { + move_id: "move-0006f523e2d1".to_string(), + hidraw_path: "bluetooth:00:06:F5:23:E2:D1".to_string(), + }, + ]); + + let released = sync_active_move_state_sources( + &mut active, + vec![MoveStateSource { + move_id: "move-0006f523e2d1".to_string(), + hidraw_path: "bluetooth:00:06:F5:23:E2:D1".to_string(), + }], + ); + + assert_eq!(released, vec!["move-000704a39772"]); + assert_eq!(active.len(), 1); + assert_eq!(active[0].source.move_id, "move-0006f523e2d1"); + } + + #[test] + fn released_usb_move_clears_pickup_backoff() { + let mut attempts = Vec::new(); + record_bluetooth_pickup_attempt(&mut attempts, "00:07:04:A3:97:72"); + assert!(bluetooth_pickup_recently_attempted( + &attempts, + "00:07:04:A3:97:72", + Duration::from_secs(30) + )); + + clear_bluetooth_pickup_attempts_for_released_usb_moves( + &mut attempts, + &["move-000704a39772".to_string()], + ); + + assert!(!bluetooth_pickup_recently_attempted( + &attempts, + "00:07:04:A3:97:72", + Duration::from_secs(30) + )); } #[test] From 75c3683ffce316953219a071b27bd8610454be34 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 17 Jun 2026 13:14:38 +0100 Subject: [PATCH 11/12] Read paired Move host for Windows identity status --- crates/muninn-daemon/src/main.rs | 153 ++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 2 deletions(-) diff --git a/crates/muninn-daemon/src/main.rs b/crates/muninn-daemon/src/main.rs index 5cf089f..de2d77a 100644 --- a/crates/muninn-daemon/src/main.rs +++ b/crates/muninn-daemon/src/main.rs @@ -2820,6 +2820,108 @@ fn windows_ps_move_bluetooth_addresses(handle: *mut std::ffi::c_void) -> Option< )) } +#[cfg(windows)] +fn windows_ps_move_paired_host_address(path: &str) -> Option { + if let Some(address) = windows_ps_move_paired_host_address_from_path(path) { + return Some(address); + } + let key = windows_ps_move_physical_key(path)?; + windows_ps_move_pairing_collection_paired_host_address(&key) +} + +#[cfg(windows)] +fn windows_ps_move_paired_host_address_from_path(path: &str) -> Option { + use windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE; + use windows_sys::Win32::Storage::FileSystem::{ + CreateFileW, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, FILE_SHARE_WRITE, OPEN_EXISTING, + }; + + let wide = wide_null(path); + let handle = unsafe { + CreateFileW( + wide.as_ptr(), + 0, + FILE_SHARE_READ | FILE_SHARE_WRITE, + std::ptr::null_mut(), + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + std::ptr::null_mut(), + ) + }; + if handle == INVALID_HANDLE_VALUE { + return None; + } + let paired_host = windows_ps_move_bluetooth_addresses(handle).map(|addresses| addresses.1); + unsafe { windows_sys::Win32::Foundation::CloseHandle(handle) }; + paired_host +} + +#[cfg(windows)] +fn windows_ps_move_pairing_collection_paired_host_address(physical_key: &str) -> Option { + use windows_sys::Win32::Devices::DeviceAndDriverInstallation::{ + DIGCF_DEVICEINTERFACE, DIGCF_PRESENT, SP_DEVICE_INTERFACE_DATA, + SetupDiDestroyDeviceInfoList, SetupDiEnumDeviceInterfaces, SetupDiGetClassDevsW, + }; + use windows_sys::Win32::Devices::HumanInterfaceDevice::HidD_GetHidGuid; + use windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE; + + let mut hid_guid = unsafe { std::mem::zeroed() }; + unsafe { HidD_GetHidGuid(&mut hid_guid) }; + let info_set = unsafe { + SetupDiGetClassDevsW( + &hid_guid, + std::ptr::null(), + std::ptr::null_mut(), + DIGCF_PRESENT | DIGCF_DEVICEINTERFACE, + ) + }; + if info_set == INVALID_HANDLE_VALUE as isize { + return None; + } + + let mut index = 0; + let mut paired_host = None; + loop { + let mut interface_data = SP_DEVICE_INTERFACE_DATA { + cbSize: std::mem::size_of::() as u32, + InterfaceClassGuid: unsafe { std::mem::zeroed() }, + Flags: 0, + Reserved: 0, + }; + let ok = unsafe { + SetupDiEnumDeviceInterfaces( + info_set, + std::ptr::null_mut(), + &hid_guid, + index, + &mut interface_data, + ) + }; + if ok == 0 { + break; + } + index += 1; + + let Some(path) = (unsafe { windows_hid_interface_path(info_set, &mut interface_data) }) + else { + continue; + }; + if !path.to_ascii_lowercase().contains("&col02#") { + continue; + } + if windows_ps_move_physical_key(&path).as_deref() != Some(physical_key) { + continue; + } + paired_host = windows_ps_move_paired_host_address_from_path(&path); + if paired_host.is_some() { + break; + } + } + + unsafe { SetupDiDestroyDeviceInfoList(info_set) }; + paired_host +} + #[cfg(windows)] fn windows_claim_ps_move_host(host: &[u8; 6]) -> Result { use windows_sys::Win32::Devices::DeviceAndDriverInstallation::{ @@ -3889,17 +3991,18 @@ fn current_move_identity_records_from_sources( sources: &[MoveStateSource], ) -> Result> { let observed_at = timestamp()?; - let bluetooth_host_address = move_host_address_for_claim(options).unwrap_or_default(); let mut identities = sources .iter() .map(|source| { let (state, detail) = move_identity_source_state_and_detail(&source.hidraw_path); + let bluetooth_host_address = + move_identity_bluetooth_host_address(options, &source.hidraw_path); MuninnMoveIdentityRecord { identity_id: format!("{}:{}:move-identity", options.host_id, source.move_id), host_id: options.host_id.clone(), move_id: source.move_id.clone(), source_path: source.hidraw_path.clone(), - bluetooth_host_address: bluetooth_host_address.clone(), + bluetooth_host_address, state, detail, observed_at: observed_at.clone(), @@ -3919,6 +4022,25 @@ fn current_move_identity_records_from_sources( Ok(identities) } +fn move_identity_bluetooth_host_address(options: &Options, source_path: &str) -> String { + move_host_address_for_claim(options) + .or_else(|| paired_bluetooth_host_address_for_source(source_path)) + .unwrap_or_default() +} + +#[cfg(windows)] +fn paired_bluetooth_host_address_for_source(source_path: &str) -> Option { + let path = source_path + .strip_prefix(WINDOWS_PS_MOVE_SOURCE_PREFIX) + .unwrap_or(source_path); + windows_ps_move_paired_host_address(path) +} + +#[cfg(not(windows))] +fn paired_bluetooth_host_address_for_source(_source_path: &str) -> Option { + None +} + #[cfg(unix)] fn current_bluetooth_move_identity_records( options: &Options, @@ -5220,6 +5342,33 @@ MODALIAS=input:b0005v054Cp03D5e0220 let _ = fs::remove_file(store_path); } + #[test] + fn current_move_identity_uses_configured_bluetooth_host() { + let options = Options::parse( + [ + "move-identity-status", + "--host", + "starfire", + "--move-host", + "5C:93:A2:9C:A8:A8", + ] + .into_iter() + .map(String::from), + ) + .unwrap(); + let identities = current_move_identity_records_from_sources( + &options, + &[MoveStateSource { + move_id: "move-000704a800d0".to_string(), + hidraw_path: "windows-psmove://silent".to_string(), + }], + ) + .unwrap(); + + assert_eq!(identities.len(), 1); + assert_eq!(identities[0].bluetooth_host_address, "5C:93:A2:9C:A8:A8"); + } + #[test] fn move_identity_status_reads_reopened_store() { let store_path = std::env::temp_dir().join(format!( From 0622ce0ac900a6cd7de016b9ddb4e507285d0ffe Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 17 Jun 2026 13:44:57 +0100 Subject: [PATCH 12/12] Drop stale configured Move joystick sources --- crates/muninn-daemon/src/main.rs | 65 ++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/crates/muninn-daemon/src/main.rs b/crates/muninn-daemon/src/main.rs index de2d77a..63187f5 100644 --- a/crates/muninn-daemon/src/main.rs +++ b/crates/muninn-daemon/src/main.rs @@ -521,17 +521,20 @@ fn publish_bluetooth_move_identity_records( fn live_move_state_sources(options: &Options) -> Vec { let discovered = platform_move_state_sources(); + merge_live_move_state_sources(discovered, &options.move_state_sources) +} + +fn merge_live_move_state_sources( + discovered: Vec, + configured: &[MoveStateSource], +) -> Vec { if discovered.is_empty() { - return options.move_state_sources.clone(); + return configured.to_vec(); } let mut sources = discovered; - for source in &options.move_state_sources { - if is_joystick_path(&source.hidraw_path) - && sources - .iter() - .any(|discovered| discovered.hidraw_path == source.hidraw_path) - { + for source in configured { + if is_platform_move_source_path(&source.hidraw_path) { continue; } if !sources.iter().any(|discovered| discovered == source) { @@ -1495,6 +1498,20 @@ fn is_joystick_path(path: &str) -> bool { path.contains("/dev/input/js") || path.contains("-joystick") } +fn is_platform_move_source_path(path: &str) -> bool { + is_joystick_path(path) || is_platform_runtime_move_source_path(path) +} + +#[cfg(windows)] +fn is_platform_runtime_move_source_path(path: &str) -> bool { + is_windows_ps_move_source(path) +} + +#[cfg(not(windows))] +fn is_platform_runtime_move_source_path(_path: &str) -> bool { + false +} + #[cfg(windows)] fn is_windows_ps_move_source(path: &str) -> bool { path.eq_ignore_ascii_case("windows-psmove") @@ -5616,6 +5633,40 @@ MODALIAS=input:b0005v054Cp03D5e0220 assert_eq!(active[0].source.move_id, "move-0006f523e2d1"); } + #[test] + fn live_move_state_merge_drops_stale_configured_joystick_sources() { + let sources = merge_live_move_state_sources( + vec![MoveStateSource { + move_id: "move-0006f523e2d1".to_string(), + hidraw_path: "/dev/input/js1".to_string(), + }], + &[ + MoveStateSource { + move_id: "move-000704a39772".to_string(), + hidraw_path: "/dev/input/js0".to_string(), + }, + MoveStateSource { + move_id: "manual-source".to_string(), + hidraw_path: "file:///tmp/manual-source".to_string(), + }, + ], + ); + + assert_eq!( + sources, + vec![ + MoveStateSource { + move_id: "move-0006f523e2d1".to_string(), + hidraw_path: "/dev/input/js1".to_string(), + }, + MoveStateSource { + move_id: "manual-source".to_string(), + hidraw_path: "file:///tmp/manual-source".to_string(), + }, + ] + ); + } + #[test] fn released_usb_move_clears_pickup_backoff() { let mut attempts = Vec::new();