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:
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: DurationImplementations§
Source§impl FoodInjection
impl FoodInjection
Sourcepub fn new(config: &FeedConfig) -> FoodInjection
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 theFeedConfigstruct, which contains parameters likedevice_switch_delay_millis.
§Returns
A new FoodInjection struct, ready to execute food dispensing operations.
Sourcefn switch_skimmer_pumps_feeder(
&mut self,
target_actuator_states: FoodInjectionTargetActuatorStates,
feed_channels: &mut FeedChannels,
) -> Result<(), Vec<FoodInjectionError>>
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- AFoodInjectionTargetActuatorStatesstruct containing the desiredActuatorStatefor 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 thanOnorOff.
Trait Implementations§
Source§impl FoodInjectionTrait for FoodInjection
impl FoodInjectionTrait for FoodInjection
Source§fn inject_food(
&mut self,
feed_channels: &mut FeedChannels,
feedpattern: &Feedpattern,
) -> (bool, Result<(), Vec<FoodInjectionError>>)
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) istrueif aQuitcommand was received from the signal handler, indicating an early termination request. Otherwise, it isfalse. - The second element is a
Result. It isOk(())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
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)
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 theFoodInjectionmodule does not process messages from a messaging channel.
§Returns
A tuple (bool, bool, bool) indicating the status of commands received:
- The first
boolistrueif aQuitcommand was received; otherwisefalse. - The second
boolis alwaysfalse(no “Start” commands processed). - The third
boolis alwaysfalse(no “Stop” commands processed).