Module mineral_injection

Source
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 the Balling controller from the concrete implementation, enabling the use of mock injectors for unit testing.

  • MineralInjection Struct: The primary, stateless implementation of the trait.

  • inject_mineral() Method: The main entry point. It orchestrates the sequence of:

    1. Sending a SwitchOn command to the RelayManager.
    2. Entering a timed loop that keeps the pump running.
    3. Continuously checking for a Quit command from the SignalHandler.
    4. Sending a SwitchOff command upon completion or interruption.

§Design and Architecture

The module is designed for safe, robust, and interruptible operation.

  • Interruptible Operation: The waiting period is not a simple sleep call. It’s an active loop using a SpinSleeper that frequently checks for external Quit commands. This ensures that a dosing operation can be aborted almost instantly, which is a crucial safety and responsiveness feature.

  • Guaranteed Cleanup: The SwitchOff command is always sent to the RelayManager at 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 main Balling module can be tested in isolation without needing real hardware or a running RelayManager thread. The tests in this module use a mock version of RelayManager.

Structs§

MineralInjection
Struct implements the MineralInjectionTrait for executing the Balling mineral dosing. It also contains state attributes for the actuators. Thread communication is as follows:

Traits§

MineralInjectionTrait
Trait for the execution of the Balling mineral dosing. This trait allows running the main control with a mock implementation for testing.