Struct FoodInjection

Source
pub struct FoodInjection {
    skimmer_state: ActuatorState,
    main_pump1_state: ActuatorState,
    main_pump2_state: ActuatorState,
    aux_pump1_state: ActuatorState,
    aux_pump2_state: ActuatorState,
    feeder_state: ActuatorState,
    spin_sleeper: SpinSleeper,
    sleep_duration_device_switch: Duration,
}
Expand description

Struct implements the FoodInjectionTrait for executing the feed pattern. It also contains state attributes for the actuators. Thread communication is as follows:

graph LR food_injection[Food injection] --> relay_manager[Relay Manager] relay_manager --> food_injection signal_handler[Signal handler] --> food_injection

Fields§

§skimmer_state: ActuatorState§main_pump1_state: ActuatorState§main_pump2_state: ActuatorState§aux_pump1_state: ActuatorState§aux_pump2_state: ActuatorState§feeder_state: ActuatorState§spin_sleeper: SpinSleeper§sleep_duration_device_switch: Duration

Implementations§

Source§

impl FoodInjection

Source

pub fn new(config: &FeedConfig) -> FoodInjection

Creates a new FoodInjection instance.

This constructor initializes the food injection control module. It sets the initial state of all associated actuators (skimmer, pumps, feeder) to Undefined and configures internal timing mechanisms, such as the delay between device switches, based on the provided FeedConfig.

§Arguments
  • config - A reference to the FeedConfig struct, which contains parameters like device_switch_delay_millis.
§Returns

A new FoodInjection struct, ready to execute food dispensing operations.

Source

fn switch_skimmer_pumps_feeder( &mut self, target_actuator_states: FoodInjectionTargetActuatorStates, feed_channels: &mut FeedChannels, ) -> Result<(), Vec<FoodInjectionError>>

Commands the specified aquarium actuators (skimmer, main pumps, auxiliary pumps, feeder) to switch to their target states.

This private helper function iterates through a set of target states for various devices. For each device whose current state differs from its target state, it sends an appropriate SwitchOn or SwitchOff command to the relay manager and waits for an acknowledgment. It includes a small delay between each switch command.

§Arguments
  • target_actuator_states - A FoodInjectionTargetActuatorStates struct containing the desired ActuatorState for each relevant device.
  • feed_channels - A mutable reference to the struct containing the channels.
§Returns

An Ok(()) if all devices were switched successfully.

§Errors

Returns an Err(Vec<FoodInjectionError>) containing a list of all errors that occurred during the switching process. This function attempts to switch all devices even if some fail. Possible errors include:

  • RelayManagerSend: Failure to send a command to the relay manager’s channel.
  • RelayManagerReceive: Failure to receive an acknowledgment from the relay manager.
  • UndefinedTargetState...: An attempt was made to set a device to a state other than On or Off.

Trait Implementations§

Source§

impl FoodInjectionTrait for FoodInjection

Source§

fn inject_food( &mut self, feed_channels: &mut FeedChannels, feedpattern: &Feedpattern, ) -> (bool, Result<(), Vec<FoodInjectionError>>)

Actuates the feeder according to the specified feed pattern to inject food.

This implementation executes a sequence of feed phases defined in the feedpattern. For each phase, it sets the state of various pumps and the feeder, waits for a specified duration, and continuously checks for a Quit command from the signal handler to allow for graceful interruption.

After the sequence is complete or aborted, it performs a cleanup step to ensure all pumps are returned to an active state and the feeder is off.

§Arguments
  • feed_channels - A mutable reference to the struct containing the channels.
  • feedpattern - A reference to the struct holding the description of the feed pattern.
§Returns

A tuple (bool, Result<(), Vec<FoodInjectionError>>) where:

  • The first element (bool) is true if a Quit command was received from the signal handler, indicating an early termination request. Otherwise, it is false.
  • The second element is a Result. It is Ok(()) if the entire sequence is completed without any errors.
§Errors

The Result part of the return tuple will be Err(Vec<FoodInjectionError>) if one or more errors occurred during the process. The function aborts the feed sequence on the first error but still performs the final cleanup step. The vector will contain all errors encountered during both the main sequence and the cleanup.

Source§

impl ProcessExternalRequestTrait for FoodInjection

Source§

fn process_external_request( &mut self, rx_from_signal_handler: &mut AquaReceiver<InternalCommand>, _: Option<&mut AquaReceiver<InternalCommand>>, ) -> (bool, bool, bool)

Checks for and processes new commands relevant to the Food Injection module from external channels.

This is the specialized implementation of ProcessExternalRequestTrait for FoodInjection. It delegates directly to process_external_request_without_messaging, indicating that the FoodInjection module only processes commands from the signal handler and ignores any input from a messaging channel.

§Arguments
  • rx_from_signal_handler - A reference to the receiver end of the channel for commands originating from the signal handler.
  • _ - This parameter is ignored, as the FoodInjection module does not process messages from a messaging channel.
§Returns

A tuple (bool, bool, bool) indicating the status of commands received:

  • The first bool is true if a Quit command was received; otherwise false.
  • The second bool is always false (no “Start” commands processed).
  • The third bool is always false (no “Stop” commands processed).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T