spread code into many files
This commit is contained in:
parent
d447354472
commit
0ab2cd7858
@ -1,6 +1,7 @@
|
||||
use crate::firmware::firmware_state::FirmwareState;
|
||||
use crate::firmware::{firmware_step_crash_screen, firmware_step_hub_home, firmware_step_init_app, firmware_step_launch_hub, firmware_step_reset, firmware_step_run_app, firmware_step_splash_screen};
|
||||
use crate::hardware::{HardwareBridge, InputSignals};
|
||||
use crate::model::{Cartridge, Color};
|
||||
use crate::model::Cartridge;
|
||||
use crate::prometeu_hub::PrometeuHub;
|
||||
use crate::prometeu_os::PrometeuOS;
|
||||
|
||||
@ -21,13 +22,13 @@ impl Firmware {
|
||||
|
||||
pub fn step_frame(&mut self, signals: &InputSignals, hw: &mut dyn HardwareBridge) {
|
||||
let next_state = match &mut self.state {
|
||||
FirmwareState::Reset => Self::step_reset(&mut self.os),
|
||||
FirmwareState::SplashScreen => Self::step_splash_screen(),
|
||||
FirmwareState::LaunchHub => Self::step_launch_hub(&mut self.hub),
|
||||
FirmwareState::HubHome => Self::step_hub_home(&mut self.hub, &mut self.os, hw),
|
||||
FirmwareState::LoadApp(cartridge) => Self::step_init_app(&mut self.os, signals, hw, cartridge),
|
||||
FirmwareState::AppRunning => Self::step_run_app(&mut self.os, signals, hw),
|
||||
FirmwareState::AppCrashes(_error) => Self::step_crash_screen(signals, hw),
|
||||
FirmwareState::Reset => firmware_step_reset::step_reset(&mut self.os),
|
||||
FirmwareState::SplashScreen => firmware_step_splash_screen::step_splash_screen(),
|
||||
FirmwareState::LaunchHub => firmware_step_launch_hub::launch_hub(&mut self.os, &mut self.hub),
|
||||
FirmwareState::HubHome => firmware_step_hub_home::step_hub_home(&mut self.hub, &mut self.os, hw),
|
||||
FirmwareState::LoadApp(cartridge) => firmware_step_init_app::step_init_app(&mut self.os, signals, hw, cartridge),
|
||||
FirmwareState::AppRunning => firmware_step_run_app::step_run_app(&mut self.os, signals, hw),
|
||||
FirmwareState::AppCrashes(_error) => firmware_step_crash_screen::step_crash_screen(signals, hw),
|
||||
};
|
||||
|
||||
if let Some(new_state) = next_state {
|
||||
@ -35,54 +36,6 @@ impl Firmware {
|
||||
}
|
||||
}
|
||||
|
||||
fn step_reset(os: &mut PrometeuOS) -> Option<FirmwareState> {
|
||||
os.reset();
|
||||
Some(FirmwareState::SplashScreen)
|
||||
}
|
||||
|
||||
fn step_splash_screen() -> Option<FirmwareState> {
|
||||
Some(FirmwareState::LaunchHub)
|
||||
}
|
||||
|
||||
fn step_launch_hub(hub: &mut PrometeuHub) -> Option<FirmwareState> {
|
||||
hub.init();
|
||||
Some(FirmwareState::HubHome)
|
||||
}
|
||||
|
||||
fn step_hub_home(hub: &mut PrometeuHub, os: &mut PrometeuOS, hw: &mut dyn HardwareBridge) -> Option<FirmwareState> {
|
||||
hw.gfx_mut().clear(Color::INDIGO);
|
||||
hub.gui_update(os);
|
||||
hw.gfx_mut().present();
|
||||
None
|
||||
}
|
||||
|
||||
fn step_init_app(os: &mut PrometeuOS, _signals: &InputSignals, _hw: &mut dyn HardwareBridge, cartridge: &Cartridge) -> Option<FirmwareState> {
|
||||
os.initialize_vm(cartridge);
|
||||
// a gente precisa carregar e inicializar o cartridge antes de mudar o estado para AppRunning
|
||||
Some(FirmwareState::AppRunning)
|
||||
}
|
||||
|
||||
fn step_run_app(os: &mut PrometeuOS, signals: &InputSignals, hw: &mut dyn HardwareBridge) -> Option<FirmwareState> {
|
||||
os.step_frame(signals, hw).map(FirmwareState::AppCrashes)
|
||||
}
|
||||
|
||||
fn step_crash_screen(signals: &InputSignals, hw: &mut dyn HardwareBridge) -> Option<FirmwareState> {
|
||||
// Atualiza periféricos para input na tela de crash
|
||||
hw.pad_mut().begin_frame(signals);
|
||||
|
||||
// Tela de erro: fundo vermelho, texto branco
|
||||
hw.gfx_mut().clear(Color::RED);
|
||||
// Por enquanto apenas logamos ou mostramos algo simples
|
||||
// No futuro, usar draw_text
|
||||
hw.gfx_mut().present();
|
||||
|
||||
// Se apertar START, volta pro Hub
|
||||
if hw.pad().start.down {
|
||||
return Some(FirmwareState::LaunchHub);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn load_cartridge(&mut self, cartridge: Cartridge) {
|
||||
self.state = FirmwareState::LoadApp(cartridge); // change state
|
||||
}
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
use crate::firmware::firmware_state::FirmwareState;
|
||||
use crate::hardware::{HardwareBridge, InputSignals};
|
||||
use crate::model::Color;
|
||||
|
||||
pub fn step_crash_screen(signals: &InputSignals, hw: &mut dyn HardwareBridge) -> Option<FirmwareState> {
|
||||
// Atualiza periféricos para input na tela de crash
|
||||
hw.pad_mut().begin_frame(signals);
|
||||
|
||||
// Tela de erro: fundo vermelho, texto branco
|
||||
hw.gfx_mut().clear(Color::RED);
|
||||
// Por enquanto apenas logamos ou mostramos algo simples
|
||||
// No futuro, usar draw_text
|
||||
hw.gfx_mut().present();
|
||||
|
||||
// Se apertar START, volta pro Hub
|
||||
if hw.pad().start.down {
|
||||
return Some(FirmwareState::LaunchHub);
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
12
crates/prometeu-core/src/firmware/firmware_step_hub_home.rs
Normal file
12
crates/prometeu-core/src/firmware/firmware_step_hub_home.rs
Normal file
@ -0,0 +1,12 @@
|
||||
use crate::firmware::firmware_state::FirmwareState;
|
||||
use crate::hardware::HardwareBridge;
|
||||
use crate::model::Color;
|
||||
use crate::prometeu_hub::PrometeuHub;
|
||||
use crate::prometeu_os::PrometeuOS;
|
||||
|
||||
pub fn step_hub_home(hub: &mut PrometeuHub, os: &mut PrometeuOS, hw: &mut dyn HardwareBridge) -> Option<FirmwareState> {
|
||||
hw.gfx_mut().clear(Color::INDIGO);
|
||||
hub.gui_update(os);
|
||||
hw.gfx_mut().present();
|
||||
None
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
use crate::firmware::firmware_state::FirmwareState;
|
||||
use crate::hardware::{HardwareBridge, InputSignals};
|
||||
use crate::model::Cartridge;
|
||||
use crate::prometeu_os::PrometeuOS;
|
||||
|
||||
pub fn step_init_app(os: &mut PrometeuOS, _signals: &InputSignals, _hw: &mut dyn HardwareBridge, cartridge: &Cartridge) -> Option<FirmwareState> {
|
||||
os.initialize_vm(cartridge);
|
||||
Some(FirmwareState::AppRunning)
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
use crate::firmware::firmware_state::FirmwareState;
|
||||
use crate::prometeu_hub::PrometeuHub;
|
||||
use crate::prometeu_os::PrometeuOS;
|
||||
|
||||
pub fn launch_hub(os: &mut PrometeuOS, hub: &mut PrometeuHub) -> Option<FirmwareState> {
|
||||
hub.init();
|
||||
Some(FirmwareState::HubHome)
|
||||
}
|
||||
7
crates/prometeu-core/src/firmware/firmware_step_reset.rs
Normal file
7
crates/prometeu-core/src/firmware/firmware_step_reset.rs
Normal file
@ -0,0 +1,7 @@
|
||||
use crate::firmware::firmware_state::FirmwareState;
|
||||
use crate::prometeu_os::PrometeuOS;
|
||||
|
||||
pub fn step_reset(os: &mut PrometeuOS) -> Option<FirmwareState> {
|
||||
os.reset();
|
||||
Some(FirmwareState::SplashScreen)
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
use crate::firmware::firmware_state::FirmwareState;
|
||||
use crate::hardware::{HardwareBridge, InputSignals};
|
||||
use crate::prometeu_os::PrometeuOS;
|
||||
|
||||
pub fn step_run_app(os: &mut PrometeuOS, signals: &InputSignals, hw: &mut dyn HardwareBridge) -> Option<FirmwareState> {
|
||||
os.step_frame(signals, hw).map(FirmwareState::AppCrashes)
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
use crate::firmware::firmware_state::FirmwareState;
|
||||
|
||||
pub fn step_splash_screen() -> Option<FirmwareState> {
|
||||
Some(FirmwareState::LaunchHub)
|
||||
}
|
||||
@ -1,4 +1,12 @@
|
||||
mod firmware;
|
||||
pub mod firmware_state;
|
||||
|
||||
mod firmware_step_reset;
|
||||
mod firmware_step_splash_screen;
|
||||
mod firmware_step_launch_hub;
|
||||
mod firmware_step_hub_home;
|
||||
mod firmware_step_init_app;
|
||||
mod firmware_step_run_app;
|
||||
mod firmware_step_crash_screen;
|
||||
|
||||
pub use firmware::Firmware;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user