From b6265e6f24ef2400826661ba6fd3b151436142c5 Mon Sep 17 00:00:00 2001 From: Lennard Kittner Date: Sat, 8 Nov 2025 13:46:33 +0100 Subject: [PATCH] Conditionally enable passive Refresh --- src/devices/cloud_ii_wireless.rs | 4 ++++ src/devices/cloud_ii_wireless_dts.rs | 4 ++++ src/devices/cloud_iii_wireless.rs | 4 ++++ src/devices/mod.rs | 20 +++++++++++--------- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/devices/cloud_ii_wireless.rs b/src/devices/cloud_ii_wireless.rs index 9e8260b..bf7d79a 100644 --- a/src/devices/cloud_ii_wireless.rs +++ b/src/devices/cloud_ii_wireless.rs @@ -267,6 +267,10 @@ impl Device for CloudIIWireless { .unwrap(); } + fn allow_passive_refresh(&mut self) -> bool { + false + } + fn execute_headset_specific_functionality(&mut self) -> Result<(), DeviceError> { //TODO: I think this unmutes the headset // println!("Writing special sequence"); diff --git a/src/devices/cloud_ii_wireless_dts.rs b/src/devices/cloud_ii_wireless_dts.rs index 57b708f..775b5b1 100644 --- a/src/devices/cloud_ii_wireless_dts.rs +++ b/src/devices/cloud_ii_wireless_dts.rs @@ -231,6 +231,10 @@ impl Device for CloudIIWirelessDTS { } } + fn allow_passive_refresh(&mut self) -> bool { + true + } + fn get_device_state(&self) -> &DeviceState { &self.state } diff --git a/src/devices/cloud_iii_wireless.rs b/src/devices/cloud_iii_wireless.rs index 9a425d0..111f830 100644 --- a/src/devices/cloud_iii_wireless.rs +++ b/src/devices/cloud_iii_wireless.rs @@ -222,6 +222,10 @@ impl Device for CloudIIIWireless { } } + fn allow_passive_refresh(&mut self) -> bool { + true + } + fn get_device_state(&self) -> &DeviceState { &self.state } diff --git a/src/devices/mod.rs b/src/devices/mod.rs index 0cb9d6a..aee9c0f 100644 --- a/src/devices/mod.rs +++ b/src/devices/mod.rs @@ -226,7 +226,8 @@ impl DeviceState { self.get_display_data() .iter() .filter_map(|(prefix, data, suffix, _)| { - data.as_ref().map(|data| format!("{:>() .join("\n") @@ -414,6 +415,8 @@ pub trait Device { fn get_device_state(&self) -> &DeviceState; fn get_device_state_mut(&mut self) -> &mut DeviceState; fn prepare_write(&mut self) {} + /// whether the app should periodically listen for packets from the headsets + fn allow_passive_refresh(&mut self) -> bool; // Helper methods to check if features are writable fn can_set_mute(&self) -> bool { @@ -526,14 +529,13 @@ pub trait Device { /// Refreshes the state by listening for events /// Only the battery level is actively queried because it is not communicated by the device on its own fn passive_refresh_state(&mut self) -> Result<(), DeviceError> { - //TODO: only if the headset allows it - // println!("passive refresh"); - // if let Some(events) = self.wait_for_updates(Duration::from_secs(1)) { - // println!("{:?}", events); - // for event in events { - // self.get_device_state_mut().update_self_with_event(&event); - // } - // } + if self.allow_passive_refresh() { + if let Some(events) = self.wait_for_updates(Duration::from_secs(1)) { + for event in events { + self.get_device_state_mut().update_self_with_event(&event); + } + } + } if let Some(batter_packet) = self.get_battery_packet() { self.prepare_write(); self.get_device_state().hid_device.write(&batter_packet)?;