[−][src]Struct monome::Monome
The client object for a Monome grid device
Methods
impl Monome
[src]
pub fn register_device_change_callback_with_port(
serialosc_port: i32,
callback: fn(_: DeviceChangeEvent)
)
[src]
serialosc_port: i32,
callback: fn(_: DeviceChangeEvent)
)
Register for device added/removed notifications, on a non-standard serialosc port
Arguments
serialosc_port
: the port on which serialosc is running
callback
: a function that is called whenever a device is added or removed.
Example
Print a message, on a machine where serialosc runs on port 1234.
use monome::Monome; use monome::DeviceChangeEvent; Monome::register_device_change_callback_with_port(1234, |event| { match event { DeviceChangeEvent::Added(id) => { println!("Device {} added", id); } DeviceChangeEvent::Removed(id) => { println!("Device {} removed", id); } } });
pub fn register_device_change_callback(callback: fn(_: DeviceChangeEvent))
[src]
Register for device added/removed notifications, on the default serialosc port
Arguments
callback
: a function that is called whenever a device is added or removed.
Example
use monome::Monome; use monome::DeviceChangeEvent; Monome::register_device_change_callback(|event| { match event { DeviceChangeEvent::Added(id) => { println!("Device {} added", id); } DeviceChangeEvent::Removed(id) => { println!("Device {} removed", id); } } });
pub fn enumerate_devices_with_port(
serialosc_port: i32
) -> Result<Vec<MonomeDevice>, String>
[src]
serialosc_port: i32
) -> Result<Vec<MonomeDevice>, String>
Enumerate all monome devices on a non-standard serialosc port.
If successful, this returns a list of MonomeDevice, which contain basic informations about the device: type, serial number, port allocated by serialosc.
Arguments
serialosc_port
: the port on which serialosc is running
Example
Enumerate and display all monome device on port 1234:
use monome::Monome; let enumeration = Monome::enumerate_devices_with_port(1234); match enumeration { Ok(devices) => { for device in &devices { println!("{}", device); } } Err(e) => { eprintln!("Error: {}", e); } }
pub fn enumerate_devices() -> Result<Vec<MonomeDevice>, String>
[src]
Enumerate all monome devices on the standard port on which serialosc runs (12002).
If successful, this returns a list of MonomeDevice, which contain basic informations about the device: type, serial number, port allocated by serialosc.
Arguments
serialosc_port
: the port on which serialosc is running
Example
Enumerate and display all monome device on port 1234:
use monome::Monome; let enumeration = Monome::enumerate_devices(); match enumeration { Ok(devices) => { for device in &devices { println!("{}", device); } } Err(e) => { eprintln!("Error: {}", e); } }
pub fn new<S>(prefix: S) -> Result<Monome, String> where
S: Into<String>,
[src]
S: Into<String>,
Sets up the "first" monome device, with a particular prefix. When multiple devices are plugged in, it's unclear which one is activated, however this is rare.
Arguments
prefix
- the prefix to use for this device and this application
Example
Set up a monome, with a prefix of "/prefix":
use monome::Monome; let m = Monome::new("/prefix"); match m { Ok(monome) => { println!("{:?}", monome); } Err(s) => { println!("Could not setup the monome: {}", s); } }
pub fn new_with_port<S>(
prefix: S,
serialosc_port: i32
) -> Result<Monome, String> where
S: Into<String>,
[src]
prefix: S,
serialosc_port: i32
) -> Result<Monome, String> where
S: Into<String>,
Sets up the "first" monome device, with a particular prefix and a non-standard port for serialosc. When multiple devices are plugged in, it's unclear which one is activated, however this is rare.
Arguments
prefix
- the prefix to use for this device and this applicationserialosc_port
- the port at which serialosc can be reached.
Example
Set up a monome, with a prefix of "/prefix", and specify an explicit port on which serialosc can be reached (here, the default of 12002):
use monome::Monome; let m = Monome::new_with_port("/prefix", 12002); match m { Ok(monome) => { println!("{:?}", monome); } Err(s) => { println!("Could not setup the monome: {}", s); } }
pub fn from_device<S>(
device: &MonomeDevice,
prefix: S
) -> Result<Monome, String> where
S: Into<String>,
[src]
device: &MonomeDevice,
prefix: S
) -> Result<Monome, String> where
S: Into<String>,
Get a monome instance on which to call commands, from a MonomeDevice
.
Arguments
device
: aMonomeDevice
acquired throughenumerate_devices
.prefix
: the prefix to use for this device and this application
Example
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); } }
pub fn set<'a, A>(&mut self, x: i32, y: i32, arg: A) where
A: IntoAddrAndArgs<'a, OscType>,
[src]
A: IntoAddrAndArgs<'a, OscType>,
Set a single led on a grid on or off.
Arguments
x
- the horizontal position of the led to set.y
- the vertical positino of the led to set.arg
- either a bool, true to set a led On, false to set it Off, or a number between 0 and 16, 0 being led off, 16 being full led brightness.
Example
Set the led on the second row and second column to On, and also the third row and second column to mid-brightness:
monome.set(1 /* 2nd, 0-indexed */, 1 /* 2nd, 0-indexed */, true); monome.set(1 /* 2nd, 0-indexed */, 2 /* 3nd, 0-indexed */, 8);
pub fn all<'a, A>(&mut self, arg: A) where
A: IntoAddrAndArgs<'a, OscType>,
[src]
A: IntoAddrAndArgs<'a, OscType>,
Set all led of the grid to an intensity
Arguments
intensity
- either a bool, true for led On or false for led Off, or a number between 0 and 16, 0 being led off, and 16 being full led brightness.
Example
On a grid, set all led to medium brightness, then turn it on:
let mut monome = Monome::new("/prefix").unwrap(); monome.all(8); monome.all(false);
pub fn set_all(&mut self, leds: &[bool])
[src]
Set all the leds of a monome in one call.
Arguments
leds
- a vector of 64 booleans for a monome 64, 128 elements for a monome 128, and 256 elements for a monome 256, packed in row order.
Example
One a monome 128, do a checkerboard pattern:
let mut monome = Monome::new("/prefix").unwrap(); let mut grid = [false; 128]; for i in 0..128 { grid[i] = (i + 1) % 2 == 0; } monome.set_all(&grid);
pub fn set_all_intensity(&mut self, leds: &[u8])
[src]
Set all the leds of a monome in one call.
Arguments
leds
- a vector of 64 integers in [0, 15] for a monome 64, 128 elements for a monome 128, and 256 elements for a monome 256, packed in row order.
Example
One a monome 128, do a gradient
let mut m = Monome::new("/prefix").unwrap(); let mut grid: Vec<u8> = vec!(0; 128); for i in 0..8 { for j in 0..16 { grid[i * 16 + j] = (2 * i) as u8; } } m.set_all_intensity(&grid);
pub fn map<'a, A>(&mut self, x_offset: i32, y_offset: i32, masks: A) where
A: IntoAddrAndArgs<'a, Vec<OscType>> + Sized,
[src]
A: IntoAddrAndArgs<'a, Vec<OscType>> + Sized,
Set the value an 8x8 quad of led on a monome grid.
Arguments
x_offset
- at which offset, that must be a multiple of 8, to set the quad.y_offset
- at which offset, that must be a multiple of 8, to set the quad.masks
- a vector of 8 unsigned 8-bit integers that is a mask representing the leds to light up, or a vector of 64 bools, true for led On, false for led Off, packed in row order, or a vector of 64 integers between 0 and 15, for the brightness of each led, packed in row order.
Example
On a monome 128, draw a triangle in the lower left half of the rightmost half, and a gradient on the leftmost half.
let mut monome = Monome::new("/prefix").unwrap(); let mut v = [0; 64]; for i in 0..64 { v[i] = (i / 4) as u8; } monome.map(0, 0, &v); monome.map(8, 0, &[1, 3, 7, 15, 32, 63, 127, 0b11111111]);
pub fn row<'a, A>(&mut self, x_offset: i32, y: i32, leds: &A) where
A: IntoAddrAndArgs<'a, Vec<OscType>>,
[src]
A: IntoAddrAndArgs<'a, Vec<OscType>>,
Set a full row of a grid, using one or more 8-bit mask(s), or a vector containing booleans or integer intensity values.
Arguments
x_offset
- at which 8 button offset to start setting the leds. This is always 0 for a 64, and can be 8 for a 128 or 256.y
- which row to set, 0-indexed. This must be lower than the number of rows of the device.leds
- either the list of masks that determine the pattern to light on for a particular 8 led long section, or a vector of either int or bool, one element for each led.
Example
On a monome 128, light up every other led of the right half of the 3rd row:
let mut monome = Monome::new("/prefix").unwrap(); monome.row(8 /* rightmost half */, 2 /* 3rd row, 0 indexed */, &0b01010101u8 /* every other led, 85 in decimal */);
pub fn col<'a, A>(&mut self, x: i32, y_offset: i32, leds: &A) where
A: IntoAddrAndArgs<'a, Vec<OscType>>,
[src]
A: IntoAddrAndArgs<'a, Vec<OscType>>,
Set a full column of a grid, using one or more 8-bit mask(s), or a vector containing booleans or integer intensity values.
Arguments
x
- which column to set 0-indexed. This must be lower than the number of columns of the device.y_offset
- at which 8 button offset to start setting the leds. This is always 0 for a 64, and can be 8 for a 128 or 256.leds
- either the list of masks that determine the pattern to light on for a particular 8 led long section, or a vector of either int or bool, one element for each led.
Example
On a monome 256, light up every other led of the bottom half of the 3rd column from the right:
use monome::Monome; let mut monome = Monome::new("/prefix").unwrap(); monome.col(2 /* 3rd column, 0-indexed */, 8 /* bottom half */, &0b01010101u8 /* every other led, 85 in decimal */);
pub fn ring_set(&mut self, n: usize, index: u32, intensity: u32)
[src]
Set a single led, with intensity, on an Arc.
Arguments
n
- the encoder to set a led on, 0-indexed.index
- which led to set. 0 is the top led, and goes clockwise. This is modulo 64, so passing in 65 is the second led from the top, going clockwise.intensity
- the intensity of the led 0 being off, 15 full brightness.
Example
On an arc, make a circular gradient on the first encoder:
use monome::Monome; let mut monome = Monome::new("/prefix").unwrap(); for i in 0..64 { monome.set(0, i, i / 4); }
pub fn ring_all(&mut self, n: usize, intensity: u32)
[src]
Set all the led on an encoder to a particular intensity.
Arguments
n
- the encoder to set the leds on, 0-indexed.intensity
- the intensity of the leds: 0 being off, 15 full brightness.
Example
On an arc, make a gradient accross all four encoders:
use monome::Monome; let mut monome = Monome::new("/prefix").unwrap(); for i in 0..4 { monome.ring_all(i, (i * 4) as u32); }
pub fn ring_range(
&mut self,
n: usize,
start_offset: usize,
end_offset: usize,
intensity: u32
)
[src]
&mut self,
n: usize,
start_offset: usize,
end_offset: usize,
intensity: u32
)
Set a range of led to a particular intensity.
Arguments
n
- the encoder to set the leds on, 0-indexed.start_offset
- the encoder to start setting the led from, 0-indexed, modulo 64.end_offset
- the encoder to end setting the led at 0-indexed, inclusive, modulo 64.intensity
- the intensity of the leds: 0 being off, 15 full brightness.
Example
On an arc, lit up halves:
use monome::Monome; let mut monome = Monome::new("/prefix").unwrap(); monome.ring_range(0, 0, 32, 15); monome.ring_range(1, 32, 64, 15); monome.ring_range(2, 16, 48, 15); monome.ring_range(3, 48, 16, 15);
pub fn ring_map(&mut self, n: usize, values: &[u8; 64])
[src]
Set all leds on an encoder to specific values.
Arguments
n
- the encoder to set the leds on, 0-indexed.values
- an array of 64 values between 0 an 16, one for each led.
Example
On an arc, make a gradient on an encoder.
use monome::Monome; let mut monome = Monome::new("/prefix").unwrap(); let mut v: [u8; 64] = [0; 64]; for i in 0..64 { v[i] = (i / 4) as u8; } monome.ring_map(0, &v);
pub fn tilt_all(&mut self, on: bool)
[src]
Enable or disable all tilt sensors (usually, there is only one), which allows receiving the
/<prefix>/tilt/
events, with the n,x,y,z coordinates as parameters.
pub fn set_rotation(&mut self, rotation: i32)
[src]
Set the rotation for this device. This is either 0, 90, 180 or 270
pub fn set_prefix(&mut self, prefix: String)
[src]
Set the prefix for this device.
pub fn name(&self) -> String
[src]
Get the name of this device.
pub fn device_type(&self) -> MonomeDeviceType
[src]
Get the type for this device (for example "monome 128"
).
pub fn port(&self) -> i32
[src]
Get the port for this device.
pub fn host(&self) -> String
[src]
Get the host for this device is at.
pub fn id(&self) -> String
[src]
Get the id of this device.
pub fn prefix(&self) -> String
[src]
Get the current prefix of this device.
pub fn rotation(&self) -> i32
[src]
Get the current rotation of this device.
pub fn size(&self) -> (i32, i32)
[src]
Get the size of this device, as a (width, height)
.
pub fn width(&self) -> usize
[src]
Get the width of this device.
pub fn height(&self) -> usize
[src]
Get the height of this device.
pub fn poll(&mut self) -> Option<MonomeEvent>
[src]
Receives a MonomeEvent, from a connected monome, which can be a grid key press, an event
from the tilt sensor, or a delta from an encoder, on an Arc. Only the events from the set
prefix
will be received.
Example
use monome::{Monome, MonomeEvent, KeyDirection}; let mut m = Monome::new("/prefix").unwrap(); loop { match m.poll() { Some(MonomeEvent::GridKey{x, y, direction}) => { match direction { KeyDirection::Down => { println!("Key pressed: {}x{}", x, y); } KeyDirection::Up => { println!("Key released: {}x{}", x, y); } } } Some(MonomeEvent::Tilt{n: _n, x, y, z: _z}) => { println!("tilt update: pitch: {}, roll {}", x, y); } _ => { break; } } }
Trait Implementations
Auto Trait Implementations
impl Unpin for Monome
impl Sync for Monome
impl Send for Monome
impl !RefUnwindSafe for Monome
impl !UnwindSafe for Monome
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,