diff --git a/boards/recovery/src/data_manager.rs b/boards/recovery/src/data_manager.rs index acceff1e..f5eab5e0 100644 --- a/boards/recovery/src/data_manager.rs +++ b/boards/recovery/src/data_manager.rs @@ -141,6 +141,7 @@ impl DataManager { messages::Data::Sensor(sensor) => match sensor.data { messages::sensor::SensorData::Air(air_data) => { /* + NOTE!!! There should be added a counter to check how many times the alt is dropped, if the number is high switch to diff --git a/boards/recovery/src/state_machine/mod.rs b/boards/recovery/src/state_machine/mod.rs index 3972b687..447190bd 100644 --- a/boards/recovery/src/state_machine/mod.rs +++ b/boards/recovery/src/state_machine/mod.rs @@ -12,6 +12,7 @@ use defmt::Format; use enum_dispatch::enum_dispatch; use messages::state; use rtic::Mutex; +pub use states::Abort; pub use states::Initializing; pub trait StateMachineSharedResources { @@ -61,6 +62,26 @@ impl StateMachine { } } + pub fn handle_event(&mut self, _event: RocketEvents, context: &mut StateMachineContext) { + if let Some(new_state) = self.state.event(event) { + self.state.exit(); + new_state.enter(context); + self.state = new_state; + } else { + match event { + RocketEvents::DeployDrogue(true) => todo!(), + RocketEvents::DeployMain(true) => todo!(), + RocketEvents::Abort => { + self.state.exit(); + let new_state = RocketStates::Abort(Abort {}); + // new_state.enter(context); + self.state = new_state; + } + _ => {} + } + } + } + pub fn get_state(&self) -> RocketStates { self.state.clone() } @@ -74,8 +95,9 @@ impl Default for StateMachine { // All events are found here pub enum RocketEvents { - DeployDrogue, - DeployMain, + DeployDrogue(bool), + DeployMain(bool), + Abort, } // All states are defined here. Another struct must be defined for the actual state, and that struct diff --git a/boards/recovery/src/state_machine/states/descent.rs b/boards/recovery/src/state_machine/states/descent.rs index 53b02270..b68b3194 100644 --- a/boards/recovery/src/state_machine/states/descent.rs +++ b/boards/recovery/src/state_machine/states/descent.rs @@ -1,12 +1,13 @@ use super::Ascent; use crate::app::fire_drogue; use crate::state_machine::{ - RocketStates, State, StateMachineContext, TerminalDescent, TransitionInto, + RocketEvents, RocketStates, State, StateMachineContext, TerminalDescent, TransitionInto, }; use crate::{no_transition, transition}; use common_arm::spawn; use defmt::{write, Format, Formatter}; use rtic::mutex::Mutex; +use typenum::False; #[derive(Debug, Clone)] pub struct Descent {} @@ -27,6 +28,16 @@ impl State for Descent { } }) } + + fn event(&mut self, event: RocketEvents, context: &mut StateMachineContext) -> Option { + match event { + RocketEvents::DeployDrogue(false) => context.shared_resources.em.run(|| { + spawn!(fire_drogue)?; + Ok(()) + }), + _ => None, + } + } } impl TransitionInto for Ascent { diff --git a/boards/recovery/src/state_machine/states/terminal_descent.rs b/boards/recovery/src/state_machine/states/terminal_descent.rs index b95b0a58..af5278c1 100644 --- a/boards/recovery/src/state_machine/states/terminal_descent.rs +++ b/boards/recovery/src/state_machine/states/terminal_descent.rs @@ -1,7 +1,7 @@ use super::Descent; use crate::app::fire_main; use crate::state_machine::{ - RocketStates, State, StateMachineContext, TransitionInto, WaitForRecovery, + RocketEvents, RocketStates, State, StateMachineContext, TransitionInto, WaitForRecovery, }; use crate::{no_transition, transition}; use atsamd_hal::prelude::_embedded_hal_timer_CountDown; @@ -37,6 +37,15 @@ impl State for TerminalDescent { } }) } + fn event(&mut self, event: RocketEvents, context: &mut StateMachineContext) -> Option { + match event { + RocketEvents::DeployMain(false) => context.shared_resources.em.run(|| { + spawn!(fire_main)?; + Ok(()) + }), + _ => None, + } + } } impl TransitionInto for Descent {