avoid panics

This commit is contained in:
Michael Sippel 2024-06-11 23:21:23 +02:00
parent 2441c5a133
commit 7dd728b7b9
Signed by: senvas
GPG key ID: 060F22F65102F95C
2 changed files with 17 additions and 55 deletions

View file

@ -179,6 +179,7 @@ async fn main() {
eprintln!("pressed {}", c);
let mut inputs = inputs.write().unwrap();
if c.is_ascii() {
match &c[0..1] {
"x" => {
// tap tempo
@ -189,59 +190,14 @@ async fn main() {
inputs.cycle_len = last_tap - old_tap;
}
}
"q" => {
// sync
inputs.t = Duration::from_millis(0);
tbegin = std::time::Instant::now();
},
"0" => {
inputs.scene_select = 0;
transition_begin = std::time::Instant::now();
}
"1" => {
inputs.scene_select = 1;
transition_begin = std::time::Instant::now();
}
"2" => {
inputs.scene_select = 2;
transition_begin = std::time::Instant::now();
}
"3" => {
inputs.scene_select = 3;
transition_begin = std::time::Instant::now();
}
"4" => {
inputs.scene_select = 4;
transition_begin = std::time::Instant::now();
}
"5" => {
inputs.scene_select = 5;
transition_begin = std::time::Instant::now();
},
"6" => {
inputs.scene_select = 6;
transition_begin = std::time::Instant::now();
}
"7" => {
inputs.scene_select = 7;
transition_begin = std::time::Instant::now();
}
"8" => {
inputs.scene_select = 8;
transition_begin = std::time::Instant::now();
}
"9" => {
inputs.scene_select = 9;
transition_begin = std::time::Instant::now();
}
"a" => {
inputs.scene_select = 10;
transition_begin = std::time::Instant::now();
}
"p" => {
inputs.scene_select = 11;
"0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9" => {
let idx = c.chars().nth(0).unwrap().to_digit(10).unwrap() as u32;
inputs.scene_select = idx as usize;
transition_begin = std::time::Instant::now();
}
"r" => { inputs.master_wave = match inputs.master_wave {
@ -280,6 +236,7 @@ async fn main() {
eprintln!("updated inputs:\n {:?}", inputs);
eprintln!("--------------");
}
}
_ => {}
}
}

View file

@ -75,6 +75,8 @@ impl ColorGrid for SceneLibrary {
);
}
if inputs.scene_select < self.library.len() {
if inputs.scene_select == sc {
// display only one animation
@ -109,6 +111,9 @@ impl ColorGrid for SceneLibrary {
)
}
} else {
Rgb::new(0.0, 0.0, 0.0)
}
}
}