EduArt Sensor Ring Library 3.0.0
Loading...
Searching...
No Matches
eduart::ring::SensorRingFactory Class Reference

Factory for creating a SensorRing. More...

#include <SensorRingFactory.hpp>

Collaboration diagram for eduart::ring::SensorRingFactory:
[legend]

Public Types

using DeviceParamsVariant = std::variant<device::VL53L8CX_Params, device::HTPA32_Params, device::WS2812b_Params>
 Currently supported devices for explicit configuration in expectBoard().
using EnumerationMap = std::unordered_map<com::ComInterfaceID, std::vector<device::EnumerationInformation> >
 Per-interface enumeration results, keyed by interface ID.

Public Member Functions

void addInterface (com::ComInterfaceID interface)
 Add a communication interface (bus) to scan during build().
void expectBoard (device::SensorBoardParams params)
 Declare an expected board on the current interface.
void expectBoard (device::SensorBoardParams params, std::vector< DeviceParamsVariant > device_params)
 Declare an expected board together with explicit per-device params.
void setDefaultDeviceParams (DeviceParamsVariant params)
 Set default params applied to every device of the given type that has no explicit params from expectBoard().
std::unique_ptr< SensorRingbuild (ValidationMode mode=ValidationMode::Strict)
 Enumerate hardware on all added interfaces, validate against expectations, and construct the SensorRing.
EnumerationMap enumerate ()
 Enumerate hardware on all added interfaces without building a SensorRing.
const EnumerationMapgetLatestEnumerationResult () const
 Return the enumeration results from the last enumerate() or build() call.
std::string printTopology () const
 Format the latest enumeration results as a human-readable topology string.
void reset ()
 Reset the factory to its initial state. Enumeration results are preserved.

Static Public Attributes

static constexpr Version MIN_FIRMWARE_VERSION = { 0, 8, 0 }
 Minimum sensor board firmware version required by this library version.

Detailed Description

Factory for creating a SensorRing.

Usage:

  1. Call addInterface() for every communication bus to use.
  2. Optionally call expectBoard() (once per expected board, in index order) to declare what hardware should be present and which device params to apply.
  3. Optionally call setDefaultDeviceParams() to set params applied to every device of that type that does not have explicit params from expectBoard().
  4. Call build() to enumerate hardware, validate against expectations, and construct the SensorRing.

If no expectBoard() calls are made for an interface, build() operates in pure auto-discovery mode: every board found on the bus is used with default (or setDefaultDeviceParams) configuration.

When expectations are present, the validation mode controls how mismatches are handled:

  • Strict (default): boards are matched by index; any mismatch fails the build.
  • Relaxed: for each expectation, the factory searches all unclaimed boards for the first one with a compatible board type and the required device types. Boards that are not claimed by any expectation remain unconfigured.

Member Function Documentation

◆ addInterface()

void eduart::ring::SensorRingFactory::addInterface ( com::ComInterfaceID interface)

Add a communication interface (bus) to scan during build().

All subsequent expectBoard() calls apply to this interface until the next addInterface() call.

◆ build()

std::unique_ptr< SensorRing > eduart::ring::SensorRingFactory::build ( ValidationMode mode = ValidationMode::Strict)

Enumerate hardware on all added interfaces, validate against expectations, and construct the SensorRing.

Parameters
[in]modeValidation mode (default: Strict). In Relaxed mode, mismatched boards are skipped instead of aborting.
Returns
Unique pointer to the SensorRing, or nullptr on failure.

◆ enumerate()

EnumerationMap eduart::ring::SensorRingFactory::enumerate ( )

Enumerate hardware on all added interfaces without building a SensorRing.

Useful for interactive applications that want to discover connected boards before committing to a build. Results are stored and retrievable via getLatestEnumerationResult(). Also called internally by build().

Returns
Per-interface enumeration results.

◆ expectBoard() [1/2]

void eduart::ring::SensorRingFactory::expectBoard ( device::SensorBoardParams params)

Declare an expected board on the current interface.

Matched by index order against enumeration results. If params.board_type is not Undefined it is validated against the hardware-reported type. All devices reported by the hardware are instantiated; setDefaultDeviceParams() applies.

◆ expectBoard() [2/2]

void eduart::ring::SensorRingFactory::expectBoard ( device::SensorBoardParams params,
std::vector< DeviceParamsVariant > device_params )

Declare an expected board together with explicit per-device params.

Only the device types present in device_params are instantiated; the hardware must have at least those devices or build() fails. If params.board_type is not Undefined it is additionally validated.

◆ getLatestEnumerationResult()

const EnumerationMap & eduart::ring::SensorRingFactory::getLatestEnumerationResult ( ) const

Return the enumeration results from the last enumerate() or build() call.

Returns
Per-interface enumeration results. Empty if neither method has been called yet.

◆ printTopology()

std::string eduart::ring::SensorRingFactory::printTopology ( ) const

Format the latest enumeration results as a human-readable topology string.

Returns
Formatted topology string. Empty if no enumeration has been performed.

◆ setDefaultDeviceParams()

void eduart::ring::SensorRingFactory::setDefaultDeviceParams ( DeviceParamsVariant params)

Set default params applied to every device of the given type that has no explicit params from expectBoard().

May be called multiple times for different device types.


The documentation for this class was generated from the following file: