Struct Board

Source
pub struct Board {
    pub pins: Vec<Pin>,
    pub i2c_data: Vec<I2CReply>,
    pub protocol_version: String,
    pub firmware_name: String,
    pub firmware_version: String,
    /* private fields */
}

Fields§

§pins: Vec<Pin>§i2c_data: Vec<I2CReply>§protocol_version: String§firmware_name: String§firmware_version: String

Implementations§

Source§

impl Board

Source

pub fn new(port: &str) -> Self

Examples found in repository?
examples/blink.rs (line 7)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    println!("firmware version {}", b.firmware_version);
10    println!("firmware name {}", b.firmware_name);
11    println!("protocol version {}", b.protocol_version);
12
13    b.set_pin_mode(13, firmata::OUTPUT);
14
15    let mut i = 0;
16
17    loop {
18        thread::sleep_ms(400);
19        println!("{}",i);
20        b.digital_write(13, i);
21        i ^= 1;
22    }
23}
More examples
Hide additional examples
examples/pwm.rs (line 7)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    let pin = 3;
10
11    println!("firmware version {}", b.firmware_version);
12    println!("firmware name {}", b.firmware_name);
13    println!("protocol version {}", b.protocol_version);
14
15    b.set_pin_mode(pin, firmata::PWM);
16
17    loop {
18        for value in 0..255 {
19            b.analog_write(pin, value);
20            println!("{}", value);
21            thread::sleep_ms(10);
22        }
23    }
24}
examples/servo.rs (line 7)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    let pin = 3;
10
11    println!("firmware version {}", b.firmware_version);
12    println!("firmware name {}", b.firmware_name);
13    println!("protocol version {}", b.protocol_version);
14
15    b.set_pin_mode(pin, firmata::SERVO);
16
17    loop {
18        for value in 0..180{
19            b.analog_write(pin, value);
20            println!("{}", value);
21            thread::sleep_ms(10);
22        }
23    }
24}
examples/analog.rs (line 7)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    let pin = 14; // A0
10
11    println!("firmware version {}", b.firmware_version);
12    println!("firmware name {}", b.firmware_name);
13    println!("protocol version {}", b.protocol_version);
14
15    b.set_pin_mode(pin, firmata::ANALOG);
16
17    b.report_analog(pin, 1);
18
19    loop {
20        b.decode();
21        println!("analog value: {:o}", b.pins[pin as usize].value);
22        thread::sleep_ms(10);
23    }
24}
examples/blinkm_i2c.rs (line 49)
48fn main() {
49    let board = Arc::new(Mutex::new(firmata::Board::new("/dev/ttyACM0")));
50
51    init(board.clone());
52
53    set_rgb(board.clone(), [255, 0, 0]);
54    println!("rgb: {:?}", read_rgb(board.clone()));
55    thread::sleep_ms(1000);
56
57    set_rgb(board.clone(), [0, 255, 0]);
58    println!("rgb: {:?}", read_rgb(board.clone()));
59    thread::sleep_ms(1000);
60
61    set_rgb(board.clone(), [0, 0, 255]);
62    println!("rgb: {:?}", read_rgb(board.clone()));
63    thread::sleep_ms(1000);
64}
examples/button.rs (line 7)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    println!("firmware version {}", b.firmware_version);
10    println!("firmware name {}", b.firmware_name);
11    println!("protocol version {}", b.protocol_version);
12
13    let led = 13;
14    let button = 2;
15
16    b.set_pin_mode(led, firmata::OUTPUT);
17    b.set_pin_mode(button, firmata::INPUT);
18
19    b.report_digital(button, 1);
20
21    loop {
22        b.decode();
23        if b.pins[button as usize].value == 0 {
24            println!("off");
25            b.digital_write(led, 0);
26        } else {
27            println!("on");
28            b.digital_write(led, 1);
29        }
30
31        thread::sleep_ms(100);
32    }
33}
Source

pub fn query_analog_mapping(&mut self)

Source

pub fn query_capabilities(&mut self)

Source

pub fn query_firmware(&mut self)

Examples found in repository?
examples/blinkm_i2c.rs (line 19)
7fn init(board: Arc<Mutex<firmata::Board>>) {
8    {
9        let mut b = board.lock().unwrap();
10        b.i2c_config(0);
11        b.i2c_write(0x09, "o".as_bytes());
12        thread::sleep_ms(10);
13    }
14
15    let b = board.clone();
16    thread::spawn(move || {
17        loop {
18            b.lock().unwrap().decode();
19            b.lock().unwrap().query_firmware();
20            thread::sleep_ms(10);
21        }
22    });
23}
Source

pub fn i2c_config(&mut self, delay: i32)

Examples found in repository?
examples/blinkm_i2c.rs (line 10)
7fn init(board: Arc<Mutex<firmata::Board>>) {
8    {
9        let mut b = board.lock().unwrap();
10        b.i2c_config(0);
11        b.i2c_write(0x09, "o".as_bytes());
12        thread::sleep_ms(10);
13    }
14
15    let b = board.clone();
16    thread::spawn(move || {
17        loop {
18            b.lock().unwrap().decode();
19            b.lock().unwrap().query_firmware();
20            thread::sleep_ms(10);
21        }
22    });
23}
Source

pub fn i2c_read(&mut self, address: i32, size: i32)

Examples found in repository?
examples/blinkm_i2c.rs (line 35)
31fn read_rgb(board: Arc<Mutex<firmata::Board>>) -> Vec<u8> {
32    {
33        let mut b = board.lock().unwrap();
34        b.i2c_write(0x09, "g".as_bytes());
35        b.i2c_read(0x09, 3);
36    }
37    loop {
38        {
39            let mut b = board.lock().unwrap();
40            if b.i2c_data.iter().count() > 0 {
41                return b.i2c_data.pop().unwrap().data;
42            }
43        }
44        thread::sleep_ms(10);
45    }
46}
Source

pub fn i2c_write(&mut self, address: i32, data: &[u8])

Examples found in repository?
examples/blinkm_i2c.rs (line 11)
7fn init(board: Arc<Mutex<firmata::Board>>) {
8    {
9        let mut b = board.lock().unwrap();
10        b.i2c_config(0);
11        b.i2c_write(0x09, "o".as_bytes());
12        thread::sleep_ms(10);
13    }
14
15    let b = board.clone();
16    thread::spawn(move || {
17        loop {
18            b.lock().unwrap().decode();
19            b.lock().unwrap().query_firmware();
20            thread::sleep_ms(10);
21        }
22    });
23}
24
25fn set_rgb(board: Arc<Mutex<firmata::Board>>, rgb: [u8; 3]) {
26    let mut b = board.lock().unwrap();
27    b.i2c_write(0x09, "n".as_bytes());
28    b.i2c_write(0x09, &rgb);
29}
30
31fn read_rgb(board: Arc<Mutex<firmata::Board>>) -> Vec<u8> {
32    {
33        let mut b = board.lock().unwrap();
34        b.i2c_write(0x09, "g".as_bytes());
35        b.i2c_read(0x09, 3);
36    }
37    loop {
38        {
39            let mut b = board.lock().unwrap();
40            if b.i2c_data.iter().count() > 0 {
41                return b.i2c_data.pop().unwrap().data;
42            }
43        }
44        thread::sleep_ms(10);
45    }
46}
Source

pub fn report_digital(&mut self, pin: i32, state: i32)

Examples found in repository?
examples/button.rs (line 19)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    println!("firmware version {}", b.firmware_version);
10    println!("firmware name {}", b.firmware_name);
11    println!("protocol version {}", b.protocol_version);
12
13    let led = 13;
14    let button = 2;
15
16    b.set_pin_mode(led, firmata::OUTPUT);
17    b.set_pin_mode(button, firmata::INPUT);
18
19    b.report_digital(button, 1);
20
21    loop {
22        b.decode();
23        if b.pins[button as usize].value == 0 {
24            println!("off");
25            b.digital_write(led, 0);
26        } else {
27            println!("on");
28            b.digital_write(led, 1);
29        }
30
31        thread::sleep_ms(100);
32    }
33}
Source

pub fn report_analog(&mut self, pin: i32, state: i32)

Examples found in repository?
examples/analog.rs (line 17)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    let pin = 14; // A0
10
11    println!("firmware version {}", b.firmware_version);
12    println!("firmware name {}", b.firmware_name);
13    println!("protocol version {}", b.protocol_version);
14
15    b.set_pin_mode(pin, firmata::ANALOG);
16
17    b.report_analog(pin, 1);
18
19    loop {
20        b.decode();
21        println!("analog value: {:o}", b.pins[pin as usize].value);
22        thread::sleep_ms(10);
23    }
24}
Source

pub fn analog_write(&mut self, pin: i32, level: i32)

Examples found in repository?
examples/pwm.rs (line 19)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    let pin = 3;
10
11    println!("firmware version {}", b.firmware_version);
12    println!("firmware name {}", b.firmware_name);
13    println!("protocol version {}", b.protocol_version);
14
15    b.set_pin_mode(pin, firmata::PWM);
16
17    loop {
18        for value in 0..255 {
19            b.analog_write(pin, value);
20            println!("{}", value);
21            thread::sleep_ms(10);
22        }
23    }
24}
More examples
Hide additional examples
examples/servo.rs (line 19)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    let pin = 3;
10
11    println!("firmware version {}", b.firmware_version);
12    println!("firmware name {}", b.firmware_name);
13    println!("protocol version {}", b.protocol_version);
14
15    b.set_pin_mode(pin, firmata::SERVO);
16
17    loop {
18        for value in 0..180{
19            b.analog_write(pin, value);
20            println!("{}", value);
21            thread::sleep_ms(10);
22        }
23    }
24}
Source

pub fn digital_write(&mut self, pin: i32, level: i32)

Examples found in repository?
examples/blink.rs (line 20)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    println!("firmware version {}", b.firmware_version);
10    println!("firmware name {}", b.firmware_name);
11    println!("protocol version {}", b.protocol_version);
12
13    b.set_pin_mode(13, firmata::OUTPUT);
14
15    let mut i = 0;
16
17    loop {
18        thread::sleep_ms(400);
19        println!("{}",i);
20        b.digital_write(13, i);
21        i ^= 1;
22    }
23}
More examples
Hide additional examples
examples/button.rs (line 25)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    println!("firmware version {}", b.firmware_version);
10    println!("firmware name {}", b.firmware_name);
11    println!("protocol version {}", b.protocol_version);
12
13    let led = 13;
14    let button = 2;
15
16    b.set_pin_mode(led, firmata::OUTPUT);
17    b.set_pin_mode(button, firmata::INPUT);
18
19    b.report_digital(button, 1);
20
21    loop {
22        b.decode();
23        if b.pins[button as usize].value == 0 {
24            println!("off");
25            b.digital_write(led, 0);
26        } else {
27            println!("on");
28            b.digital_write(led, 1);
29        }
30
31        thread::sleep_ms(100);
32    }
33}
Source

pub fn set_pin_mode(&mut self, pin: i32, mode: u8)

Examples found in repository?
examples/blink.rs (line 13)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    println!("firmware version {}", b.firmware_version);
10    println!("firmware name {}", b.firmware_name);
11    println!("protocol version {}", b.protocol_version);
12
13    b.set_pin_mode(13, firmata::OUTPUT);
14
15    let mut i = 0;
16
17    loop {
18        thread::sleep_ms(400);
19        println!("{}",i);
20        b.digital_write(13, i);
21        i ^= 1;
22    }
23}
More examples
Hide additional examples
examples/pwm.rs (line 15)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    let pin = 3;
10
11    println!("firmware version {}", b.firmware_version);
12    println!("firmware name {}", b.firmware_name);
13    println!("protocol version {}", b.protocol_version);
14
15    b.set_pin_mode(pin, firmata::PWM);
16
17    loop {
18        for value in 0..255 {
19            b.analog_write(pin, value);
20            println!("{}", value);
21            thread::sleep_ms(10);
22        }
23    }
24}
examples/servo.rs (line 15)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    let pin = 3;
10
11    println!("firmware version {}", b.firmware_version);
12    println!("firmware name {}", b.firmware_name);
13    println!("protocol version {}", b.protocol_version);
14
15    b.set_pin_mode(pin, firmata::SERVO);
16
17    loop {
18        for value in 0..180{
19            b.analog_write(pin, value);
20            println!("{}", value);
21            thread::sleep_ms(10);
22        }
23    }
24}
examples/analog.rs (line 15)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    let pin = 14; // A0
10
11    println!("firmware version {}", b.firmware_version);
12    println!("firmware name {}", b.firmware_name);
13    println!("protocol version {}", b.protocol_version);
14
15    b.set_pin_mode(pin, firmata::ANALOG);
16
17    b.report_analog(pin, 1);
18
19    loop {
20        b.decode();
21        println!("analog value: {:o}", b.pins[pin as usize].value);
22        thread::sleep_ms(10);
23    }
24}
examples/button.rs (line 16)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    println!("firmware version {}", b.firmware_version);
10    println!("firmware name {}", b.firmware_name);
11    println!("protocol version {}", b.protocol_version);
12
13    let led = 13;
14    let button = 2;
15
16    b.set_pin_mode(led, firmata::OUTPUT);
17    b.set_pin_mode(button, firmata::INPUT);
18
19    b.report_digital(button, 1);
20
21    loop {
22        b.decode();
23        if b.pins[button as usize].value == 0 {
24            println!("off");
25            b.digital_write(led, 0);
26        } else {
27            println!("on");
28            b.digital_write(led, 1);
29        }
30
31        thread::sleep_ms(100);
32    }
33}
Source

pub fn decode(&mut self)

Examples found in repository?
examples/blinkm_i2c.rs (line 18)
7fn init(board: Arc<Mutex<firmata::Board>>) {
8    {
9        let mut b = board.lock().unwrap();
10        b.i2c_config(0);
11        b.i2c_write(0x09, "o".as_bytes());
12        thread::sleep_ms(10);
13    }
14
15    let b = board.clone();
16    thread::spawn(move || {
17        loop {
18            b.lock().unwrap().decode();
19            b.lock().unwrap().query_firmware();
20            thread::sleep_ms(10);
21        }
22    });
23}
More examples
Hide additional examples
examples/analog.rs (line 20)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    let pin = 14; // A0
10
11    println!("firmware version {}", b.firmware_version);
12    println!("firmware name {}", b.firmware_name);
13    println!("protocol version {}", b.protocol_version);
14
15    b.set_pin_mode(pin, firmata::ANALOG);
16
17    b.report_analog(pin, 1);
18
19    loop {
20        b.decode();
21        println!("analog value: {:o}", b.pins[pin as usize].value);
22        thread::sleep_ms(10);
23    }
24}
examples/button.rs (line 22)
6fn main() {
7    let mut b = firmata::Board::new("/dev/ttyACM0");
8
9    println!("firmware version {}", b.firmware_version);
10    println!("firmware name {}", b.firmware_name);
11    println!("protocol version {}", b.protocol_version);
12
13    let led = 13;
14    let button = 2;
15
16    b.set_pin_mode(led, firmata::OUTPUT);
17    b.set_pin_mode(button, firmata::INPUT);
18
19    b.report_digital(button, 1);
20
21    loop {
22        b.decode();
23        if b.pins[button as usize].value == 0 {
24            println!("off");
25            b.digital_write(led, 0);
26        } else {
27            println!("on");
28            b.digital_write(led, 1);
29        }
30
31        thread::sleep_ms(100);
32    }
33}

Auto Trait Implementations§

§

impl Freeze for Board

§

impl RefUnwindSafe for Board

§

impl Send for Board

§

impl Sync for Board

§

impl Unpin for Board

§

impl UnwindSafe for Board

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.