pub fn from_device<S>(device: &MonomeDevice, prefix: S) -> Result<Monome, String>
    where
        S: Into<String>,
    {
        let prefix = prefix.into();
        let (info, socket, name, device_type, device_port) = Monome::setup(&*prefix, device)?;

        let (sender, receiver) = futures::sync::mpsc::unbounded();
        let q = Arc::new(ArrayQueue::new(32));
        let q2 = q.clone();
        let t = Transport::new(device.host(), device_port, socket, q, receiver);

        thread::spawn(move || {
            tokio::run(t.map_err(|e| error!("server error = {:?}", e)));
        });

        Ok(Monome {
            tx: sender,
            q: q2,
            name,
            device_type,
            host: info.host.unwrap(),
            id: info.id.unwrap(),
            port: device_port,
            prefix,
            rotation: info.rotation.unwrap(),
            size: info.size.unwrap(),
        })
    }
/// Get a monome instance on which to call commands, from a `MonomeDevice`.
///
/// # Arguments
///
/// * `device`: a `MonomeDevice` acquired through `enumerate_devices`.
/// * `prefix`: the prefix to use for this device and this application
///
/// # Example
///
/// ```no_run
/// # use monome::Monome;
/// let enumeration = Monome::enumerate_devices();
/// match enumeration {
///     Ok(devices) => {
///         for device in &devices {
///             println!("{}", device);
///             match Monome::from_device(device, "prefix") {
///                 Ok(m) => {
///                     println!("Monome setup:\n{}", m);
///                 }
///                 Err(e) => {
///                     println!("Error setting up {} ({})", device, e);
///                 }
///             }
///         }
///     }
///     Err(e) => {
///         eprintln!("Error: {}", e);
///     }
/// }
/// ```
Get a monome instance on which to call commands, from a `MonomeDevice`.
Get a monome instance on which to call commands from a ` MonomeDevice ` .
pub fn from_device<S>(device: &MonomeDevice, prefix: S) -> Result<Monome, String>
    where
        S: Into<String>,
    {
        let prefix = prefix.into();
        let (info, socket, name, device_type, device_port) = Monome::setup(&*prefix, device)?;
        let (sender, receiver) = futures::sync::mpsc::unbounded();
        let q = Arc::new(ArrayQueue::new(32));
        let q2 = q.clone();
        let t = Transport::new(device.host(), device_port, socket, q, receiver);
        thread::spawn(move || {
            tokio::run(t.map_err(|e| error!("server error = {:?}", e)));
        });
        Ok(Monome {
            tx: sender,
            q: q2,
            name,
            device_type,
            host: info.host.unwrap(),
            id: info.id.unwrap(),
            port: device_port,
            prefix,
            rotation: info.rotation.unwrap(),
            size: info.size.unwrap(),
        })
    }
pub fn from_device < S > ( device : & MonomeDevice , prefix : S ) -> Result < Monome , String > where S : Into < String > , { let prefix = prefix . into ( ) ; let ( info , socket , name , device_type , device_port ) = Monome :: setup ( & * prefix , device ) ? ; let ( sender , receiver ) = futures :: sync :: mpsc :: unbounded ( ) ; let q = Arc :: new ( ArrayQueue :: new ( 32 ) ) ; let q2 = q . clone ( ) ; let t = Transport :: new ( device . host ( ) , device_port , socket , q , receiver ) ; thread :: spawn ( move | | { tokio :: run ( t . map_err ( | e | error ! ( " " e ) ) ) ; } ) ; Ok ( Monome { tx : sender , q : q2 , name , device_type , host : info . host . unwrap ( ) , id : info . id . unwrap ( ) , port : device_port , prefix , rotation : info . rotation . unwrap ( ) , size : info . size . unwrap ( ) , } ) }
Get a monome instance on which to call commands, from a `MonomeDevice`.
Get a monome instance on which to call commands from a ` MonomeDevice ` .
device
&MonomeDevice
prefix
S
device
&MonomeDevice
prefix
S
example
None
use monome::monome;
let enumeration = Monome::enumerate_devices();
match enumeration {
Ok(devices) => {
for device in &devices {
println!("{}", device);
match Monome::from_device(device, "prefix") {
Ok(m) => {
println!("Monome setup:\n{}", m);
}
Err(e) => {
println!("Error setting up {} ({})", device, e);
}
}
}
}
Err(e) => {
eprintln!("Error: {}", e);
}
}
```
let enumeration = Monome :: enumerate_devices () ; match enumeration { Ok ( devices ) = > { for device in &devices { println! ( " {} " device ) ; match Monome :: from_device ( device " prefix " ) { Ok ( m ) = > { println! ( " Monome setup : \ n {} " m ) ; } Err ( e ) = > { println! ( " Error setting up {} ( {} ) " device e ) ; } } } } Err ( e ) = > { eprintln! ( " Error : {} " e ) ; } } ` ` `