SFM Flow Meter Driver 1.0.0
API reference
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
sfm::Driver< I2cT > Class Template Reference

SF06 flow-meter client. More...

#include <sfm_driver.hpp>

Public Member Functions

 Driver (I2cT &i2c, uint8_t address=addr::kSfm4300Default, Family family=Family::Sf06) noexcept
 
uint8_t Address () const noexcept
 
void SetAddress (uint8_t address) noexcept
 
Variant KnownVariant () const noexcept
 Variant learned from the last successful ReadProductIdentifier().
 
void AssumeVariant (Variant v) noexcept
 Let the caller assert a variant when the identifier cannot be read (already measuring).
 
Family PartFamily () const noexcept
 Family in use (from the identifier, AssumeVariant, or the constructor).
 
Gas ActiveGas () const noexcept
 Gas selected by the last successful StartContinuous().
 
bool Measuring () const noexcept
 
const Scaling & ActiveScaling () const noexcept
 Scaling captured for the active gas.
 
DriverResult< ProductInfo > ReadProductIdentifier () noexcept
 Read product identifier and serial number (§4.3.9).
 
DriverResult< Scaling > ReadScaleOffsetUnit (Gas g) noexcept
 Query scale factor, offset and unit for a gas table (§4.3.6).
 
DriverResult< void > StartContinuous (Gas g, uint16_t o2_permille=0) noexcept
 Start continuous measurement for g (§4.3.1).
 
DriverResult< void > Stop () noexcept
 Stop continuous measurement → idle (§4.3.4).
 
DriverResult< Measurement > ReadMeasurement () noexcept
 Read one flow / temperature / status frame (§4.3.1).
 
DriverResult< float > ReadTemperature () noexcept
 SFx6000: read the flow-chip temperature while measuring (pointer 0xE102 → one word → pointer back to results 0xE000).
 
DriverResult< float > ReadFlowOnly () noexcept
 Flow-only read (2 words + CRC) for the tightest loop; status not refreshed.
 
DriverResult< void > ConfigureAveraging (uint16_t window) noexcept
 Configure on-sensor averaging (§4.3.5).
 
DriverResult< void > UpdateConcentration (uint16_t o2_permille) noexcept
 Update the O2 fraction of a running mixture measurement (§4.3.3).
 
DriverResult< void > EnterSleep () noexcept
 Enter sleep (idle mode only, §4.3.8).
 
DriverResult< void > ExitSleep () noexcept
 Exit sleep: any write header wakes the part; it does not ACK (§4.3.8). Polls up to ~20 ms until the address is acknowledged again.
 
DriverResult< void > SoftReset () noexcept
 I2C general-call soft reset (§4.3.7): 0x06 to address 0x00, then ~20 ms.
 

Static Public Member Functions

static DriverResult< Measurement > DecodeMeasurement (Family family, const Scaling &scaling, const uint8_t frame[9]) noexcept
 Decode one 9-byte continuous-mode frame (3 × word + CRC).
 
static void EncodeWord (uint16_t word, uint8_t out[3]) noexcept
 Encode a 16-bit word + CRC-8 into 3 bytes.
 
static DriverError DecodeWords (const uint8_t *in, std::size_t count, uint16_t *out) noexcept
 Decode count (word, crc) triplets; returns Crc on the first mismatch.
 

Detailed Description

template<typename I2cT>
class sfm::Driver< I2cT >

SF06 flow-meter client.

Template Parameters
I2cTConcrete type inheriting I2cInterface<I2cT>.

Constructor & Destructor Documentation

◆ Driver()

template<typename I2cT >
sfm::Driver< I2cT >::Driver ( I2cT &  i2c,
uint8_t  address = addr::kSfm4300Default,
Family  family = Family::Sf06 
)
inlineexplicitnoexcept
Parameters
i2cTransport adapter (must outlive the driver).
address7-bit device address (default SFM4300 0x2A).
familyFamily assumed until the product identifier is read.

Member Function Documentation

◆ ActiveGas()

template<typename I2cT >
Gas sfm::Driver< I2cT >::ActiveGas ( ) const
inlinenoexcept

Gas selected by the last successful StartContinuous().

◆ ActiveScaling()

template<typename I2cT >
const Scaling & sfm::Driver< I2cT >::ActiveScaling ( ) const
inlinenoexcept

Scaling captured for the active gas.

◆ Address()

template<typename I2cT >
uint8_t sfm::Driver< I2cT >::Address ( ) const
inlinenoexcept

◆ AssumeVariant()

template<typename I2cT >
void sfm::Driver< I2cT >::AssumeVariant ( Variant  v)
inlinenoexcept

Let the caller assert a variant when the identifier cannot be read (already measuring).

◆ ConfigureAveraging()

template<typename I2cT >
DriverResult< void > sfm::Driver< I2cT >::ConfigureAveraging ( uint16_t  window)
inlinenoexcept

Configure on-sensor averaging (§4.3.5).

Parameters
window0 = average-until-read (default), 1…128 = fixed-N.

◆ DecodeMeasurement()

template<typename I2cT >
static DriverResult< Measurement > sfm::Driver< I2cT >::DecodeMeasurement ( Family  family,
const Scaling &  scaling,
const uint8_t  frame[9] 
)
inlinestaticnoexcept

Decode one 9-byte continuous-mode frame (3 × word + CRC).

Pure: the same decode serves the blocking read above and an interrupt / DMA reader that fetched the frame itself. SF06: flow, temperature, status. SFx6000: flow, reserved, status (temperature through ReadTemperature()).

◆ DecodeWords()

template<typename I2cT >
static DriverError sfm::Driver< I2cT >::DecodeWords ( const uint8_t *  in,
std::size_t  count,
uint16_t *  out 
)
inlinestaticnoexcept

Decode count (word, crc) triplets; returns Crc on the first mismatch.

◆ EncodeWord()

template<typename I2cT >
static void sfm::Driver< I2cT >::EncodeWord ( uint16_t  word,
uint8_t  out[3] 
)
inlinestaticnoexcept

Encode a 16-bit word + CRC-8 into 3 bytes.

◆ EnterSleep()

template<typename I2cT >
DriverResult< void > sfm::Driver< I2cT >::EnterSleep ( )
inlinenoexcept

Enter sleep (idle mode only, §4.3.8).

◆ ExitSleep()

template<typename I2cT >
DriverResult< void > sfm::Driver< I2cT >::ExitSleep ( )
inlinenoexcept

Exit sleep: any write header wakes the part; it does not ACK (§4.3.8). Polls up to ~20 ms until the address is acknowledged again.

◆ KnownVariant()

template<typename I2cT >
Variant sfm::Driver< I2cT >::KnownVariant ( ) const
inlinenoexcept

Variant learned from the last successful ReadProductIdentifier().

◆ Measuring()

template<typename I2cT >
bool sfm::Driver< I2cT >::Measuring ( ) const
inlinenoexcept

◆ PartFamily()

template<typename I2cT >
Family sfm::Driver< I2cT >::PartFamily ( ) const
inlinenoexcept

Family in use (from the identifier, AssumeVariant, or the constructor).

◆ ReadFlowOnly()

template<typename I2cT >
DriverResult< float > sfm::Driver< I2cT >::ReadFlowOnly ( )
inlinenoexcept

Flow-only read (2 words + CRC) for the tightest loop; status not refreshed.

◆ ReadMeasurement()

template<typename I2cT >
DriverResult< Measurement > sfm::Driver< I2cT >::ReadMeasurement ( )
inlinenoexcept

Read one flow / temperature / status frame (§4.3.1).

Requires a running continuous measurement. A NACK on the read header (no fresh sample yet, or idle) is reported as DriverError::NoData.

◆ ReadProductIdentifier()

template<typename I2cT >
DriverResult< ProductInfo > sfm::Driver< I2cT >::ReadProductIdentifier ( )
inlinenoexcept

Read product identifier and serial number (§4.3.9).

Note
Idle mode only — call before StartContinuous() or after Stop().

◆ ReadScaleOffsetUnit()

template<typename I2cT >
DriverResult< Scaling > sfm::Driver< I2cT >::ReadScaleOffsetUnit ( Gas  g)
inlinenoexcept

Query scale factor, offset and unit for a gas table (§4.3.6).

Parameters
gGas selector whose start command is passed as the argument.

◆ ReadTemperature()

template<typename I2cT >
DriverResult< float > sfm::Driver< I2cT >::ReadTemperature ( )
inlinenoexcept

SFx6000: read the flow-chip temperature while measuring (pointer 0xE102 → one word → pointer back to results 0xE000).

Returns
NotSupported on SF06 (temperature is in every frame).

◆ SetAddress()

template<typename I2cT >
void sfm::Driver< I2cT >::SetAddress ( uint8_t  address)
inlinenoexcept

◆ SoftReset()

template<typename I2cT >
DriverResult< void > sfm::Driver< I2cT >::SoftReset ( )
inlinenoexcept

I2C general-call soft reset (§4.3.7): 0x06 to address 0x00, then ~20 ms.

Returns
NotSupported when the transport has no general-call write.

◆ StartContinuous()

template<typename I2cT >
DriverResult< void > sfm::Driver< I2cT >::StartContinuous ( Gas  g,
uint16_t  o2_permille = 0 
)
inlinenoexcept

Start continuous measurement for g (§4.3.1).

Reads the gas table scaling first (so ReadMeasurement() can convert), refuses gases the known variant does not calibrate, refuses a scaling reply it cannot use (UnexpectedUnit: scale 0, or a unit other than 0x0148 on a known SF06 part), then issues the start command and waits timing::kFirstResultAfterStartMs. If this driver started a measurement that is still running (Measuring()), it sends Stop() first: the sensor takes no other command while measuring (§4.3.4), so switching gas needs stop, 0.5 ms, query, start.

Parameters
gGas or mixture.
o2_permilleO2 volume fraction for mixtures (ignored for pure gases).

◆ Stop()

template<typename I2cT >
DriverResult< void > sfm::Driver< I2cT >::Stop ( )
inlinenoexcept

Stop continuous measurement → idle (§4.3.4).

Waits timing::kStopToIdleMs after the command: the sensor needs up to 0.5 ms to enter idle mode before the next command.

◆ UpdateConcentration()

template<typename I2cT >
DriverResult< void > sfm::Driver< I2cT >::UpdateConcentration ( uint16_t  o2_permille)
inlinenoexcept

Update the O2 fraction of a running mixture measurement (§4.3.3).

Parameters
o2_permilleNew O2 volume fraction (‰).

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