39 lines
1.4 KiB
Rust
39 lines
1.4 KiB
Rust
use crate::firmware::boot_target::BootTarget;
|
|
use crate::firmware::firmware_state::{FirmwareState, HubHomeStep, LoadCartridgeStep};
|
|
use crate::firmware::prometeu_context::PrometeuContext;
|
|
use prometeu_hal::cartridge_loader::CartridgeLoader;
|
|
use prometeu_hal::log::{LogLevel, LogSource};
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct LaunchHubStep;
|
|
|
|
impl LaunchHubStep {
|
|
pub fn on_enter(&mut self, ctx: &mut PrometeuContext) {
|
|
ctx.os.log(LogLevel::Info, LogSource::Pos, 0, "Launching Hub".to_string());
|
|
ctx.hub.init();
|
|
}
|
|
|
|
pub fn on_update(&mut self, ctx: &mut PrometeuContext) -> Option<FirmwareState> {
|
|
if let BootTarget::Cartridge { path, .. } = ctx.boot_target {
|
|
match CartridgeLoader::load(path) {
|
|
Ok(cartridge) => {
|
|
// In the case of debug, we could pause here, but the requirement says
|
|
// for the Runtime to open the socket and wait.
|
|
return Some(FirmwareState::LoadCartridge(LoadCartridgeStep::new(cartridge)));
|
|
}
|
|
Err(e) => {
|
|
ctx.os.log(
|
|
LogLevel::Error,
|
|
LogSource::Pos,
|
|
0,
|
|
format!("Failed to auto-load cartridge: {:?}", e),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
Some(FirmwareState::HubHome(HubHomeStep))
|
|
}
|
|
|
|
pub fn on_exit(&mut self, _ctx: &mut PrometeuContext) {}
|
|
}
|