Struct monome::Monome [−][src]
pub struct Monome { /* fields omitted */ }
Expand description
The client object for a Monome grid device
Implementations
pub fn register_device_change_callback_with_host_and_port(
serialosc_addr: IpAddr,
serialosc_port: u16,
callback: fn(_: DeviceChangeEvent)
)
pub fn register_device_change_callback_with_host_and_port(
serialosc_addr: IpAddr,
serialosc_port: u16,
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 the machine at 192.168.1.12, on port 1234.
Monome::register_device_change_callback_with_host_and_port("192.168.1.12".parse().unwrap(), 1234, |event| {
match event {
DeviceChangeEvent::Added(id) => {
println!("Device {} added", id);
}
DeviceChangeEvent::Removed(id) => {
println!("Device {} removed", id);
}
}
});
Register for device added/removed notifications, on the default serialosc port, when it runs on localhost.
Arguments
callback
: a function that is called whenever a device is added or removed.
Example
Monome::register_device_change_callback(|event| {
match event {
DeviceChangeEvent::Added(id) => {
println!("Device {} added", id);
}
DeviceChangeEvent::Removed(id) => {
println!("Device {} removed", id);
}
}
});
pub fn register_device_change_callback_with_host(
addr: IpAddr,
callback: fn(_: DeviceChangeEvent)
)
pub fn register_device_change_callback_with_host(
addr: IpAddr,
callback: fn(_: DeviceChangeEvent)
)
Register for device added/removed notifications, on the default serialosc port, passing in the address at which serialoscd is reachable.
Arguments
addr
: the address on which serialoscd is reachable.callback
: a function that is called whenever a device is added or removed.
Example
Monome::register_device_change_callback_with_host("192.168.1.12".parse().unwrap(), |event| {
match event {
DeviceChangeEvent::Added(id) => {
println!("Device {} added", id);
}
DeviceChangeEvent::Removed(id) => {
println!("Device {} removed", id);
}
}
});
pub fn register_device_change_callback_with_port(
port: u16,
callback: fn(_: DeviceChangeEvent)
)
pub fn register_device_change_callback_with_port(
port: u16,
callback: fn(_: DeviceChangeEvent)
)
Register for device added/removed notifications, on the specific serialosc port, when serialoscd is running on localhost.
Arguments
port
: the port at which serialoscd is.callback
: a function that is called whenever a device is added or removed.
Example
Monome::register_device_change_callback_with_port(12012, |event| {
match event {
DeviceChangeEvent::Added(id) => {
println!("Device {} added", id);
}
DeviceChangeEvent::Removed(id) => {
println!("Device {} removed", id);
}
}
});
pub fn enumerate_devices_with_host_and_port(
serialosc_addr: IpAddr,
serialosc_port: u16
) -> Result<Vec<MonomeDevice>, String>
pub fn enumerate_devices_with_host_and_port(
serialosc_addr: IpAddr,
serialosc_port: u16
) -> Result<Vec<MonomeDevice>, String>
Enumerate all monome devices on a non-standard serialosc port, on a specific host.
If successful, this returns a list of MonomeDevice, which contain basic informations about the device: type, serial number, port allocated by serialosc.
Arguments
- `serialosc_addr: the address of the host on which serialosc runs
serialosc_port
: the port on which serialosc is running
Example
Enumerate and display all monome device on port 1234:
let enumeration = Monome::enumerate_devices_with_host_and_port("192.168.1.12".parse().unwrap(), 1234);
match enumeration {
Ok(devices) => {
for device in &devices {
println!("{}", device);
}
}
Err(e) => {
eprintln!("Error: {}", e);
}
}
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:
let enumeration = Monome::enumerate_devices();
match enumeration {
Ok(devices) => {
for device in &devices {
println!("{}", device);
}
}
Err(e) => {
eprintln!("Error: {}", e);
}
}
Enumerate all monome devices on localhost, on a specific port.
If successful, this returns a list of MonomeDevice, which contain basic informations about the device: type, serial number, port allocated by serialosc.
Arguments
port
: the port serialoscd is bound to.
Example
Enumerate and display all monome device running on default port at a specific address.
match enumeration {
Ok(devices) => {
for device in &devices {
println!("{}", device);
}
}
Err(e) => {
eprintln!("Error: {}", e);
}
}
Enumerate all monome devices on the standard port on which serialosc runs (12002), on a specific address.
If successful, this returns a list of MonomeDevice, which contain basic informations about the device: type, serial number, port allocated by serialosc.
Arguments
- `addr: the address at which serialosc is reachable
Example
Enumerate and display all monome device running on default port at a specific addr.
let enumeration = Monome::enumerate_devices_on_host("192.168.1.12".parse().unwrap());
match enumeration {
Ok(devices) => {
for device in &devices {
println!("{}", device);
}
}
Err(e) => {
eprintln!("Error: {}", e);
}
}
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”:
let m = Monome::new("/prefix");
match m {
Ok(monome) => {
println!("{:?}", monome);
}
Err(s) => {
println!("Could not setup the monome: {}", s);
}
}
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):
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>,
pub fn from_device<S>(
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
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);
}
}
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);
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);
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);
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);
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]);
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 */);
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 */);
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);
}
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);
}
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);
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);
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.
Set the rotation for this device. This is either 0, 90, 180 or 270
Set the prefix for this device.
Get the type for this device (for example "monome 128"
).
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;
}
}
}