libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
daisy::Dps310< Transport > Class Template Reference

Device support for DPS310 Barometric Pressure and Altitude Sensor. More...

Detailed Description

template<typename Transport>
class daisy::Dps310< Transport >

Device support for DPS310 Barometric Pressure and Altitude Sensor.

Author
beserge
Date
January 2022

#include <dps310.h>

Classes

struct  Config
 

Public Types

enum  dps310_rate_t {
  DPS310_1HZ , DPS310_2HZ , DPS310_4HZ , DPS310_8HZ ,
  DPS310_16HZ , DPS310_32HZ , DPS310_64HZ , DPS310_128HZ
}
 
enum  dps310_oversample_t {
  DPS310_1SAMPLE , DPS310_2SAMPLES , DPS310_4SAMPLES , DPS310_8SAMPLES ,
  DPS310_16SAMPLES , DPS310_32SAMPLES , DPS310_64SAMPLES , DPS310_128SAMPLES
}
 
enum  dps310_mode_t {
  DPS310_IDLE = 0b000 , DPS310_ONE_PRESSURE = 0b001 , DPS310_ONE_TEMPERATURE = 0b010 , DPS310_CONT_PRESSURE = 0b101 ,
  DPS310_CONT_TEMP = 0b110 , DPS310_CONT_PRESTEMP = 0b111
}
 
enum  Result { OK = 0 , ERR }
 

Public Member Functions

 Dps310 ()
 
 ~Dps310 ()
 
Result Init (Config config)
 
void reset (void)
 
void _readCalibration (void)
 
bool temperatureAvailable (void)
 
bool pressureAvailable (void)
 
float GetAltitude (float seaLevelhPa)
 
void setMode (dps310_mode_t mode)
 
void configurePressure (dps310_rate_t rate, dps310_oversample_t os)
 
void configureTemperature (dps310_rate_t rate, dps310_oversample_t os)
 
void Process (void)
 
float GetTemperature ()
 
float GetPressure ()
 
void Write8 (uint8_t reg, uint8_t value)
 
void ReadReg (uint8_t reg, uint8_t *buff, uint8_t size)
 
uint8_t Read8 (uint8_t reg)
 
uint16_t Read16 (uint8_t reg)
 
uint32_t Read24 (uint8_t reg)
 
uint16_t Read16_LE (uint8_t reg)
 
int16_t ReadS16 (uint8_t reg)
 
int16_t ReadS16_LE (uint8_t reg)
 
uint8_t ReadBits (uint8_t reg, uint8_t bits, uint8_t shift)
 
void WriteBits (uint8_t reg, uint8_t data, uint8_t bits, uint8_t shift)
 
Result GetTransportError ()
 

Static Public Member Functions

static int32_t twosComplement (int32_t val, uint8_t bits)
 

Public Attributes

int32_t oversample_scalefactor [8] = {524288, 1572864, 3670016, 7864320, 253952, 516096, 1040384, 2088960}
 

Member Enumeration Documentation

◆ dps310_mode_t

The oversample rate ranges

Enumerator
DPS310_IDLE 

Stopped/idle.

DPS310_ONE_PRESSURE 

Take single pressure measurement.

DPS310_ONE_TEMPERATURE 

Take single temperature measurement.

DPS310_CONT_PRESSURE 

Continuous pressure measurements.

DPS310_CONT_TEMP 

Continuous pressure measurements.

DPS310_CONT_PRESTEMP 

Continuous temp+pressure measurements.

◆ dps310_oversample_t

The oversample rate ranges

Enumerator
DPS310_1SAMPLE 

1 Hz

DPS310_2SAMPLES 

2 Hz

DPS310_4SAMPLES 

4 Hz

DPS310_8SAMPLES 

8 Hz

DPS310_16SAMPLES 

16 Hz

DPS310_32SAMPLES 

32 Hz

DPS310_64SAMPLES 

64 Hz

DPS310_128SAMPLES 

128 Hz

◆ dps310_rate_t

The measurement rate ranges

Enumerator
DPS310_1HZ 

1 Hz

DPS310_2HZ 

2 Hz

DPS310_4HZ 

4 Hz

DPS310_8HZ 

8 Hz

DPS310_16HZ 

16 Hz

DPS310_32HZ 

32 Hz

DPS310_64HZ 

64 Hz

DPS310_128HZ 

128 Hz

◆ Result

Enumerator
OK 
ERR 

Constructor & Destructor Documentation

◆ Dps310()

template<typename Transport >
daisy::Dps310< Transport >::Dps310 ( )
inline

◆ ~Dps310()

template<typename Transport >
daisy::Dps310< Transport >::~Dps310 ( )
inline

Member Function Documentation

◆ _readCalibration()

template<typename Transport >
void daisy::Dps310< Transport >::_readCalibration ( void  )
inline

◆ configurePressure()

template<typename Transport >
void daisy::Dps310< Transport >::configurePressure ( dps310_rate_t  rate,
dps310_oversample_t  os 
)
inline

Set the sample rate and oversampling averaging for pressure

Parameters
rateHow many samples per second to take
osHow many oversamples to average

◆ configureTemperature()

template<typename Transport >
void daisy::Dps310< Transport >::configureTemperature ( dps310_rate_t  rate,
dps310_oversample_t  os 
)
inline

Set the sample rate and oversampling averaging for temperature

Parameters
rateHow many samples per second to take
osHow many oversamples to average

◆ GetAltitude()

template<typename Transport >
float daisy::Dps310< Transport >::GetAltitude ( float  seaLevelhPa)
inline

Calculates the approximate altitude using barometric pressure and the supplied sea level hPa as a reference.

Parameters
seaLevelhPaThe current hPa at sea level.
Returns
The approximate altitude above sea level in meters.

◆ GetPressure()

template<typename Transport >
float daisy::Dps310< Transport >::GetPressure ( )
inline

Get the last pressure reading

Returns
Pressure in hPa

◆ GetTemperature()

template<typename Transport >
float daisy::Dps310< Transport >::GetTemperature ( )
inline

Get last temperature reading

Returns
temp in degrees Centigrade

◆ GetTransportError()

template<typename Transport >
Result daisy::Dps310< Transport >::GetTransportError ( )
inline

Get and reset the transport error flag

Returns
Whether the transport has errored since the last check

◆ Init()

template<typename Transport >
Result daisy::Dps310< Transport >::Init ( Config  config)
inline

Initialize the Dps310 device

Parameters
configConfiguration settings

◆ pressureAvailable()

template<typename Transport >
bool daisy::Dps310< Transport >::pressureAvailable ( void  )
inline

Whether new pressure data is available

Returns
True if new data available to read

◆ Process()

template<typename Transport >
void daisy::Dps310< Transport >::Process ( void  )
inline

Read the XYZ data from the sensor and store in the internal raw_pressure, raw_temperature, _pressure and _temperature variables.

◆ Read16()

template<typename Transport >
uint16_t daisy::Dps310< Transport >::Read16 ( uint8_t  reg)
inline

Reads a 16 bit value over I2C or SPI

Parameters
regthe register address to read from
Returns
the 16 bit data value read from the device

◆ Read16_LE()

template<typename Transport >
uint16_t daisy::Dps310< Transport >::Read16_LE ( uint8_t  reg)
inline

Reads a signed 16 bit little endian value over I2C or SPI

Parameters
regthe register address to read from
Returns
the 16 bit data value read from the device

◆ Read24()

template<typename Transport >
uint32_t daisy::Dps310< Transport >::Read24 ( uint8_t  reg)
inline

Reads a 24 bit value

Parameters
regthe register address to read from
Returns
the 24 bit data value read from the device

◆ Read8()

template<typename Transport >
uint8_t daisy::Dps310< Transport >::Read8 ( uint8_t  reg)
inline

Reads an 8 bit value

Parameters
regthe register address to read from
Returns
the data uint8_t read from the device

◆ ReadBits()

template<typename Transport >
uint8_t daisy::Dps310< Transport >::ReadBits ( uint8_t  reg,
uint8_t  bits,
uint8_t  shift 
)
inline

◆ ReadReg()

template<typename Transport >
void daisy::Dps310< Transport >::ReadReg ( uint8_t  reg,
uint8_t buff,
uint8_t  size 
)
inline

Read from a reg address a defined number of bytes

◆ ReadS16()

template<typename Transport >
int16_t daisy::Dps310< Transport >::ReadS16 ( uint8_t  reg)
inline

Reads a signed 16 bit value over I2C or SPI

Parameters
regthe register address to read from
Returns
the 16 bit data value read from the device

◆ ReadS16_LE()

template<typename Transport >
int16_t daisy::Dps310< Transport >::ReadS16_LE ( uint8_t  reg)
inline

Reads a signed little endian 16 bit value over I2C or SPI

Parameters
regthe register address to read from
Returns
the 16 bit data value read from the device

◆ reset()

template<typename Transport >
void daisy::Dps310< Transport >::reset ( void  )
inline

Performs a software reset

◆ setMode()

template<typename Transport >
void daisy::Dps310< Transport >::setMode ( dps310_mode_t  mode)
inline

Set the operational mode of the sensor (continuous or one-shot)

Parameters
modecan be DPS310_IDLE, one shot: DPS310_ONE_PRESSURE or DPS310_ONE_TEMPERATURE, continuous: DPS310_CONT_PRESSURE, DPS310_CONT_TEMP, DPS310_CONT_PRESTEMP

◆ temperatureAvailable()

template<typename Transport >
bool daisy::Dps310< Transport >::temperatureAvailable ( void  )
inline

Whether new temperature data is available

Returns
True if new data available to read

◆ twosComplement()

template<typename Transport >
static int32_t daisy::Dps310< Transport >::twosComplement ( int32_t  val,
uint8_t  bits 
)
inlinestatic

◆ Write8()

template<typename Transport >
void daisy::Dps310< Transport >::Write8 ( uint8_t  reg,
uint8_t  value 
)
inline

Writes an 8 bit value

Parameters
regthe register address to write to
valuethe value to write to the register

◆ WriteBits()

template<typename Transport >
void daisy::Dps310< Transport >::WriteBits ( uint8_t  reg,
uint8_t  data,
uint8_t  bits,
uint8_t  shift 
)
inline

Member Data Documentation

◆ oversample_scalefactor

template<typename Transport >
int32_t daisy::Dps310< Transport >::oversample_scalefactor[8] = {524288, 1572864, 3670016, 7864320, 253952, 516096, 1040384, 2088960}

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