[−][src]Struct joycon_rs::joycon::JoyConManager
A manager for dealing with Joy-Cons.
JoyConManager has a scanner that detects new connections/disconnections/reconnections
of JoyCon by scanning periodically
(every second: You can set the interval in JoyConManager::with_duration()
).
Methods
impl JoyConManager
[src]
pub fn new() -> JoyConResult<Arc<Mutex<Self>>>
[src]
Constructor
pub fn with_interval(interval: Duration) -> JoyConResult<Arc<Mutex<Self>>>
[src]
pub fn scan(&mut self) -> JoyConResult<Vec<Arc<Mutex<JoyConDevice>>>>
[src]
Scan the JoyCon connected to your computer. This returns new Joy-Cons.
pub fn managed_devices(&self) -> Vec<Arc<Mutex<JoyConDevice>>>
[src]
Collection of managed JoyCons. It may contains disconnected ones.
pub fn new_devices(&self) -> Receiver<Arc<Mutex<JoyConDevice>>>
[src]
Receiver of new devices. This method provides receiver of mpmc channel. Since the channel has no capacity, the message will disappear if it is not received at the same time as it is sent.
Example
use joycon_rs::prelude::*; let (tx, rx) = std::sync::mpsc::channel(); let _output = std::thread::spawn( move || { while let Ok(update) = rx.recv() { dbg!(update); } }); let manager = JoyConManager::new().unwrap(); let (managed_devices, new_devices) = { let lock = manager.lock(); match lock { Ok(manager) => (manager.managed_devices(), manager.new_devices()), Err(_) => return, } }; managed_devices.into_iter() .chain(new_devices) .flat_map(|device| SimpleJoyConDriver::new(&device)) .try_for_each::<_, JoyConResult<()>>(|driver| { let simple_hid_mode = SimpleHIDMode::new(driver)?; let tx = tx.clone(); let thread = std::thread::spawn(move || { loop { tx.send(simple_hid_mode.read_input_report()); } }); Ok(()) });
Auto Trait Implementations
impl !RefUnwindSafe for JoyConManager
impl Send for JoyConManager
impl Sync for JoyConManager
impl Unpin for JoyConManager
impl !UnwindSafe for JoyConManager
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,