35 lines
873 B
Rust
35 lines
873 B
Rust
// This project is licensed under MIT Licese.
|
|
// See the LICENSE folder for details.
|
|
|
|
use std::thread;
|
|
|
|
use gpio_cdev::{Chip, LineRequestFlags};
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
let mut chip = Chip::new("/dev/gpiochip0")?;
|
|
alarm(&mut chip)?;
|
|
Ok(())
|
|
}
|
|
|
|
fn alarm(chip: &mut Chip) -> Result<(), Box<dyn std::error::Error>> {
|
|
let beeper = chip
|
|
.get_line(17)?
|
|
.request(LineRequestFlags::OUTPUT, 0, "my-gpio")?;
|
|
|
|
for _ in 0..5 {
|
|
beeper.set_value(1)?;
|
|
thread::sleep(std::time::Duration::from_secs(1));
|
|
beeper.set_value(0)?;
|
|
thread::sleep(std::time::Duration::from_secs(1));
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn turn_off_led(chip: &mut Chip) -> Result<(), Box<dyn std::error::Error>> {
|
|
chip.get_line(17)?
|
|
.request(LineRequestFlags::OUTPUT, 0, "my-gpio")?
|
|
.set_value(0)?;
|
|
Ok(())
|
|
}
|