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

Abstraction around BME280 temperature/humidity/pressure sensor. More...

#include <nrfcxx/sensor/bme280.hpp>

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

Data Structures

struct  observations_type
 Structure used to return sampled values. More...
 

Public Member Functions

 bme280 (notifier_type notify, nrfcxx::periph::SPI &spi, int csn_psel)
 Construct an instance that controls through the SPI interface. More...
 
 bme280 (notifier_type notify, nrfcxx::periph::TWI &twi, bool addr_sec=false)
 Construct an instance that controls through the I2C interface. More...
 
int initialize ()
 Initialize the BME280. More...
 
int sample ()
 Request a new sample from the device. More...
 
int fetch (observations_type &obs)
 Retrieve the results from the most recent observation. 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 Attributes

static constexpr unsigned int SAMPLE_DELAY_utt = clock::uptime::from_ms(10)
 Lower bound for wait after sample() before get_sensor_data(). More...
 
static constexpr uint16_t INVALID_TEMPHUMID = 30000
 Value used for invalid temperature and humidity observations.
 
static constexpr unsigned int INVALID_PRESSURE = 0x00C00000
 Value used for invalid pressure observations. More...
 

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
 
- 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 inherited from nrfcxx::lpm::lpsm_capable
state_machine machine_
 

Detailed Description

Abstraction around BME280 temperature/humidity/pressure sensor.

Interface to the Bosch Sensortec BME280 sensor, wrapping the vendor-supplied library.

This uses forced (one-shot) sampling only, hard-coded with the parameters recommended for weather monitoring.

Note
Due to limitations in the vendor-provided API only one SPI-based and one TWI-based instance may be present in a single application.

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

Constructor & Destructor Documentation

◆ bme280() [1/2]

nrfcxx::sensor::bme280::bme280 ( notifier_type  notify,
nrfcxx::periph::SPI spi,
int  csn_psel 
)

Construct an instance that controls through the SPI interface.

Parameters
notifythe notifier to inform the application of LPM processing needs.
spireference to the SPI peripheral to use.
csn_pselGPIO pin selector (index) identifying the GPIo connected to the BME280 CSn signal.

◆ bme280() [2/2]

nrfcxx::sensor::bme280::bme280 ( notifier_type  notify,
nrfcxx::periph::TWI twi,
bool  addr_sec = false 
)

Construct an instance that controls through the I2C interface.

Parameters
notifythe notifier to inform the application of LPM processing needs.
twireference to the TWI peripheral to use.
addr_secfalse to use the primary I2C address, true to use the secondary I2C address.

Member Function Documentation

◆ fetch()

int nrfcxx::sensor::bme280::fetch ( observations_type obs)

Retrieve the results from the most recent observation.

Note
The SPI/TWI peripheral must be enabled before this method is invoked.
Returns
zero on success, or a non-zero error code.

◆ initialize()

int nrfcxx::sensor::bme280::initialize ( )

Initialize the BME280.

Issue this only once for each instance. This confirms communication with the device and configures the sample options.

Note
The SPI/TWI peripheral must be enabled before this method is invoked.
Warning
If the BME280 is non-responsive this may delay internally for up to 15 ms waiting to successfully connect to the device. This is due to busy-wait calls inside the vendor-supplied library.
Returns
zero on success, or a non-zero error code.

◆ sample()

int nrfcxx::sensor::bme280::sample ( )
inline

Request a new sample from the device.

Note
Wait for SAMPLE_DELAY_utt ticks before attempting to invoke fetch().
The SPI/TWI peripheral must be enabled before this method is invoked.
Returns
zero on success, or a non-zero error code.

Field Documentation

◆ INVALID_PRESSURE

constexpr unsigned int nrfcxx::sensor::bme280::INVALID_PRESSURE = 0x00C00000
staticconstexpr

Value used for invalid pressure observations.

This is sized to fit in a 24-bit unsigned integer, with a maximum representable value of 1258.2911 hPa.

◆ SAMPLE_DELAY_utt

constexpr unsigned int nrfcxx::sensor::bme280::SAMPLE_DELAY_utt = clock::uptime::from_ms(10)
staticconstexpr

Lower bound for wait after sample() before get_sensor_data().

This value is designed for the weather monitoring configuration hard-coded into the implementation. Nominal maximum 9.3 ms.


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