added depedency for gpio, implemented proof of concept alarm

This commit is contained in:
2025-12-03 19:40:34 +01:00
parent b7417455aa
commit c5c185c5ab
3 changed files with 74 additions and 2 deletions

View File

@@ -1,6 +1,34 @@
// This project is licensed under MIT Licese.
// See the LICENSE folder for details.
fn main() {
println!("Hello, world!!");
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(())
}