Refactor idle animation
This commit is contained in:
@ -5,7 +5,7 @@ use futures::{select_biased, FutureExt};
|
||||
use tgnt::button::Button;
|
||||
|
||||
use crate::{
|
||||
lights::shaders::{LsdHyperspace, OrthoRainbow, PowerOffAnim, PowerOnAnim, Shader, Shaders},
|
||||
lights::shaders::{PowerOffAnim, PowerOnAnim, Shader, Shaders},
|
||||
rgb::Rgb,
|
||||
usb::{UsbEvent, USB_EVENTS},
|
||||
};
|
||||
@ -18,6 +18,8 @@ const UNTIL_IDLE: Duration = Duration::from_secs(30);
|
||||
/// DUration between each animation frame.
|
||||
const FRAMETIME: Duration = Duration::from_millis(16);
|
||||
|
||||
const IDLE_ANIM: Shaders = Shaders::OrthoRainbow;
|
||||
|
||||
#[derive(Default)]
|
||||
enum LightsState {
|
||||
Active {
|
||||
@ -74,7 +76,7 @@ pub(super) async fn task(mut events: KbEvents, state: &'static State) {
|
||||
*idle_at = Instant::now() + UNTIL_IDLE;
|
||||
handle_usb_event(ev, &mut lights).await;
|
||||
}
|
||||
_ = Timer::at(*idle_at).fuse() => lights = LightsState::Idle(Shaders::LsdHyperspace(LsdHyperspace)),
|
||||
_ = Timer::at(*idle_at).fuse() => lights = LightsState::Idle(IDLE_ANIM),
|
||||
_ = Timer::at(*next_frame).fuse() => {
|
||||
keypress_tick(state, keys).await;
|
||||
*next_frame = Instant::now() + FRAMETIME;
|
||||
|
||||
@ -17,22 +17,15 @@ pub trait Shader {
|
||||
}
|
||||
|
||||
pub enum Shaders {
|
||||
OrthoRainbow(OrthoRainbow),
|
||||
LsdHyperspace(LsdHyperspace),
|
||||
OrthoRainbow,
|
||||
LsdHyperspace,
|
||||
}
|
||||
|
||||
impl Shader for Shaders {
|
||||
fn sample(&self, time: Instant, uv: (f32, f32)) -> Rgb {
|
||||
match self {
|
||||
Shaders::OrthoRainbow(s) => s.sample(time, uv),
|
||||
Shaders::LsdHyperspace(s) => s.sample(time, uv),
|
||||
}
|
||||
}
|
||||
|
||||
fn end_time(&self) -> Option<Instant> {
|
||||
match self {
|
||||
Shaders::OrthoRainbow(s) => s.end_time(),
|
||||
Shaders::LsdHyperspace(s) => s.end_time(),
|
||||
Shaders::OrthoRainbow => OrthoRainbow.sample(time, uv),
|
||||
Shaders::LsdHyperspace => LsdHyperspace.sample(time, uv),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user