diff --git a/src/main.rs b/src/main.rs index 1e56068..9eeca6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ use std::sync::Arc; use redis_ctrl::{RedisCtrl, Order}; use conf::Conf; use errors::LJResult; -use point::Point; +use point::{Point,Color}; use transformer::Transformers; use log::{LevelFilter, info, /* warn, */ error}; use env_logger::Builder; @@ -87,9 +87,10 @@ fn run_all() -> LJResult<()> { // 6 : Max Intensity Change = reread redis key /intensity // 7 : kpps change = reread redis key /kpps // 8 : color balance change = reread redis keys /red /green /blue - match order { - Order::Draw => { + Order::Draw | Order::Black => { + world_state.black = order == Order::Black; + let frame = get_next_frame( &config, &transformers, @@ -103,8 +104,6 @@ fn run_all() -> LJResult<()> { world_state.intensity = rs.get_int("intensity")? .try_into()?; }, - Order::Black => { - }, Order::Edh => { world_state.edh = rs.get_edh()?; }, @@ -157,6 +156,27 @@ fn get_next_frame( for transformer in transformers { line = transformer.apply(&line, world_state); } + + info!("-> {}", world_state.black); + + // LIMITER and BLACK + line = line.into_iter() + .map(| p | { + + let color = if world_state.black { + Color { r: 0, g: 0, b: 0 } + } else { + Color { + r: p.color.r.min(world_state.intensity), + g: p.color.g.min(world_state.intensity), + b: p.color.b.min(world_state.intensity) + } + }; + Point { color, + ..p + } + }) + .collect(); //info!("Line: {:?}", line); Ok(line) diff --git a/src/point.rs b/src/point.rs index 5eb6d42..21c65c8 100644 --- a/src/point.rs +++ b/src/point.rs @@ -7,9 +7,9 @@ pub struct Point { #[derive(Debug,Clone,Copy,Default,PartialEq)] pub struct Color { - r: u8, - g: u8, - b: u8 + pub r: u8, + pub g: u8, + pub b: u8 } impl From<(f32,f32,u32)> for Point { diff --git a/src/worldstate.rs b/src/worldstate.rs index c097247..24bb22a 100644 --- a/src/worldstate.rs +++ b/src/worldstate.rs @@ -43,7 +43,8 @@ pub struct WorldState { pub client_key: String, //u8, pub intensity: u8, pub kpps: u32, - pub color: Color + pub color: Color, + pub black: bool } impl WorldState {