forked from gkaklas/labadoor
Use struct for passing module arguments: gpio
This commit is contained in:
parent
bace7ef138
commit
104d8a862d
3 changed files with 27 additions and 13 deletions
|
@ -1,13 +1,20 @@
|
|||
use gpio_cdev::{Chip, LineRequestFlags};
|
||||
|
||||
pub fn gpio(device: String, pin: u8, active_low: bool, active_time: u32) {
|
||||
let mut chip = Chip::new(device).unwrap();
|
||||
pub struct GPIOArgs {
|
||||
pub device: String,
|
||||
pub pin: u8,
|
||||
pub active_low: bool,
|
||||
pub active_time: u32,
|
||||
}
|
||||
|
||||
pub fn gpio(args: GPIOArgs) {
|
||||
let mut chip = Chip::new(args.device).unwrap();
|
||||
let handle = chip
|
||||
.get_line(pin as u32)
|
||||
.get_line(args.pin as u32)
|
||||
.unwrap()
|
||||
.request(LineRequestFlags::OUTPUT, 1, "labadoor-gpio")
|
||||
.unwrap();
|
||||
handle.set_value(!active_low as u8).unwrap();
|
||||
std::thread::sleep(std::time::Duration::from_millis(active_time as u64));
|
||||
handle.set_value(active_low as u8).unwrap();
|
||||
handle.set_value(!args.active_low as u8).unwrap();
|
||||
std::thread::sleep(std::time::Duration::from_millis(args.active_time as u64));
|
||||
handle.set_value(args.active_low as u8).unwrap();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue