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
use sysfs_gpio::Pin;
use traits::Device;
#[derive(Debug)]
pub struct GPIODevice {
pub pin: Pin
}
impl GPIODevice {
pub fn new(pin:u64) -> GPIODevice{
let gpio = Pin::new(pin);
gpio.export().expect("Could not export the selected gpio");
GPIODevice {pin:gpio}
}
}
impl Device for GPIODevice {
fn pin(&self) -> Pin {
self.pin
}
fn value(&self) -> i8 {
let value = self.pin.get_value().expect("Could not check if device is active");
value as i8
}
}