Skip to content

Commit

Permalink
Attempt at organizing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
acodili-jg committed May 14, 2024
1 parent 98f7dce commit b2939ee
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ constants! {
RINSING = DEFAULT_LONG;
SEPARATOR_HOLDING = DEFAULT_LONG;
SEPARATOR_TRANSITION = DEFAULT;
SOAK_WATER_PUMPING = DEFAULT_LONG;
WATER_PUMPING = DEFAULT_LONG;
}
6 changes: 3 additions & 3 deletions src/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl Sketch {
self.water_pump.set_high();
}

State::InitialSetupWaterPumping if delta_ms < duration::SOAK_WATER_PUMPING => {}
State::InitialSetupWaterPumping if delta_ms < duration::WATER_PUMPING => {}
State::InitialSetupWaterPumping => {
transition_to!(InitialSetupSeparatorClosing);
self.water_pump.set_low();
Expand All @@ -209,7 +209,7 @@ impl Sketch {
self.upper_drain_pump.set_high();
self.water_pump.set_low();
}
State::SoakWaterPumping if delta_ms < duration::SOAK_WATER_PUMPING => {}
State::SoakWaterPumping if delta_ms < duration::WATER_PUMPING => {}
State::SoakWaterPumping => {
transition_to!(SoakWaterHeating);
self.water_pump.set_low();
Expand Down Expand Up @@ -318,7 +318,7 @@ impl Sketch {
self.water_pump.set_high();
}

State::SetupWaterPumping if delta_ms < duration::SOAK_WATER_PUMPING => {}
State::SetupWaterPumping if delta_ms < duration::WATER_PUMPING => {}
State::SetupWaterPumping => {
transition_to!(SetupSeparatorClosing);
self.water_pump.set_low();
Expand Down
94 changes: 94 additions & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::{duration, millis::Millis};

#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum State {
#[default]
Expand Down Expand Up @@ -27,3 +29,95 @@ pub enum State {
Locking,
Unlocking,
}

#[allow(clippy::cognitive_complexity)]
#[must_use]
pub fn override_for(curr: State, delta: Millis, starting: bool, stopping: bool) -> Option<State> {
Some(match curr {
State::InitialDraining if delta >= duration::DRAINING => State::InitialIdling,

State::InitialIdling if starting => State::InitialLocking,

State::InitialLocking if !starting => State::InitialUnlocking,
State::InitialLocking if delta >= duration::LOCKING => State::InitialSetupSeparatorOpening,

State::InitialUnlocking if delta >= duration::LOCKING => State::InitialIdling,

State::InitialSetupSeparatorOpening if delta >= duration::SEPARATOR_TRANSITION => {
State::InitialSetupWaterPumping
}

State::InitialSetupWaterPumping if delta >= duration::WATER_PUMPING => {
State::InitialSetupSeparatorClosing
}

State::InitialSetupSeparatorClosing if delta >= duration::SEPARATOR_TRANSITION => {
State::SoakWaterPumping
}

State::SoakWaterPumping
| State::SoakWaterHeating
| State::SoakWaterHeatedMixing
| State::SoakWaterMixing
if stopping =>
{
State::SoakWaterDraining
}

State::SoakWaterPumping if delta >= duration::WATER_PUMPING => State::SoakWaterDraining,
State::SoakWaterHeating if delta >= duration::HEATING => State::SoakWaterHeatedMixing,
State::SoakWaterHeatedMixing if delta >= duration::HEATED_MIXING => State::SoakWaterMixing,
State::SoakWaterMixing if delta >= duration::MIXING => State::SoakWaterDraining,

State::SoakWaterDraining if delta >= duration::DRAINING => {
if stopping {
State::Idling
} else {
State::RinseWaterPumping
}
}

State::RinseWaterPumping if stopping || delta >= duration::RINSING => {
State::RinseWaterDraining
}

State::RinseWaterDraining if delta >= duration::DRAINING => {
if stopping {
State::Idling
} else {
State::SeparatorOpening
}
}

State::SeparatorOpening if delta >= duration::SEPARATOR_TRANSITION => {
State::SeparatorHolding
}

State::SeparatorHolding if delta >= duration::SEPARATOR_HOLDING => State::SeparatorClosing,

State::SeparatorClosing if delta >= duration::SEPARATOR_TRANSITION => State::Blending,

State::Blending if delta >= duration::BLENDING => State::PulpDraining,

State::PulpDraining if delta >= duration::DRAINING => State::SetupSeparatorOpening,

State::SetupSeparatorOpening if delta >= duration::SEPARATOR_TRANSITION => {
State::SetupWaterPumping
}

State::SetupWaterPumping if delta >= duration::WATER_PUMPING => {
State::SetupSeparatorClosing
}

State::SetupSeparatorClosing if delta >= duration::SEPARATOR_TRANSITION => State::Idling,

State::Idling if starting => State::Locking,

State::Locking if !starting => State::Unlocking,
State::Locking if delta >= duration::LOCKING => State::SoakWaterPumping,

State::Unlocking if delta >= duration::LOCKING => State::Idling,

_ => return None,
})
}

0 comments on commit b2939ee

Please sign in to comment.