diff --git a/src/main.rs b/src/main.rs index dc23fcf..15056b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,7 +39,7 @@ use ui::console_ui_loop; fn main() -> Result<(), ProgramError> { let (tx, rx) = channel::(); - let handle = thread::spawn(move || -> Result<(), ProgramError> { + let strip_handle = thread::spawn(move || -> Result<(), ProgramError> { let mut strip = LEDStrip::new(strip::Config { // I have 89 right now, but start off with 20 num_lights: 20, @@ -49,13 +49,12 @@ fn main() -> Result<(), ProgramError> { global_brightness_max: 20, tick_time_ms: strip::DEFAULT_TICK_TIME_MS, })?; - strip.strip_loop(&rx); - Err(ProgramError::General(String::from( - "Dead strip thread. Terminating", - ))) + strip.strip_loop(&rx) }); - console_ui_loop(&tx)?; + // I do not care if the console ui crashes + let _console_ui_handle = + thread::spawn(move || -> Result<(), ProgramError> { console_ui_loop(&tx) }); - handle.join()? + strip_handle.join()? } diff --git a/src/strip.rs b/src/strip.rs index 55750c9..6e38600 100644 --- a/src/strip.rs +++ b/src/strip.rs @@ -100,7 +100,7 @@ impl LEDStrip { } } - pub fn strip_loop(&mut self, rx: &Receiver) { + pub fn strip_loop(&mut self, rx: &Receiver) -> Result<(), ProgramError> { let mut exit = false; loop { let target_time = Instant::now().add(Duration::from_millis(self.config.tick_time_ms)); @@ -145,9 +145,12 @@ impl LEDStrip { } // TODO: Handle error properly - let result = self.pattern.step(); - if let Ok(true) = result { - self.write_buf_from_pattern(); + if self + .pattern + .step() + .map_err(|_| ProgramError::General(String::from("Pattern step failure")))? + { + self.write_buf_from_pattern()?; } if exit {