diff --git a/src/rustylee/src/brain.rs b/src/rustylee/src/brain.rs index 3117499..09980f1 100644 --- a/src/rustylee/src/brain.rs +++ b/src/rustylee/src/brain.rs @@ -1,13 +1,15 @@ pub mod state; +pub mod led_pump; pub use self::state::State; use tracing::info; use std::thread::JoinHandle; - +use self::led_pump::LedPump; pub struct Brain { pub state: State, device_threads: Vec>, + led_pump: LedPump } impl Brain { @@ -15,6 +17,7 @@ impl Brain { Self { state: State::Starting, device_threads: Vec::new(), + led_pump: LedPump::new() } } @@ -31,7 +34,7 @@ impl Brain { self.state = State::Running; } State::Running => { - // Logic will go here eventually + self.led_pump.beat(); } State::Stopping => { info!("Brain: Waiting for all threads to join..."); diff --git a/src/rustylee/src/brain/led_pump.rs b/src/rustylee/src/brain/led_pump.rs new file mode 100644 index 0000000..9360466 --- /dev/null +++ b/src/rustylee/src/brain/led_pump.rs @@ -0,0 +1,28 @@ +use std::time::{Duration, Instant}; +use tracing::debug; +pub struct LedPump { + last_beat: Option, + interval: Duration, +} + +impl LedPump { + pub fn new() -> LedPump { + Self{ + last_beat: None, + interval: Duration::from_millis(500), + } + } + + pub fn beat(&mut self) { + let now = Instant::now(); + + + let should_beat = self.last_beat.map_or( + true, |last_beat| now.duration_since(last_beat) > self.interval); + + if should_beat { + self.last_beat = Some(now); + debug!("LED Pump beat."); + } + } +} \ No newline at end of file diff --git a/src/rustylee/src/main.rs b/src/rustylee/src/main.rs index 0cabfc7..4a99184 100644 --- a/src/rustylee/src/main.rs +++ b/src/rustylee/src/main.rs @@ -45,7 +45,7 @@ fn setup_logging() { .compact(); tracing_subscriber::registry() - .with(EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"))) + .with(EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("debug"))) .with(console_layer) .init(); } \ No newline at end of file