69 lines
2.4 KiB
Rust
69 lines
2.4 KiB
Rust
use crate::firmware::firmware_state::{FirmwareState, LaunchHubStep};
|
|
use crate::firmware::prometeu_context::PrometeuContext;
|
|
use prometeu_hal::color::Color;
|
|
use prometeu_hal::log::{LogLevel, LogSource};
|
|
use prometeu_hal::primitives::Rect;
|
|
use prometeu_hal::{FrameId, GfxUiCommand, RenderSubmission, ShellUiFramePacket};
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct SplashScreenStep {
|
|
pub frame: u32,
|
|
}
|
|
|
|
impl SplashScreenStep {
|
|
pub fn on_enter(&mut self, ctx: &mut PrometeuContext) {
|
|
ctx.os.log(LogLevel::Info, LogSource::Pos, 0, "Showing SplashScreen".to_string());
|
|
// Play sound on enter
|
|
// ctx.platform.audio_mut().play(0, 0, 0, 255, 127, 1.0, 0, LoopMode::Off);
|
|
}
|
|
|
|
pub fn on_update(&mut self, ctx: &mut PrometeuContext) -> Option<FirmwareState> {
|
|
const ANIMATION_DURATION: u32 = 60; // 1 second at 60fps
|
|
const TOTAL_DURATION: u32 = 240; // 4 seconds total (updated from 2s based on total_duration logic)
|
|
|
|
// Update peripherals for input
|
|
ctx.platform.input_mut().pad_mut().begin_frame(ctx.signals);
|
|
|
|
// Draw expanding square
|
|
let (sw, sh) = ctx.platform.display_size();
|
|
let max_size = (sw.min(sh) as i32 / 2).max(1);
|
|
|
|
let current_size = if self.frame < ANIMATION_DURATION {
|
|
(max_size * (self.frame as i32 + 1)) / ANIMATION_DURATION as i32
|
|
} else {
|
|
max_size
|
|
};
|
|
|
|
let x = (sw as i32 - current_size) / 2;
|
|
let y = (sh as i32 - current_size) / 2;
|
|
|
|
let packet = ShellUiFramePacket::new(vec![
|
|
GfxUiCommand::Clear { color: Color::ORANGE },
|
|
GfxUiCommand::FillRect {
|
|
rect: Rect { x, y, w: current_size, h: current_size },
|
|
color: Color::WHITE,
|
|
},
|
|
]);
|
|
ctx.platform
|
|
.render_submission_sink()
|
|
.submit_render_submission(RenderSubmission::shell_ui(FrameId::ZERO, packet))
|
|
.expect("firmware splash render submission should publish");
|
|
|
|
// Transition logic
|
|
// If any button is pressed at any time after the animation ends
|
|
if self.frame >= ANIMATION_DURATION && ctx.platform.input().pad().any() {
|
|
return Some(FirmwareState::LaunchHub(LaunchHubStep));
|
|
}
|
|
|
|
if self.frame >= TOTAL_DURATION {
|
|
return Some(FirmwareState::LaunchHub(LaunchHubStep));
|
|
}
|
|
|
|
self.frame += 1;
|
|
|
|
None
|
|
}
|
|
|
|
pub fn on_exit(&mut self, _ctx: &mut PrometeuContext) {}
|
|
}
|