Expand description
Contains the trait implementation for the execution of the dosing Implements the physical actuation of a single mineral dosing pump.
This module provides the MineralInjectionTrait and its concrete implementation,
MineralInjection. Its sole responsibility is to translate a command to dose a
specific mineral into the physical actions of switching a peristaltic pump on and
off for a precise duration. It acts as the final link between the logical Balling
controller and the RelayManager that controls the hardware.
§Key Components
-
MineralInjectionTrait: An abstraction for the mineral injection process. This is a critical design element that decouples theBallingcontroller from the concrete implementation, enabling the use of mock injectors for unit testing. -
MineralInjectionStruct: The primary, stateless implementation of the trait. -
inject_mineral()Method: The main entry point. It orchestrates the sequence of:- Sending a
SwitchOncommand to theRelayManager. - Entering a timed loop that keeps the pump running.
- Continuously checking for a
Quitcommand from theSignalHandler. - Sending a
SwitchOffcommand upon completion or interruption.
- Sending a
§Design and Architecture
The module is designed for safe, robust, and interruptible operation.
-
Interruptible Operation: The waiting period is not a simple
sleepcall. It’s an activeloopusing aSpinSleeperthat frequently checks for externalQuitcommands. This ensures that a dosing operation can be aborted almost instantly, which is a crucial safety and responsiveness feature. -
Guaranteed Cleanup: The
SwitchOffcommand is always sent to theRelayManagerat the end of the function, regardless of whether the dosing completed normally or was interrupted. This prevents a pump from being left in the “on” state indefinitely. -
Trait-based Decoupling: By depending on the
MineralInjectionTrait, the mainBallingmodule can be tested in isolation without needing real hardware or a runningRelayManagerthread. The tests in this module use a mock version ofRelayManager.
Structs§
- Mineral
Injection - Struct implements the MineralInjectionTrait for executing the Balling mineral dosing. It also contains state attributes for the actuators. Thread communication is as follows:
Traits§
- Mineral
Injection Trait - Trait for the execution of the Balling mineral dosing. This trait allows running the main control with a mock implementation for testing.