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

43
Cargo.lock generated
View File

@@ -2,6 +2,49 @@
# It is not intended for manual editing.
version = 4
[[package]]
name = "bitflags"
version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "gpio-cdev"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09831ec59b80be69e75d29cf36e16afbbe5fd1af9c1bf4689ad91c77db5aa6a6"
dependencies = [
"bitflags",
"libc",
"nix",
]
[[package]]
name = "libc"
version = "0.2.178"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091"
[[package]]
name = "nix"
version = "0.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053"
dependencies = [
"bitflags",
"cfg-if",
"libc",
]
[[package]]
name = "snooze-pal"
version = "0.1.0"
dependencies = [
"gpio-cdev",
]

View File

@@ -4,3 +4,4 @@ version = "0.1.0"
edition = "2024"
[dependencies]
gpio-cdev = "0.6.0"

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(())
}