Skip to content

Commit

Permalink
feat(CompositeDevice): change clear_state for targets that use hidraw…
Browse files Browse the repository at this point in the history
… or usb virtual devices to reset their state
  • Loading branch information
blindedone1458 committed Feb 12, 2025
1 parent b3fe66f commit d55996d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 28 deletions.
15 changes: 6 additions & 9 deletions src/input/target/dualsense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -982,15 +982,12 @@ impl TargetInputDevice for DualSenseDevice {

/// Clear any local state on the target device.
fn clear_state(&mut self) {
let caps = self.get_capabilities().unwrap_or_else(|_| {
log::error!("No target device capabilities found while clearing state.");
Vec::new()
});
for cap in caps {
let ev = NativeEvent::new(cap, InputValue::Bool(false));
self.queued_events
.push(ScheduledNativeEvent::new(ev, Duration::from_millis(0)));
}
self.state = match self.state {
PackedInputDataReport::Usb(_) => PackedInputDataReport::Usb(Default::default()),
PackedInputDataReport::Bluetooth(_) => {
PackedInputDataReport::Bluetooth(Default::default())
}
};
}
}

Expand Down
12 changes: 2 additions & 10 deletions src/input/target/horipad_steam.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Emulates a Horipad Steam Controller as a target input device.
use std::{cmp::Ordering, error::Error, fmt::Debug, fs::File, time::Duration};
use std::{cmp::Ordering, error::Error, fmt::Debug, fs::File};

use packed_struct::prelude::*;
use uhid_virt::{Bus, CreateParams, StreamError, UHIDDevice};
Expand Down Expand Up @@ -321,15 +321,7 @@ impl TargetInputDevice for HoripadSteamDevice {

/// Clear any local state on the target device.
fn clear_state(&mut self) {
let caps = self.get_capabilities().unwrap_or_else(|_| {
log::error!("No target device capabilities found while clearing state.");
Vec::new()
});
for cap in caps {
let ev = NativeEvent::new(cap, InputValue::Bool(false));
self.queued_events
.push(ScheduledNativeEvent::new(ev, Duration::from_millis(0)));
}
self.state = Default::default();
}
}

Expand Down
10 changes: 1 addition & 9 deletions src/input/target/steam_deck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,15 +834,7 @@ impl TargetInputDevice for SteamDeckDevice {

/// Clear any local state on the target device.
fn clear_state(&mut self) {
let caps = self.get_capabilities().unwrap_or_else(|_| {
log::error!("No target device capabilities found while clearing state.");
Vec::new()
});
for cap in caps {
let ev = NativeEvent::new(cap, InputValue::Bool(false));
self.queued_events
.push(ScheduledNativeEvent::new(ev, Duration::from_millis(0)));
}
self.state = Default::default();
}
}

Expand Down

0 comments on commit d55996d

Please sign in to comment.