diff --git a/left/src/main.rs b/left/src/main.rs index ce40c9b..7a550be 100644 --- a/left/src/main.rs +++ b/left/src/main.rs @@ -106,7 +106,7 @@ async fn main(_spawner: Spawner) { neopixel.write(&[Rgb::new(0x00, 0x00, 0xFF)]).await; for w in 0usize.. { - neopixel.write(&[wheel(w as u8)]).await; + neopixel.write(&[wheel(w as u8) * 0.15]).await; Timer::after(Duration::from_millis(10)).await; } } diff --git a/lib/src/keyboard/lights.rs b/lib/src/keyboard/lights.rs index 3a3c152..0fcf824 100644 --- a/lib/src/keyboard/lights.rs +++ b/lib/src/keyboard/lights.rs @@ -15,7 +15,7 @@ const UNTIL_IDLE: Duration = Duration::from_secs(30); const IDLE_ANIMATION_SPEED: u64 = 3; const IDLE_ANIMATION_KEY_OFFSET: u64 = 10; const IDLE_BRIGHTNESS_RAMPUP: Duration = Duration::from_secs(120); -const MAX_IDLE_BRIGHTESS: f32 = 0.3; +const MAX_IDLE_BRIGHTESS: f32 = 0.2; const MIN_IDLE_BRIGHTESS: f32 = 0.05; #[derive(Clone, Copy)] @@ -123,16 +123,10 @@ async fn idle_animation(state: &'static State) { let Some(light) = lights.get_mut(i) else { continue; }; - let [r, g, b] = wheel( + let rgb = wheel( (n as u64 * IDLE_ANIMATION_KEY_OFFSET + tick * IDLE_ANIMATION_SPEED) as u8, - ) - .components(); - let rgb = Rgb::new( - ((r as f32) * brightness) as u8, - ((g as f32) * brightness) as u8, - ((b as f32) * brightness) as u8, ); - *light = rgb; + *light = rgb * brightness; } }) .await; diff --git a/lib/src/rgb.rs b/lib/src/rgb.rs index a545e16..8371e91 100644 --- a/lib/src/rgb.rs +++ b/lib/src/rgb.rs @@ -1,7 +1,7 @@ use bytemuck::{cast_slice, Pod, Zeroable}; use core::{ fmt::{self, Debug}, - ops::Div, + ops::{Div, Mul}, }; /// An Rgb value that can be safely transmuted to u32 for use with Ws2812. @@ -44,6 +44,19 @@ impl Div for Rgb { } } +impl Mul for Rgb { + type Output = Rgb; + + fn mul(self, factor: f32) -> Self::Output { + let [r, g, b] = self.components(); + Rgb::new( + ((r as f32) * factor) as u8, + ((g as f32) * factor) as u8, + ((b as f32) * factor) as u8, + ) + } +} + #[cfg(all(target_arch = "x86_64", test))] mod tests { use super::*; diff --git a/right/src/main.rs b/right/src/main.rs index 0d5d6a3..7d313b3 100644 --- a/right/src/main.rs +++ b/right/src/main.rs @@ -104,7 +104,7 @@ async fn main(_spawner: Spawner) { neopixel.write(&[Rgb::new(0x00, 0x00, 0xFF)]).await; for w in 0usize.. { - neopixel.write(&[wheel(w as u8)]).await; + neopixel.write(&[wheel(w as u8) * 0.15]).await; Timer::after(Duration::from_millis(10)).await; } }