SFM_FLOW_METER Driver 0.1.0
API reference
Loading...
Searching...
No Matches
Public Member Functions | List of all members
sfm::SfmFlowMeter< Port, FamilyMask > Class Template Reference

The driver. More...

#include <sfm_flow_meter.hpp>

Public Member Functions

 SfmFlowMeter (Port &port, const Config &config=Config{}) noexcept
 Bind a port and a configuration. No bus traffic.
 
 SfmFlowMeter (const SfmFlowMeter &)=delete
 The driver is not copied: it holds a reference to the port.
 
SfmFlowMeter & operator= (const SfmFlowMeter &)=delete
 The driver is not copied.
 
Lifecycle
Result< Wait > BeginInitialize () noexcept
 Start identification: wake the sensor, check the product identifier (or serial number), set the averaging. Returns the first wait; finish with Poll() or AwaitPending().
 
Result< void > EnsureInitialized () noexcept
 BeginInitialize() and AwaitPending(): blocking, needs the port's DelayUs().
 
Result< void > Deinitialize () noexcept
 Forget the initialisation. No bus traffic: call Stop() first if the sensor measures.
 
Operations that may wait
Result< Wait > StartMeasurement (Gas gas, uint16_t o2_permille=0) noexcept
 Start a measurement of a gas or gas mixture; reads and checks the part's scaling first.
 
Result< Wait > Stop () noexcept
 Stop the measurement. A no-op when idle. Failure leaves StateUnknown.
 
Result< Wait > SetAveraging (uint16_t n) noexcept
 Set the averaging while idle.
 
Result< Wait > ReadScaling (Gas gas) noexcept
 Read and check the sensor's scaling of a gas while idle; see GetScaling().
 
Result< Wait > Sleep () noexcept
 Enter sleep mode (idle only). Failure leaves StateUnknown.
 
Result< Wait > WakeUp () noexcept
 Wake from sleep and write the averaging again.
 
Result< Wait > SoftReset () noexcept
 Reset by the part's soft-reset command (the general call needs allow_general_call_reset). Afterwards the driver is Uninitialized: call EnsureInitialized() again.
 
Result< Wait > HardReset () noexcept
 Reset by the /RES pin (SFM4200) or by cycling the supply; needs the port hook.
 
Result< Wait > UpdateConcentration (uint16_t o2_permille) noexcept
 Change the oxygen fraction of a running mixture (no read in between).
 
Result< Wait > Poll (uint32_t elapsed_us) noexcept
 Continue a pending operation after the wait it returned.
 
Result< Wait > Poll () noexcept
 Poll() using the port's NowUs(); without a clock the whole wait counts as elapsed.
 
Result< void > AwaitPending () noexcept
 Wait with DelayUs() until no operation is pending. Needs the port's DelayUs().
 
Measurement
Result< Sample > ReadSample () noexcept
 Read one sample of the running measurement.
 
Result< RawReply > ReadRawReply () noexcept
 One raw read of the running measurement: the CRC-checked words, with no decoding, no status check and no range check. The single-shot raw access for bring-up and diagnostics; GetLastReply() returns it again without I/O. A failed read does not count towards the SF05 error limit, and a silent sensor is never reported here (NoData for ever): only ReadSample() reports DeviceReset.
 
Result< Wait > ReadTemperature () noexcept
 Read the sensor temperature by a pointer sequence while measuring (parts that offer it); the SF05 family needs 5 ms between the pointer and the read, so this returns a wait. The value is GetTemperature() once the operation ended without an error.
 
State
State GetState () const noexcept
 
bool HasPending () const noexcept
 
const ProductInfo & GetProductInfo () const noexcept
 
int32_t GetTemperature () const noexcept
 
const RawReply & GetLastReply () const noexcept
 
const ScalingInfo & GetScaling () const noexcept
 
const Stats & GetStats () const noexcept
 
const Config & GetConfig () const noexcept
 
const PartInfo * GetPart () const noexcept
 
Capabilities GetCapabilities () const noexcept
 
uint8_t GetAddress () const noexcept
 

Detailed Description

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
class sfm::SfmFlowMeter< Port, FamilyMask >

The driver.

Template Parameters
PortYour port class, derived from I2cInterface<Port>.
FamilyMaskThe protocol families the object may drive (kFamilySf06 | ...); a configuration outside the mask is Unsupported. The default is every family.

Constructor & Destructor Documentation

◆ SfmFlowMeter()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
sfm::SfmFlowMeter< Port, FamilyMask >::SfmFlowMeter ( Port &  port,
const Config &  config = Config{} 
)
inlineexplicitnoexcept

Bind a port and a configuration. No bus traffic.

Parameters
portThe platform port; it must outlive the driver.
configThe configuration; checked by EnsureInitialized() and Validate().

Member Function Documentation

◆ AwaitPending()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< void > sfm::SfmFlowMeter< Port, FamilyMask >::AwaitPending ( )
noexcept

Wait with DelayUs() until no operation is pending. Needs the port's DelayUs().

Returns
Ok, the operation's error, or Timeout after an implausible number of rounds.

◆ BeginInitialize()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< Wait > sfm::SfmFlowMeter< Port, FamilyMask >::BeginInitialize ( )
noexcept

Start identification: wake the sensor, check the product identifier (or serial number), set the averaging. Returns the first wait; finish with Poll() or AwaitPending().

Returns
The wait (0 when done), InvalidArgument, Unsupported, Bus (the port could not bring the bus up), Busy, or a plan error: NoDevice, Crc, DeviceIdMismatch, InvalidReply.

◆ Deinitialize()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< void > sfm::SfmFlowMeter< Port, FamilyMask >::Deinitialize ( )
noexcept

Forget the initialisation. No bus traffic: call Stop() first if the sensor measures.

Returns
Ok.

◆ EnsureInitialized()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< void > sfm::SfmFlowMeter< Port, FamilyMask >::EnsureInitialized ( )
noexcept

BeginInitialize() and AwaitPending(): blocking, needs the port's DelayUs().

Returns
Ok, or the error of either call. Returns at once when already initialised.

◆ GetAddress()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
uint8_t sfm::SfmFlowMeter< Port, FamilyMask >::GetAddress ( ) const
inlinenoexcept
Returns
The 7-bit address in use.

◆ GetCapabilities()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Capabilities sfm::SfmFlowMeter< Port, FamilyMask >::GetCapabilities ( ) const
inlinenoexcept
Returns
The part's capabilities (all false without a part).

◆ GetConfig()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
const Config & sfm::SfmFlowMeter< Port, FamilyMask >::GetConfig ( ) const
inlinenoexcept
Returns
The configuration.

◆ GetLastReply()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
const RawReply & sfm::SfmFlowMeter< Port, FamilyMask >::GetLastReply ( ) const
inlinenoexcept
Returns
The CRC-valid words of the last frame read by ReadSample() or ReadRawReply(); empty before. No I/O.

◆ GetPart()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
const PartInfo * sfm::SfmFlowMeter< Port, FamilyMask >::GetPart ( ) const
inlinenoexcept
Returns
The part's table row; the family's first row for Auto before identification; may be null.

◆ GetProductInfo()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
const ProductInfo & sfm::SfmFlowMeter< Port, FamilyMask >::GetProductInfo ( ) const
inlinenoexcept
Returns
What identification read; zeros before. No I/O.

◆ GetScaling()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
const ScalingInfo & sfm::SfmFlowMeter< Port, FamilyMask >::GetScaling ( ) const
inlinenoexcept
Returns
What the last scale read returned. No I/O.

◆ GetState()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
State sfm::SfmFlowMeter< Port, FamilyMask >::GetState ( ) const
inlinenoexcept
Returns
The driver's shadow of the chip's mode. No I/O.

◆ GetStats()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
const Stats & sfm::SfmFlowMeter< Port, FamilyMask >::GetStats ( ) const
inlinenoexcept
Returns
The counters. No I/O.

◆ GetTemperature()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
int32_t sfm::SfmFlowMeter< Port, FamilyMask >::GetTemperature ( ) const
inlinenoexcept
Returns
The last temperature ReadTemperature() decoded, in milli-degrees C; 0 before and after a failed call. No I/O.

◆ HardReset()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< Wait > sfm::SfmFlowMeter< Port, FamilyMask >::HardReset ( )
noexcept

Reset by the /RES pin (SFM4200) or by cycling the supply; needs the port hook.

Returns
The wait (0 when done), Unsupported, Busy, or a plan error.

◆ HasPending()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
bool sfm::SfmFlowMeter< Port, FamilyMask >::HasPending ( ) const
inlinenoexcept
Returns
Whether an operation waits for Poll().

◆ Poll() [1/2]

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< Wait > sfm::SfmFlowMeter< Port, FamilyMask >::Poll ( )
noexcept

Poll() using the port's NowUs(); without a clock the whole wait counts as elapsed.

Returns
As Poll(uint32_t).

◆ Poll() [2/2]

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< Wait > sfm::SfmFlowMeter< Port, FamilyMask >::Poll ( uint32_t  elapsed_us)
noexcept

Continue a pending operation after the wait it returned.

Parameters
elapsed_usHow long you waited; less than the wait returns the remainder.
Returns
The next wait (0 when done) or the operation's error.

◆ ReadRawReply()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< RawReply > sfm::SfmFlowMeter< Port, FamilyMask >::ReadRawReply ( )
noexcept

One raw read of the running measurement: the CRC-checked words, with no decoding, no status check and no range check. The single-shot raw access for bring-up and diagnostics; GetLastReply() returns it again without I/O. A failed read does not count towards the SF05 error limit, and a silent sensor is never reported here (NoData for ever): only ReadSample() reports DeviceReset.

Returns
The words, or NotInitialized, Busy, StateUnknown, NoData, Crc, InvalidReply, Bus, Timeout.

◆ ReadSample()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< Sample > sfm::SfmFlowMeter< Port, FamilyMask >::ReadSample ( )
noexcept

Read one sample of the running measurement.

Returns
The sample, or NotInitialized, Busy, StateUnknown, NoData (nothing new yet), Crc, InvalidReply, StatusMismatch, OutOfRange, Stale, DeviceReset, NoDevice, Bus, Timeout (SFM4100 stretch).

◆ ReadScaling()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< Wait > sfm::SfmFlowMeter< Port, FamilyMask >::ReadScaling ( Gas  gas)
noexcept

Read and check the sensor's scaling of a gas while idle; see GetScaling().

Parameters
gasA gas of the part's table row.
Returns
The wait (0 when done), Unsupported, InvalidArgument, Crc, DeviceFault, or a plan error.

◆ ReadTemperature()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< Wait > sfm::SfmFlowMeter< Port, FamilyMask >::ReadTemperature ( )
noexcept

Read the sensor temperature by a pointer sequence while measuring (parts that offer it); the SF05 family needs 5 ms between the pointer and the read, so this returns a wait. The value is GetTemperature() once the operation ended without an error.

Returns
The wait (0 when done), Unsupported, Busy, NotInitialized, StateUnknown, Bus, Crc. A failure after the pointer moved leaves StateUnknown.

◆ SetAveraging()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< Wait > sfm::SfmFlowMeter< Port, FamilyMask >::SetAveraging ( uint16_t  n)
noexcept

Set the averaging while idle.

Parameters
n0 for average-until-read where offered, 1 to 128, or kAveragingDefault.
Returns
The wait (0 when done), Unsupported, InvalidArgument, Busy, or a plan error.

◆ Sleep()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< Wait > sfm::SfmFlowMeter< Port, FamilyMask >::Sleep ( )
noexcept

Enter sleep mode (idle only). Failure leaves StateUnknown.

Returns
The wait (0 when done), Unsupported, Busy, or a plan error.

◆ SoftReset()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< Wait > sfm::SfmFlowMeter< Port, FamilyMask >::SoftReset ( )
noexcept

Reset by the part's soft-reset command (the general call needs allow_general_call_reset). Afterwards the driver is Uninitialized: call EnsureInitialized() again.

Returns
The wait (0 when done), Unsupported, Busy, or a plan error.

◆ StartMeasurement()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< Wait > sfm::SfmFlowMeter< Port, FamilyMask >::StartMeasurement ( Gas  gas,
uint16_t  o2_permille = 0 
)
noexcept

Start a measurement of a gas or gas mixture; reads and checks the part's scaling first.

Parameters
gasA gas of the part's table row.
o2_permilleMixtures: the oxygen fraction, 0 to 1000; 0 otherwise.
Returns
The wait until the first sample (0 when none), NotInitialized, Busy, StateUnknown, InvalidArgument, DeviceFault (scaling differs), or a plan error.

◆ Stop()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< Wait > sfm::SfmFlowMeter< Port, FamilyMask >::Stop ( )
noexcept

Stop the measurement. A no-op when idle. Failure leaves StateUnknown.

Returns
The wait (0 when done), NotInitialized, Busy, StateUnknown, or a plan error.

◆ UpdateConcentration()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< Wait > sfm::SfmFlowMeter< Port, FamilyMask >::UpdateConcentration ( uint16_t  o2_permille)
noexcept

Change the oxygen fraction of a running mixture (no read in between).

Parameters
o2_permilleThe new fraction, 0 to 1000.
Returns
The wait (0 when done), Unsupported, InvalidArgument, Busy, or a plan error.

◆ WakeUp()

template<I2cPort Port, uint32_t FamilyMask = kAllFamilies>
Result< Wait > sfm::SfmFlowMeter< Port, FamilyMask >::WakeUp ( )
noexcept

Wake from sleep and write the averaging again.

Returns
The wait (0 when done), Busy, Timeout (the sensor stays asleep), or a plan error.

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