Add configuration options for GPIO
This commit is contained in:
parent
413568af5e
commit
c8e412fa34
4 changed files with 34 additions and 9 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -4,3 +4,9 @@ token = ""
|
|||
[matrix]
|
||||
username = ""
|
||||
password = ""
|
||||
|
||||
[gpio]
|
||||
device = ""
|
||||
pin = 1
|
||||
active_low = false
|
||||
active_time = 2000
|
||||
|
|
|
@ -16,7 +16,7 @@ pub enum Command {
|
|||
#[cfg(feature = "csv")]
|
||||
CSV,
|
||||
#[cfg(feature = "gpio")]
|
||||
GPIO,
|
||||
GPIO(GPIO),
|
||||
}
|
||||
|
||||
#[cfg(feature = "telegram")]
|
||||
|
@ -35,6 +35,19 @@ pub struct Matrix {
|
|||
pub password: Option<String>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "gpio")]
|
||||
#[derive(Deserialize, Parser, Debug)]
|
||||
pub struct GPIO {
|
||||
#[clap(short, long)]
|
||||
pub device: Option<String>,
|
||||
#[clap(short, long)]
|
||||
pub pin: Option<u8>,
|
||||
#[clap(short, long)]
|
||||
pub active_low: Option<bool>,
|
||||
#[clap(short = 't', long)]
|
||||
pub active_time: Option<u32>,
|
||||
}
|
||||
|
||||
pub fn parse() -> Cli {
|
||||
Cli::parse()
|
||||
}
|
||||
|
|
|
@ -23,8 +23,14 @@ fn main() {
|
|||
labadoor_csv::csv();
|
||||
}
|
||||
#[cfg(feature = "gpio")]
|
||||
cli::Command::GPIO => {
|
||||
labadoor_gpio::gpio();
|
||||
cli::Command::GPIO(_) => {
|
||||
let gpio = config.get::<cli::GPIO>("gpio").unwrap();
|
||||
labadoor_gpio::gpio(
|
||||
gpio.device.unwrap(),
|
||||
gpio.pin.unwrap(),
|
||||
gpio.active_low.unwrap(),
|
||||
gpio.active_time.unwrap(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue