M5Unit-ENV 1.2.0 git rev:d576302
Loading...
Searching...
No Matches
m5::unit::UnitSCD40 Class Reference

SCD40 unit component. More...

#include <unit_SCD40.hpp>

Inheritance diagram for m5::unit::UnitSCD40:
m5::unit::UnitSCD41

Classes

struct  config_t
 Settings for begin. More...
 

Public Member Functions

 UnitSCD40 (const uint8_t addr=DEFAULT_ADDRESS)
 
virtual bool begin () override
 
virtual void update (const bool force=false) override
 
Settings for begin
config_t config () const
 Gets the configration.
 
void config (const config_t &cfg)
 Set the configration.
 
Measurement data by periodic
uint16_t co2 () const
 Oldest measured CO2 concentration (ppm)
 
float temperature () const
 Oldest measured temperature (Celsius)
 
float celsius () const
 Oldest measured temperature (Celsius)
 
float fahrenheit () const
 Oldest measured temperature (Fahrenheit)
 
float humidity () const
 Oldest measured humidity (RH)
 
Periodic measurement
bool startPeriodicMeasurement (const scd4x::Mode mode=scd4x::Mode::Normal)
 Start periodic measurement.
 
bool startLowPowerPeriodicMeasurement ()
 Start low power periodic measurement.
 
bool stopPeriodicMeasurement (const uint32_t duration=scd4x::STOP_PERIODIC_MEASUREMENT_DURATION)
 Stop periodic measurement.
 
On-Chip Output Signal Compensation
bool writeTemperatureOffset (const float offset, const uint32_t duration=scd4x::SET_TEMPERATURE_OFFSET_DURATION)
 Write the temperature offset.
 
bool readTemperatureOffset (float &offset)
 Read the temperature offset.
 
bool writeSensorAltitude (const uint16_t altitude, const uint32_t duration=scd4x::SET_SENSOR_ALTITUDE_DURATION)
 Write the sensor altitude.
 
bool readSensorAltitude (uint16_t &altitude)
 Read the sensor altitude.
 
bool writeAmbientPressure (const float pressure, const uint32_t duration=scd4x::SET_AMBIENT_PRESSURE_DURATION)
 Write the ambient pressure.
 
Field Calibration
bool performForcedRecalibration (const uint16_t concentration, int16_t &correction)
 Perform forced recalibration.
 
bool writeAutomaticSelfCalibrationEnabled (const bool enabled=true, const uint32_t duration=scd4x::SET_AUTOMATIC_SELF_CALIBRATION_ENABLED_DURATION)
 Enable/disable automatic self calibration.
 
bool readAutomaticSelfCalibrationEnabled (bool &enabled)
 Check if automatic self calibration is enabled.
 
Advanced Features
bool writePersistSettings (const uint32_t duration=scd4x::PERSIST_SETTINGS_DURATION)
 Write sensor settings from RAM to EEPROM.
 
bool readSerialNumber (char *serialNumber)
 Read the serial number string.
 
bool readSerialNumber (uint64_t &serialNumber)
 Read the serial number value.
 
bool performSelfTest (bool &malfunction)
 Perform self test.
 
bool performFactoryReset (const uint32_t duration=scd4x::PERFORM_FACTORY_RESET_DURATION)
 Peform factory reset.
 
bool reInit (const uint32_t duration=scd4x::REINIT_DURATION)
 Re-initialize the sensor, load settings from EEPROM.
 

Protected Member Functions

bool start_periodic_measurement (const scd4x::Mode mode=scd4x::Mode::Normal)
 
bool stop_periodic_measurement (const uint32_t duration=scd4x::STOP_PERIODIC_MEASUREMENT_DURATION)
 
bool read_data_ready_status ()
 
bool read_measurement (scd4x::Data &d, const bool all=true)
 
 M5_UNIT_COMPONENT_PERIODIC_MEASUREMENT_ADAPTER_HPP_BUILDER (UnitSCD40, scd4x::Data)
 

Protected Attributes

std::unique_ptr< m5::container::CircularBuffer< scd4x::Data > > _data {}
 
config_t _cfg {}
 

Detailed Description

SCD40 unit component.

Member Function Documentation

◆ performFactoryReset()

bool m5::unit::UnitSCD40::performFactoryReset ( const uint32_t duration = scd4x::PERFORM_FACTORY_RESET_DURATION)

Peform factory reset.

Reset all settings to the factory values

Returns
True if successful
Warning
During periodic detection runs, an error is returned
Measurement duration max 1200 ms

◆ performForcedRecalibration()

bool m5::unit::UnitSCD40::performForcedRecalibration ( const uint16_t concentration,
int16_t & correction )

Perform forced recalibration.

Parameters
concentrationUnit:ppm
[out]correctionThe FRC correction value
Returns
True if successful
Warning
During periodic detection runs, an error is returned
Blocked until the process is completed (about 400ms)

◆ performSelfTest()

bool m5::unit::UnitSCD40::performSelfTest ( bool & malfunction)

Perform self test.

Parameters
[out]Trueif malfunction detected
Returns
True if successful
Note
Takes 10 seconds to complete
Warning
During periodic detection runs, an error is returned

◆ readAutomaticSelfCalibrationEnabled()

bool m5::unit::UnitSCD40::readAutomaticSelfCalibrationEnabled ( bool & enabled)

Check if automatic self calibration is enabled.

Parameters
[out]enabledTrue if automatic self calibration is enabled
Returns
True if successful
Warning
During periodic detection runs, an error is returned
Measurement duration max 1 ms

◆ readSensorAltitude()

bool m5::unit::UnitSCD40::readSensorAltitude ( uint16_t & altitude)

Read the sensor altitude.

Parameters
[out]altitudeAltitude value
durationMax command duration(ms)
Returns
True if successful
Warning
During periodic detection runs, an error is returned

◆ readSerialNumber() [1/2]

bool m5::unit::UnitSCD40::readSerialNumber ( char * serialNumber)

Read the serial number string.

Parameters
[out]serialNumberOutput buffer
Returns
True if successful
Warning
Size must be at least 13 bytes
During periodic detection runs, an error is returned

◆ readSerialNumber() [2/2]

bool m5::unit::UnitSCD40::readSerialNumber ( uint64_t & serialNumber)

Read the serial number value.

Parameters
[out]serialNumberserial number value
Returns
True if successful
Note
The serial number is 48 bit
Warning
During periodic detection runs, an error is returned

◆ readTemperatureOffset()

bool m5::unit::UnitSCD40::readTemperatureOffset ( float & offset)

Read the temperature offset.

Parameters
[out]offsetOffset value
durationMax command duration(ms)
Returns
True if successful
Warning
During periodic detection runs, an error is returned

◆ reInit()

bool m5::unit::UnitSCD40::reInit ( const uint32_t duration = scd4x::REINIT_DURATION)

Re-initialize the sensor, load settings from EEPROM.

Returns
True if successful
Warning
During periodic detection runs, an error is returned
Measurement duration max 20 ms

◆ startLowPowerPeriodicMeasurement()

bool m5::unit::UnitSCD40::startLowPowerPeriodicMeasurement ( )
inline

Start low power periodic measurement.

Returns
True if successful

◆ startPeriodicMeasurement()

bool m5::unit::UnitSCD40::startPeriodicMeasurement ( const scd4x::Mode mode = scd4x::Mode::Normal)
inline

Start periodic measurement.

Parameters
modeMeasurement mode
Returns
True if successful

◆ stopPeriodicMeasurement()

bool m5::unit::UnitSCD40::stopPeriodicMeasurement ( const uint32_t duration = scd4x::STOP_PERIODIC_MEASUREMENT_DURATION)
inline

Stop periodic measurement.

Parameters
durationMax command duration(ms)
Returns
True if successful

◆ writeAmbientPressure()

bool m5::unit::UnitSCD40::writeAmbientPressure ( const float pressure,
const uint32_t duration = scd4x::SET_AMBIENT_PRESSURE_DURATION )

Write the ambient pressure.

Define the ambient pressure in Pascals, so RH and CO2 are compensated for atmospheric pressure setAmbientPressure overrides setSensorAltitude

Parameters
presureUnit: pascals (>= 0.0f)
durationMax command duration(ms)
Returns
True if successful

◆ writeAutomaticSelfCalibrationEnabled()

bool m5::unit::UnitSCD40::writeAutomaticSelfCalibrationEnabled ( const bool enabled = true,
const uint32_t duration = scd4x::SET_AUTOMATIC_SELF_CALIBRATION_ENABLED_DURATION )

Enable/disable automatic self calibration.

Parameters
enabledEnable automatic self calibration if true
Returns
True if successful
Warning
During periodic detection runs, an error is returned

◆ writePersistSettings()

bool m5::unit::UnitSCD40::writePersistSettings ( const uint32_t duration = scd4x::PERSIST_SETTINGS_DURATION)

Write sensor settings from RAM to EEPROM.

Returns
True if successful
Warning
During periodic detection runs, an error is returned

◆ writeSensorAltitude()

bool m5::unit::UnitSCD40::writeSensorAltitude ( const uint16_t altitude,
const uint32_t duration = scd4x::SET_SENSOR_ALTITUDE_DURATION )

Write the sensor altitude.

Define the sensor altitude in metres above sea level, so RH and CO2 arecompensated for atmospheric pressure Default altitude is 0m

Parameters
altitudeUnit:metres
durationMax command duration(ms)
Returns
True if successful
Warning
During periodic detection runs, an error is returned

◆ writeTemperatureOffset()

bool m5::unit::UnitSCD40::writeTemperatureOffset ( const float offset,
const uint32_t duration = scd4x::SET_TEMPERATURE_OFFSET_DURATION )

Write the temperature offset.

Define how warm the sensor is compared to ambient, so RH and T are temperature compensated. Has no effect on the CO2 reading Default offsetis 4C

Parameters
offset(0 <= offset < 175)
durationMax command duration(ms)
Returns
True if successful
Warning
During periodic detection runs, an error is returned