added crontab. this is a test for viability

This commit is contained in:
2025-12-29 20:29:51 +01:00
parent 74cedf678a
commit a4628a6f9b
4 changed files with 511 additions and 14 deletions

View File

@@ -1,11 +1,24 @@
use std::thread;
use std::{sync::{Arc, Mutex}, thread};
use gpio_cdev::{Chip, LineRequestFlags};
use cron_tab::Cron;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut chip = Chip::new("/dev/gpiochip0")?;
alarm(&mut chip)?;
Ok(())
let chip = Arc::new(Mutex::new(Chip::new("/dev/gpiochip0")?));
let mut cron = Cron::new(chrono::Local);
let job_result = cron.add_fn("0 16 20 * * * *", move || {
let mut guard = chip.lock().unwrap();
alarm(&mut*guard).unwrap();
});
let _ = job_result.expect("Failed to add job");
cron.start();
println!("Started snooze-pal");
loop { }
}
fn alarm(chip: &mut Chip) -> Result<(), Box<dyn std::error::Error>> {
@@ -22,10 +35,3 @@ fn alarm(chip: &mut Chip) -> Result<(), Box<dyn std::error::Error>> {
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(())
}