Handle errors properly
This commit is contained in:
parent
409f1d65a5
commit
3a1faf7edc
13
src/main.rs
13
src/main.rs
@ -39,7 +39,7 @@ use ui::console_ui_loop;
|
||||
|
||||
fn main() -> Result<(), ProgramError> {
|
||||
let (tx, rx) = channel::<Message>();
|
||||
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()?
|
||||
}
|
||||
|
11
src/strip.rs
11
src/strip.rs
@ -100,7 +100,7 @@ impl LEDStrip {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn strip_loop(&mut self, rx: &Receiver<Message>) {
|
||||
pub fn strip_loop(&mut self, rx: &Receiver<Message>) -> 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user