Add configuration options for GPIO

This commit is contained in:
George Kaklamanos 2023-06-30 20:44:37 +03:00
parent 413568af5e
commit c8e412fa34
4 changed files with 34 additions and 9 deletions

View file

@ -1,13 +1,13 @@
use gpio_cdev::{Chip, LineRequestFlags};
pub fn gpio() {
let mut chip = Chip::new("/dev/gpiochip0").unwrap();
pub fn gpio(device: String, pin: u8, active_low: bool, active_time: u32) {
let mut chip = Chip::new(device).unwrap();
let handle = chip
.get_line(6)
.get_line(pin as u32)
.unwrap()
.request(LineRequestFlags::OUTPUT, 1, "labadoor-gpio")
.unwrap();
handle.set_value(1).unwrap();
std::thread::sleep(std::time::Duration::from_millis(2000));
handle.set_value(0).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();
}