Tweak brightness

This commit is contained in:
2023-12-19 19:31:08 +01:00
parent 7d9cfe9557
commit 00b3b51b36
4 changed files with 19 additions and 12 deletions

View File

@ -106,7 +106,7 @@ async fn main(_spawner: Spawner) {
neopixel.write(&[Rgb::new(0x00, 0x00, 0xFF)]).await; neopixel.write(&[Rgb::new(0x00, 0x00, 0xFF)]).await;
for w in 0usize.. { 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; Timer::after(Duration::from_millis(10)).await;
} }
} }

View File

@ -15,7 +15,7 @@ const UNTIL_IDLE: Duration = Duration::from_secs(30);
const IDLE_ANIMATION_SPEED: u64 = 3; const IDLE_ANIMATION_SPEED: u64 = 3;
const IDLE_ANIMATION_KEY_OFFSET: u64 = 10; const IDLE_ANIMATION_KEY_OFFSET: u64 = 10;
const IDLE_BRIGHTNESS_RAMPUP: Duration = Duration::from_secs(120); 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; const MIN_IDLE_BRIGHTESS: f32 = 0.05;
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
@ -123,16 +123,10 @@ async fn idle_animation(state: &'static State) {
let Some(light) = lights.get_mut(i) else { let Some(light) = lights.get_mut(i) else {
continue; continue;
}; };
let [r, g, b] = wheel( let rgb = wheel(
(n as u64 * IDLE_ANIMATION_KEY_OFFSET + tick * IDLE_ANIMATION_SPEED) as u8, (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; .await;

View File

@ -1,7 +1,7 @@
use bytemuck::{cast_slice, Pod, Zeroable}; use bytemuck::{cast_slice, Pod, Zeroable};
use core::{ use core::{
fmt::{self, Debug}, fmt::{self, Debug},
ops::Div, ops::{Div, Mul},
}; };
/// An Rgb value that can be safely transmuted to u32 for use with Ws2812. /// An Rgb value that can be safely transmuted to u32 for use with Ws2812.
@ -44,6 +44,19 @@ impl Div<u8> for Rgb {
} }
} }
impl Mul<f32> 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))] #[cfg(all(target_arch = "x86_64", test))]
mod tests { mod tests {
use super::*; use super::*;

View File

@ -104,7 +104,7 @@ async fn main(_spawner: Spawner) {
neopixel.write(&[Rgb::new(0x00, 0x00, 0xFF)]).await; neopixel.write(&[Rgb::new(0x00, 0x00, 0xFF)]).await;
for w in 0usize.. { 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; Timer::after(Duration::from_millis(10)).await;
} }
} }