diff --git a/lib/state_machine/Cargo.toml b/lib/state_machine/Cargo.toml index 4c954a8..023d1ba 100644 --- a/lib/state_machine/Cargo.toml +++ b/lib/state_machine/Cargo.toml @@ -3,5 +3,5 @@ name = "hyped_state_machine" version = "0.1.0" edition = "2021" -[lib] -path = "src/state_machine.rs" \ No newline at end of file +[features] +std = [] \ No newline at end of file diff --git a/lib/state_machine/src/lib.rs b/lib/state_machine/src/lib.rs new file mode 100644 index 0000000..7669a46 --- /dev/null +++ b/lib/state_machine/src/lib.rs @@ -0,0 +1,4 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +pub mod state_machine; +pub mod types; diff --git a/lib/state_machine/src/state_machine.rs b/lib/state_machine/src/state_machine.rs index ffbccb3..01f6c94 100644 --- a/lib/state_machine/src/state_machine.rs +++ b/lib/state_machine/src/state_machine.rs @@ -1 +1,12 @@ -#![no_std] +use crate::types::State; + +pub struct StateMachine { + current_state: State, + // transition_map: HashMap (use heapless::FnvIndexMap)? +} + +impl StateMachine { + pub fn handle_transition(&mut self) { + self.current_state = State::KStopped; + } +} diff --git a/lib/state_machine/src/types.rs b/lib/state_machine/src/types.rs new file mode 100644 index 0000000..8af0c90 --- /dev/null +++ b/lib/state_machine/src/types.rs @@ -0,0 +1,27 @@ +#[derive(Hash)] +pub enum State { + KIdle, + KCalibrate, + KPrecharge, + KReadyForLevitation, + KBeginLevitation, + KLevitating, + KReady, + KAccelerate, + KLimBrake, + KFrictionBrake, + KStopLevitation, + KStopped, + KBatteryRecharge, + KCapacitorDischarge, + KFailureBrake, + KFailure, + KSafe, + KShutdown, +} + +#[derive(Hash)] +pub struct SourceAndTarget { + source: State, + target: State, +}