[][src]Struct joycon_rs::joycon::JoyConManager

pub struct JoyConManager { /* fields omitted */ }

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.