quit should clear
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Andre Henriques 2023-03-18 15:09:06 +00:00
parent 80fb12db49
commit 51d25b4303
2 changed files with 47 additions and 4 deletions

View File

@ -103,7 +103,7 @@ fn ligth_controll(
}, },
Action::Stop => { Action::Stop => {
render.blank(); render.blank();
render.render(); render.im_render();
break 'mainloop; break 'mainloop;
}, },
} }

View File

@ -52,6 +52,11 @@ pub struct Render {
local_led_config: Vec<LocalLedConfiguration>, local_led_config: Vec<LocalLedConfiguration>,
} }
struct GetRender {
data: Vec<RGB<f64>>,
delta: u128,
}
fn try_into_usize (input: Option<u32>) -> Option<usize> { fn try_into_usize (input: Option<u32>) -> Option<usize> {
if input.is_none() {return None;} if input.is_none() {return None;}
@ -230,9 +235,7 @@ impl Render {
} }
} }
pub fn render(&mut self) { fn get_render(&mut self) -> GetRender {
if self.ws.is_none() { return; }
let mut data: Vec<RGB<f64>> = vec![RGB::default(); self.num_leds.try_into().unwrap()]; let mut data: Vec<RGB<f64>> = vec![RGB::default(); self.num_leds.try_into().unwrap()];
@ -290,6 +293,21 @@ impl Render {
to_clean.iter().for_each(|i| self.remove_animation(i.to_string())); to_clean.iter().for_each(|i| self.remove_animation(i.to_string()));
return GetRender {
data,
delta
};
}
pub fn render(&mut self) {
if self.ws.is_none() { return; }
let get_render = self.get_render();
let data = get_render.data;
let delta = get_render.delta;
if self.last.is_empty() || !self.last.clone().iter().eq(data.clone().iter()) { if self.last.is_empty() || !self.last.clone().iter().eq(data.clone().iter()) {
if self.last.len() == 0 { if self.last.len() == 0 {
@ -313,6 +331,31 @@ impl Render {
} }
} }
pub fn im_render(&mut self) {
if self.ws.is_none() { return; }
let data = self.get_render().data;
if self.last.is_empty() || !self.last.clone().iter().eq(data.clone().iter()) {
if self.last.len() == 0 {
self.last = data.clone();
}
let to_set_data: Vec<RGB<u8>> = rgbs_f64_to_u8(&data);
let err = self.ws.as_mut().unwrap().write(to_set_data.into_iter());
if err.is_err() || err.ok().is_none() {
println!("Failed to write data");
}
self.last = data;
}
}
} }
pub fn rgbs_f64_to_u8(data: &Vec<RGB<f64>>) -> Vec<RGB<u8>>{ pub fn rgbs_f64_to_u8(data: &Vec<RGB<f64>>) -> Vec<RGB<u8>>{