Embedded Artistry Framework
Embedded Systems C++ Framework
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
embvm::tof::sensor Class Referenceabstract

This class defines common time-of-flight (ToF) sensor interfaces. More...

#include <time_of_flight.hpp>

Inheritance diagram for embvm::tof::sensor:
Inheritance graph

Public Types

using read_cb_t = stdext::inplace_function< void(uint16_t)>
 ToF Callback function which retuns distance in mm. More...
 

Public Member Functions

virtual tof::distance_t getMaxRangeForModeDark (tof::mode m) const noexcept=0
 Check the maximum range in the dark. More...
 
virtual tof::distance_t getMaxRangeForModeStrongLight (tof::mode m) const noexcept=0
 Check the maximum range in strong light conditions. More...
 
tof::mode mode () const noexcept
 Get the ToF ranging mode. More...
 
virtual tof::mode mode (tof::mode m) noexcept=0
 Set the ToF ranging mode. More...
 
virtual void registerReadCallback (const read_cb_t &cb) noexcept=0
 Register a callback for the read() function. More...
 
virtual void registerReadCallback (read_cb_t &&cb) noexcept=0
 Register a callback for the read() function. More...
 
virtual void read () noexcept=0
 Trigger a sensor read. More...
 
virtual void reset () noexcept=0
 Reset the ToF sensor. More...
 
void start () noexcept
 Start the driver. More...
 
void stop () noexcept
 Stop the driver. More...
 
void restart () noexcept
 Restart the driver. More...
 
type_safe::boolean started () const noexcept
 Check if the driver has been started. More...
 
constexpr embvm::DriverType_t DriverType () const noexcept
 Returns the registered type ID of the driver. More...
 
constexpr const std::string_view & name () const noexcept
 Provides a string_view reference of the driver name. More...
 
constexpr const char * name_cstr () const noexcept
 Provides a c-string version of the driver name. More...
 
virtual DriverBaseoperator++ () noexcept
 Increment operator is a no-op, but is used for iterator compatibility. More...
 

Static Public Member Functions

static constexpr embvm::DriverType type () noexcept
 ToF Driver Type ID. More...
 

Protected Member Functions

 sensor () noexcept
 Default constructor. More...
 
 sensor (const char *name) noexcept
 Construct an tof::sensor with a C-string name. More...
 
 sensor (const std::string &name) noexcept
 Construct an tof::sensor with a std::string name. More...
 
 sensor (const std::string_view &name) noexcept
 Construct an tof::sensor with a std::string_view name. More...
 
 ~sensor () noexcept override
 Default destructor. More...
 
void start_ () noexcept override=0
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 
void stop_ () noexcept override=0
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 

Protected Attributes

tof::mode mode_ = tof::mode::defaultRange
 The configured ranging mode for the ToF sensor. More...
 
type_safe::boolean started_ = false
 Tracks the driver state. More...
 
const std::string_view name_
 Name of the driver instance. More...
 
const embvm::DriverType_t type_
 Type ID of the driver instance. More...
 

Detailed Description

This class defines common time-of-flight (ToF) sensor interfaces.

tof::sensor is the base class for time-of-flight (ToF) sensor devices.

Define a ToF Driver

To define a ToF driver, derive from the tof::sensor object:

class vl53l1x final : public tof::sensor
{ ... };

Derived classes must implement the following functions:

Additional sensor-specific functions may be defined. They are simply not available in the public/common interface.

Derived classes must also implement pure virtual embvm::DriverBase functions:

Using a ToF driver

The ToF driver should be configured with the desired ranging mode (tof::mode) using the mode() function.

Once the sensor is configured, a callback should be registered via registerReadCallback(). The callback is required in order to receive results from the read() command.

To get a range result from the sensor, call the read() function. The function operates asynchronously and will return immediately. When the read operation completes, registered callbacks will be called.

Member Typedef Documentation

◆ read_cb_t

using embvm::tof::sensor::read_cb_t = stdext::inplace_function<void(uint16_t)>

ToF Callback function which retuns distance in mm.

Constructor & Destructor Documentation

◆ sensor() [1/4]

embvm::tof::sensor::sensor ( )
inlineprotectednoexcept

Default constructor.

Initializes the tof::sensor instance with a generic name.

◆ sensor() [2/4]

embvm::tof::sensor::sensor ( const char *  name)
inlineprotectednoexcept

Construct an tof::sensor with a C-string name.

Initializes the tof::sensor instance with a name.

Parameters
nameThe name of the ToF instance.

◆ sensor() [3/4]

embvm::tof::sensor::sensor ( const std::string &  name)
inlineprotectednoexcept

Construct an tof::sensor with a std::string name.

Initializes the tof::sensor instance with a name.

Parameters
nameThe name of the ToF instance. tof::sensor() uses a std::string_view, so the std::string must remain valid

◆ sensor() [4/4]

embvm::tof::sensor::sensor ( const std::string_view &  name)
inlineprotectednoexcept

Construct an tof::sensor with a std::string_view name.

Initializes the tof::sensor instance with a name.

Parameters
nameThe name of the ToF instance.

◆ ~sensor()

embvm::tof::sensor::~sensor ( )
overrideprotecteddefaultnoexcept

Default destructor.

Member Function Documentation

◆ DriverType()

constexpr embvm::DriverType_t embvm::DriverBase::DriverType ( ) const
inlinenoexceptinherited

Returns the registered type ID of the driver.

When using DriverBase interfaces, clients can retrieve the registered driver type in order to up-cast to the correct interface.

The type is returned as a embvm::DriverType_t rather than a embvm::DriverType enum to work with custom user-defined types. Enforcing a embvm::DriverType return value would prevent clients from defining and using their own custom types.

Returns
the registered driver type as a embvm::DriverType_t value

References embvm::DriverBase::type_.

◆ getMaxRangeForModeDark()

virtual tof::distance_t embvm::tof::sensor::getMaxRangeForModeDark ( tof::mode  m) const
pure virtualnoexcept

Check the maximum range in the dark.

Returns
the sensor's maximum distance capability (in mm) in the dark.

Implemented in embdrv::vl53l1x.

◆ getMaxRangeForModeStrongLight()

virtual tof::distance_t embvm::tof::sensor::getMaxRangeForModeStrongLight ( tof::mode  m) const
pure virtualnoexcept

Check the maximum range in strong light conditions.

Returns
the sensor's maximum distance capability (in mm) in strong light.

Implemented in embdrv::vl53l1x.

◆ mode() [1/2]

tof::mode embvm::tof::sensor::mode ( ) const
inlinenoexcept

Get the ToF ranging mode.

Returns
the currently configured ToF ranging mode.

References mode_.

◆ mode() [2/2]

virtual tof::mode embvm::tof::sensor::mode ( tof::mode  m)
pure virtualnoexcept

Set the ToF ranging mode.

Parameters
mThe desired ToF ranging mode.
Returns
the active ToF mode.

Implemented in embdrv::vl53l1x.

◆ name()

constexpr const std::string_view& embvm::DriverBase::name ( ) const
inlinenoexceptinherited

Provides a string_view reference of the driver name.

Returns
std::string_view ref containing the driver name.

References embvm::DriverBase::name_.

◆ name_cstr()

constexpr const char* embvm::DriverBase::name_cstr ( ) const
inlinenoexceptinherited

Provides a c-string version of the driver name.

Returns
c-string containing the driver name

References embvm::DriverBase::name_.

◆ operator++()

virtual DriverBase& embvm::DriverBase::operator++ ( )
inlinevirtualnoexceptinherited

Increment operator is a no-op, but is used for iterator compatibility.

◆ read()

virtual void embvm::tof::sensor::read ( )
pure virtualnoexcept

Trigger a sensor read.

Trigger an asynchronous read of the ToF sensor. The result will be provided to consumers through a callback function. When the read() operation completes, the callback will be invoked with the result.

Implemented in embdrv::vl53l1x.

◆ registerReadCallback() [1/2]

virtual void embvm::tof::sensor::registerReadCallback ( const read_cb_t cb)
pure virtualnoexcept

Register a callback for the read() function.

The read() function works asynchronously, and the result will be provided to consumers through a callback function. When the read() operation completes, the callback will be invoked with the result.

This function must be implemented by the derived class.

Parameters
cbThe functor which will be called when read() completes.

Implemented in embdrv::vl53l1x.

Referenced by FrameworkDemoSimPlatform::init_().

◆ registerReadCallback() [2/2]

virtual void embvm::tof::sensor::registerReadCallback ( read_cb_t &&  cb)
pure virtualnoexcept

Register a callback for the read() function.

The read() function works asynchronously, and the result will be provided to consumers through a callback function. When the read() operation completes, the callback will be invoked with the result.

This function must be implemented by the derived class.

Parameters
cbThe functor which will be called when read() completes.

Implemented in embdrv::vl53l1x.

◆ reset()

virtual void embvm::tof::sensor::reset ( )
pure virtualnoexcept

Reset the ToF sensor.

Implemented in embdrv::vl53l1x.

◆ restart()

void embvm::DriverBase::restart ( )
inlinenoexceptinherited

Restart the driver.

Calls stop() and then start() on the driver. If the driver is not started, then it will be started after the start() function is invoked.

References embvm::DriverBase::start(), and embvm::DriverBase::stop().

◆ start()

void embvm::DriverBase::start ( )
inlinenoexceptinherited

◆ start_()

void embvm::tof::sensor::start_ ( )
overrideprotectedpure virtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::DriverBase.

Implemented in embdrv::vl53l1x.

◆ started()

type_safe::boolean embvm::DriverBase::started ( ) const
inlinenoexceptinherited

Check if the driver has been started.

Returns
true if the driver is running (started), false if not running (stopped).

References embvm::DriverBase::started_.

Referenced by embdrv::aardvarkSPIMaster::configure_(), embdrv::aardvarkGPIOInput< 4 >::get(), embdrv::aardvarkGPIOOutput< 5 >::set(), embdrv::vl53l1x::start_(), embdrv::aardvarkAdapter::start_(), and embdrv::aardvarkAdapter::stop_().

◆ stop()

void embvm::DriverBase::stop ( )
inlinenoexceptinherited

◆ stop_()

void embvm::tof::sensor::stop_ ( )
overrideprotectedpure virtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::DriverBase.

Implemented in embdrv::vl53l1x.

◆ type()

static constexpr embvm::DriverType embvm::tof::sensor::type ( )
inlinestaticnoexcept

ToF Driver Type ID.

Returns
ToF type ID.

References embvm::TIME_OF_FLIGHT.

Member Data Documentation

◆ mode_

tof::mode embvm::tof::sensor::mode_ = tof::mode::defaultRange
protected

The configured ranging mode for the ToF sensor.

Referenced by mode().

◆ name_

const std::string_view embvm::DriverBase::name_
protectedinherited

Name of the driver instance.

Referenced by embvm::DriverBase::name(), and embvm::DriverBase::name_cstr().

◆ started_

type_safe::boolean embvm::DriverBase::started_ = false
protectedinherited

Tracks the driver state.

True if the driver has been started, false if it has been stopped or not yet started.

Referenced by embvm::DriverBase::start(), embvm::DriverBase::started(), and embvm::DriverBase::stop().

◆ type_

const embvm::DriverType_t embvm::DriverBase::type_
protectedinherited

Type ID of the driver instance.

Referenced by embvm::DriverBase::DriverType().


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