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