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> {
|
fn main() -> Result<(), ProgramError> {
|
||||||
let (tx, rx) = channel::<Message>();
|
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 {
|
let mut strip = LEDStrip::new(strip::Config {
|
||||||
// I have 89 right now, but start off with 20
|
// I have 89 right now, but start off with 20
|
||||||
num_lights: 20,
|
num_lights: 20,
|
||||||
@ -49,13 +49,12 @@ fn main() -> Result<(), ProgramError> {
|
|||||||
global_brightness_max: 20,
|
global_brightness_max: 20,
|
||||||
tick_time_ms: strip::DEFAULT_TICK_TIME_MS,
|
tick_time_ms: strip::DEFAULT_TICK_TIME_MS,
|
||||||
})?;
|
})?;
|
||||||
strip.strip_loop(&rx);
|
strip.strip_loop(&rx)
|
||||||
Err(ProgramError::General(String::from(
|
|
||||||
"Dead strip thread. Terminating",
|
|
||||||
)))
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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;
|
let mut exit = false;
|
||||||
loop {
|
loop {
|
||||||
let target_time = Instant::now().add(Duration::from_millis(self.config.tick_time_ms));
|
let target_time = Instant::now().add(Duration::from_millis(self.config.tick_time_ms));
|
||||||
@ -145,9 +145,12 @@ impl LEDStrip {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Handle error properly
|
// TODO: Handle error properly
|
||||||
let result = self.pattern.step();
|
if self
|
||||||
if let Ok(true) = result {
|
.pattern
|
||||||
self.write_buf_from_pattern();
|
.step()
|
||||||
|
.map_err(|_| ProgramError::General(String::from("Pattern step failure")))?
|
||||||
|
{
|
||||||
|
self.write_buf_from_pattern()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if exit {
|
if exit {
|
||||||
|
Loading…
Reference in New Issue
Block a user