diff --git a/src-slider_io/src/device/hid.rs b/src-slider_io/src/device/hid.rs index 4b4a62a..254fb34 100644 --- a/src-slider_io/src/device/hid.rs +++ b/src-slider_io/src/device/hid.rs @@ -153,7 +153,20 @@ impl HidJob { buf_chunk[1] = state_chunk[0]; buf_chunk[2] = state_chunk[2]; } - buf.data[96..240].fill(0); + + for (buf_chunks, state_chunk) in buf.data[96..240].chunks_mut(24).zip( + lights + .air_left + .chunks(3) + .rev() + .chain(lights.air_right.chunks(3)), + ) { + for idx in 0..8 { + buf_chunks[0 + idx * 3] = state_chunk[1]; + buf_chunks[1 + idx * 3] = state_chunk[0]; + buf_chunks[2 + idx * 3] = state_chunk[2]; + } + } }, ), HardwareSpec::Yuancon => Self::new( @@ -213,12 +226,14 @@ impl HidJob { WriteType::Interrupt, |buf, lights| { buf.len = 62; + + let air_color = lights.get_air_middle(); let lights_nibbles: Vec = lights .ground .chunks(3) .rev() .flat_map(|x| x.iter().map(|y| *y >> 4)) - .chain([0, 0, 0]) + .chain([air_color[0] >> 4, air_color[1] >> 4, air_color[2] >> 4]) .collect(); for (buf_chunk, state_chunk) in buf diff --git a/src-slider_io/src/state.rs b/src-slider_io/src/state.rs index 3d78ce6..5f921a9 100644 --- a/src-slider_io/src/state.rs +++ b/src-slider_io/src/state.rs @@ -102,6 +102,14 @@ impl SliderLights { self.air_right[3 * idx..3 * (idx + 1)].copy_from_slice(color); } + pub fn get_air_middle(&self) -> [u8; 3] { + return [ + ((self.air_left[3] as u16 + self.air_right[3] as u16) / 2) as u8, + ((self.air_left[4] as u16 + self.air_right[4] as u16) / 2) as u8, + ((self.air_left[5] as u16 + self.air_right[5] as u16) / 2) as u8, + ]; + } + pub fn reset(&mut self) { self.ground.fill(0); self.air_left.fill(0);