1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use futures::prelude::*;
use futures::future::{ok, err};
use crate::common::*;
use crate::manager::Manager;
use crate::error::Error;
pub mod i2c;
pub use i2c::I2c;
pub mod spi;
pub use spi::Spi;
pub mod pin;
pub use pin::Pin;
pub struct Client {
_reserved: (),
}
impl Client {
pub fn new() -> impl Future<Item=Client, Error=Error> {
ok(Client{_reserved: ()})
}
}
impl Manager for Client {
type Spi = Spi;
type Pin = Pin;
type I2c = I2c;
fn spi(&mut self, path: &str, baud: u32, mode: SpiMode) -> Box<Future<Item=Spi, Error=Error>+ Send> {
debug!("attempting connection to SPI device: {}", path);
let d = match Spi::new(path, baud, mode) {
Ok(d) => ok(d),
Err(e) => err(e),
};
Box::new(d)
}
fn pin(&mut self, path: &str, mode: PinMode) -> Box<Future<Item=Pin, Error=Error> + Send> {
debug!("attempting connection to Pin: {}", path);
let d = match Pin::new(path, mode) {
Ok(d) => ok(d),
Err(e) => err(e),
};
Box::new(d)
}
fn i2c(&mut self, path: &str) -> Box<Future<Item=I2c, Error=Error> + Send> {
debug!("attempting connection to I2c: {}", path);
let d = match I2c::new(path) {
Ok(d) => ok(d),
Err(e) => err(e),
};
Box::new(d)
}
}