prevent to fast updates
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Andre Henriques 2023-03-19 09:50:55 +00:00
parent 62b9a6acd5
commit 3676821fb8

View File

@ -43,6 +43,7 @@ pub struct Render {
num_leds: u32, num_leds: u32,
last_render: u128, last_render: u128,
last_update: u128,
ws: Option<Ws2812Rpi>, ws: Option<Ws2812Rpi>,
last: Vec<RGB<f64>>, last: Vec<RGB<f64>>,
@ -55,6 +56,7 @@ pub struct Render {
struct GetRender { struct GetRender {
data: Vec<RGB<f64>>, data: Vec<RGB<f64>>,
delta: u128, delta: u128,
time: u128,
} }
fn try_into_usize (input: Option<u32>) -> Option<usize> { fn try_into_usize (input: Option<u32>) -> Option<usize> {
@ -73,6 +75,7 @@ impl Render {
conn, conn,
num_leds: 0, num_leds: 0,
last_render: 0, last_render: 0,
last_update: 0,
ws: None, ws: None,
animations: vec![], animations: vec![],
local_led_config: vec![], local_led_config: vec![],
@ -295,7 +298,8 @@ impl Render {
return GetRender { return GetRender {
data, data,
delta delta,
time
}; };
} }
@ -307,6 +311,7 @@ impl Render {
let data = get_render.data; let data = get_render.data;
let delta = get_render.delta; let delta = get_render.delta;
let time = get_render.time;
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()) {
@ -314,6 +319,12 @@ impl Render {
self.last = data.clone(); self.last = data.clone();
} }
if self.last_update - time < 500 {
println!("To Fast! Skiping");
}
self.last_update = time;
let lerp_data: Vec<RGB<f64>> = data.iter().zip(&self.last).map(|(d, l)| l.lerp(d, delta as f64)).collect(); let lerp_data: Vec<RGB<f64>> = data.iter().zip(&self.last).map(|(d, l)| l.lerp(d, delta as f64)).collect();