nrfcxx  0.1.0
C++-17 Framework for Nordic nRF5 Devices
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
nrfcxx::sensor::sht21 Class Reference

Abstraction around SHT21/HTU21D temperature/humidity sensor. More...

#include <nrfcxx/sensor/sht21.hpp>

Inheritance diagram for nrfcxx::sensor::sht21:
nrfcxx::lpm::lpsm_capable

Data Structures

struct  iface_config_type
 Information required to communicate with a sensor instance. More...
 
struct  observations_type
 Storage for cached results. More...
 

Public Types

using eic_type = uint8_t[8]
 Storage for the Electronic Identification Code.
 

Public Member Functions

const iface_config_typeiface_config () const
 Access the interface configuration for the sensor.
 
 sht21 (notifier_type setter, iface_config_type &ifc)
 Construct a sensor interface around a TWI device and events.
 
 sht21 (const sht21 &)=delete
 
sht21operator= (const sht21 &)=delete
 
 sht21 (sht21 &&)=delete
 
sht21operator= (sht21 &)=delete
 
int reset ()
 Send a soft-reset command to the SHT21. More...
 
int configure (int config)
 Configure resolution and heater. More...
 
int read_eic (eic_type &eic)
 Read the Electronic Identification Code from the device. More...
 
int trigger_temperature ()
 Initiate a temperature measurement. More...
 
int trigger_humidity ()
 Initiate a temperature measurement. More...
 
int temperature_cK ()
 Retrieve the last measurement as a temperature measurement. More...
 
int humidity_pptt ()
 Retrieve the last measurement as a humidity measurement. More...
 
const observations_typeobservations () const
 Retrieve the most recent observations calculated through the LPM infrastructure.
 
- Public Member Functions inherited from nrfcxx::lpm::lpsm_capable
virtual int lpsm_start ()
 Validate and prepare to initiate an LPM collection. More...
 
virtual int lpsm_sample ()
 Ask the LPM infrastructure to initiate a new sample. More...
 
lpm::state_machine::process_flags_type lpsm_process ()
 Make progress on an LPM collection. More...
 
int lpsm_stop ()
 
int lpsm_reset ()
 
int lpsm_process_rc () const
 Get the internal result code from the last invocation of lpsm_process_(). More...
 
const lpm::state_machinemachine () const
 Gain read-only access to the LPM machine state.
 

Static Public Member Functions

static bool eic_is_sht21 (const eic_type &eic)
 Return true iff the eic indicates a Sensirion SHT21 device.
 
static bool eic_is_htu21d (const eic_type &eic)
 Return true iff the eic indicates a Measurement Specialties HTU21D device.
 

Static Public Attributes

constexpr static unsigned int RESET_DELAY_ms = 15
 The maximum time required by the sensor to stabilize after reset(), in milliseconds.
 
constexpr static unsigned int SAMPLE14_DELAY_ms = 85
 The maximum time required for a 14-bit measurement, in milliseconds. More...
 
constexpr static unsigned int SAMPLE12_DELAY_ms = 22
 The maximum time required for a 12-bit measurement, in milliseconds. More...
 
constexpr static uint8_t CONFIG_RES_H12T14 = 0x00
 Bits for parameter to configure() specifying 12-bit humidity and 14-bit temperature measurements.
 
constexpr static uint8_t CONFIG_RES_H8T12 = 0x01
 Bits for parameter to configure() specifying 8-bit humidity and 12-bit temperature measurements.
 
constexpr static uint8_t CONFIG_RES_H10T13 = 0x80
 Bits for parameter to configure() specifying 10-bit humidity and 13-bit temperature measurements.
 
constexpr static uint8_t CONFIG_RES_H11T11 = 0x81
 Bits for parameter to configure() specifying for 11-bit humidity and 11-bit temperature measurements.
 
constexpr static uint8_t CONFIG_RES_Msk = 0x81
 Mask to isolate the bits of the SHT21 user register that identify sampling resolution.
 
constexpr static uint8_t CONFIG_OTPRn = 0x02
 Bit set in configure() parameter/result to disable configuration reset on each measurement.
 
constexpr static uint8_t CONFIG_HEATER = 0x04
 Bit set in configure() parameter/result to enable the on-chip heater.
 
constexpr static uint8_t CONFIG_EOB = 0x40
 Bit set in configure() result indicating Vdd is below 2.25V.
 
constexpr static int INVALID_OBSERVATION = -30000
 Value for observations that are known to be invalid. More...
 
constexpr static int NOT_READY = periph::TWI::error_encoded(periph::TWI::ERR_ANACK)
 The error code returned from temperature_cK() and humidity_pptt() when the device is still processing a measurement.
 

Protected Member Functions

int lpsm_process_ (int &delay, process_flags_type &pf) override
 
int trigger_ (bool humidity)
 
int fetch_ (bool humidity)
 Fetch the latest result as a raw value. More...
 
- Protected Member Functions inherited from nrfcxx::lpm::lpsm_capable
 lpsm_capable (notifier_type notify)
 Create a state machine that records state and supports delayed transitions. More...
 
virtual int lpsm_process_ (int &delay, process_flags_type &pf)
 Override to implement machine-specific operations of lpsm_process(). More...
 
virtual void lpsm_reset_ ()
 Override to reset state that is held outside the machine.
 

Protected Attributes

iface_config_typeiface_config_
 
observations_type observations_
 
- Protected Attributes inherited from nrfcxx::lpm::lpsm_capable
state_machine machine_
 

Additional Inherited Members

- Protected Types inherited from nrfcxx::lpm::lpsm_capable
using state_type = state_machine::state_type
 
using process_flags_type = state_machine::process_flags_type
 

Detailed Description

Abstraction around SHT21/HTU21D temperature/humidity sensor.

Interface to the Sensirion SHT21 Digital Humidity Sensor or the Measurement Specialties HTU21D clone.

lpm::lpsm_capable::lpsm_process() for this sensor returns the following flags in addition to the diagnostic flags:

Member Function Documentation

◆ configure()

int nrfcxx::sensor::sht21::configure ( int  config)

Configure resolution and heater.

Parameters
configA nonnegative configuration byte comprising a resolution setting (e.g. CONFIG_RES_H12T14) and optionally CONFIG_HEATER, or a negative value to query the current configuration without changing it.
Returns
The non-negative content of the configuration register prior to invoking this function, or a negative encoded error.
Note
CONFIG_OTPRn is unconditionally set in any non-negative config value.

◆ fetch_()

int nrfcxx::sensor::sht21::fetch_ ( bool  humidity)
protected

Fetch the latest result as a raw value.

NOT_READY indicates that the collection is still in progress.

The caller is responsible for ensuring that humidity is consistent with the previous invocation of trigger_().

◆ humidity_pptt()

int nrfcxx::sensor::sht21::humidity_pptt ( )
inline

Retrieve the last measurement as a humidity measurement.

Returns
the non-negative relative humidity in parts-per-ten-thousand, or a negative error code such as NOT_READY or an encoded TWI error or TWI::ERR_INVALID if the last measurement was not humidity.

◆ read_eic()

int nrfcxx::sensor::sht21::read_eic ( eic_type eic)

Read the Electronic Identification Code from the device.

Parameters
eicStorage for the EIC, which is device-specific and can also be used to distinguish Sensirion SHT21 from HTU21D devices.

◆ reset()

int nrfcxx::sensor::sht21::reset ( )

Send a soft-reset command to the SHT21.

If successful this is equivalent to a power-on reset except that the CONFIG_HEATER bit remains unaffected.

Returns
a non-negative value on success, or a negative encoded error.

◆ temperature_cK()

int nrfcxx::sensor::sht21::temperature_cK ( )
inline

Retrieve the last measurement as a temperature measurement.

Returns
the non-negative temperature in hundredths of a degree Kelvin, or a negative error code such as NOT_READY or an encoded TWI error or TWI::ERR_INVALID if the last measurement was not temperature.

◆ trigger_humidity()

int nrfcxx::sensor::sht21::trigger_humidity ( )
inline

Initiate a temperature measurement.

The time required for completion of the measurement is device- and resolution-specific, but may be as long as 29 ms.

Returns
Zero on success, or anegative encoded error.

◆ trigger_temperature()

int nrfcxx::sensor::sht21::trigger_temperature ( )
inline

Initiate a temperature measurement.

The time required for completion of the measurement is device- and resolution-specific, but may be as long as 85 ms.

Returns
Zero on success, or a negative encoded error.

Field Documentation

◆ INVALID_OBSERVATION

constexpr static int nrfcxx::sensor::sht21::INVALID_OBSERVATION = -30000
staticconstexpr

Value for observations that are known to be invalid.

This fits in a 16-bit signed value and is outside the valid range for both temperature_cK() and humidity_pptt().

◆ SAMPLE12_DELAY_ms

constexpr static unsigned int nrfcxx::sensor::sht21::SAMPLE12_DELAY_ms = 22
staticconstexpr

The maximum time required for a 12-bit measurement, in milliseconds.

This is for a SHT21; the HTU21D is about 25% faster.

◆ SAMPLE14_DELAY_ms

constexpr static unsigned int nrfcxx::sensor::sht21::SAMPLE14_DELAY_ms = 85
staticconstexpr

The maximum time required for a 14-bit measurement, in milliseconds.

This is for a SHT21; the HTU21D is about 30% faster.


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