Conditionally enable passive Refresh
This commit is contained in:
@@ -267,6 +267,10 @@ impl Device for CloudIIWireless {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn allow_passive_refresh(&mut self) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
fn execute_headset_specific_functionality(&mut self) -> Result<(), DeviceError> {
|
fn execute_headset_specific_functionality(&mut self) -> Result<(), DeviceError> {
|
||||||
//TODO: I think this unmutes the headset
|
//TODO: I think this unmutes the headset
|
||||||
// println!("Writing special sequence");
|
// println!("Writing special sequence");
|
||||||
|
|||||||
@@ -231,6 +231,10 @@ impl Device for CloudIIWirelessDTS {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn allow_passive_refresh(&mut self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
fn get_device_state(&self) -> &DeviceState {
|
fn get_device_state(&self) -> &DeviceState {
|
||||||
&self.state
|
&self.state
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,6 +222,10 @@ impl Device for CloudIIIWireless {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn allow_passive_refresh(&mut self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
fn get_device_state(&self) -> &DeviceState {
|
fn get_device_state(&self) -> &DeviceState {
|
||||||
&self.state
|
&self.state
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -226,7 +226,8 @@ impl DeviceState {
|
|||||||
self.get_display_data()
|
self.get_display_data()
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(prefix, data, suffix, _)| {
|
.filter_map(|(prefix, data, suffix, _)| {
|
||||||
data.as_ref().map(|data| format!("{:<padding$} {}{}", prefix, data, suffix))
|
data.as_ref()
|
||||||
|
.map(|data| format!("{:<padding$} {}{}", prefix, data, suffix))
|
||||||
})
|
})
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("\n")
|
.join("\n")
|
||||||
@@ -414,6 +415,8 @@ pub trait Device {
|
|||||||
fn get_device_state(&self) -> &DeviceState;
|
fn get_device_state(&self) -> &DeviceState;
|
||||||
fn get_device_state_mut(&mut self) -> &mut DeviceState;
|
fn get_device_state_mut(&mut self) -> &mut DeviceState;
|
||||||
fn prepare_write(&mut self) {}
|
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
|
// Helper methods to check if features are writable
|
||||||
fn can_set_mute(&self) -> bool {
|
fn can_set_mute(&self) -> bool {
|
||||||
@@ -526,14 +529,13 @@ pub trait Device {
|
|||||||
/// Refreshes the state by listening for events
|
/// 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
|
/// 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> {
|
fn passive_refresh_state(&mut self) -> Result<(), DeviceError> {
|
||||||
//TODO: only if the headset allows it
|
if self.allow_passive_refresh() {
|
||||||
// println!("passive refresh");
|
if let Some(events) = self.wait_for_updates(Duration::from_secs(1)) {
|
||||||
// if let Some(events) = self.wait_for_updates(Duration::from_secs(1)) {
|
for event in events {
|
||||||
// println!("{:?}", events);
|
self.get_device_state_mut().update_self_with_event(&event);
|
||||||
// for event in events {
|
}
|
||||||
// self.get_device_state_mut().update_self_with_event(&event);
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
if let Some(batter_packet) = self.get_battery_packet() {
|
if let Some(batter_packet) = self.get_battery_packet() {
|
||||||
self.prepare_write();
|
self.prepare_write();
|
||||||
self.get_device_state().hid_device.write(&batter_packet)?;
|
self.get_device_state().hid_device.write(&batter_packet)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user