From 579035851f95a33129c96be1c6818a5f40067663 Mon Sep 17 00:00:00 2001 From: Francois <thiebolt@irit.fr> Date: Thu, 10 Mar 2022 00:39:40 +0100 Subject: [PATCH] update --- .../libraries/neocampus_drivers/SCD4x.cpp | 50 +++++----- neosensor/libraries/neocampus_drivers/SCD4x.h | 98 ++++++------------- 2 files changed, 56 insertions(+), 92 deletions(-) diff --git a/neosensor/libraries/neocampus_drivers/SCD4x.cpp b/neosensor/libraries/neocampus_drivers/SCD4x.cpp index 75789847..28cd8fb9 100644 --- a/neosensor/libraries/neocampus_drivers/SCD4x.cpp +++ b/neosensor/libraries/neocampus_drivers/SCD4x.cpp @@ -42,22 +42,18 @@ const uint8_t SCD4x::i2c_addrs[] = { 0x69 }; -#if 0 -TO BE CONTINUED - - /**************************************************************************/ /*! @brief Test if device at 'adr' is really what we think of */ /**************************************************************************/ -boolean SHT3x::is_device( uint8_t a ) { +boolean SCD4x::is_device( uint8_t a ) { // First step, parse all addresses boolean found = false; - for( uint8_t i=0; i < sizeof(SHT3x::i2c_addrs); i++ ) { - if( SHT3x::i2c_addrs[i] == a) { + for( uint8_t i=0; i < sizeof(SCD4x::i2c_addrs); i++ ) { + if( SCD4x::i2c_addrs[i] == a) { found = true; break; } @@ -77,21 +73,22 @@ boolean SHT3x::is_device( uint8_t a ) { @brief Instantiates a new class */ /**************************************************************************/ -SHT3x::SHT3x( sht3xMeasureType_t kindness ) : generic_driver() { +SCD4x::SCD4x( scd4xMeasureType_t kindness ) : generic_driver() { _i2caddr = -1; _measureType = kindness; - _resolution = SHT3X_DEFL_RESOLUTION; } /* declare kind of units */ -const char *SHT3x::_t_units = "celsius"; -const char *SHT3x::_rh_units = "%r.H."; +const char *SCD4x::units_co2 = "ppm"; +const char *SCD4x::units_temp = "celsius"; +const char *SCD4x::units_rh = "%r.H."; /* declare others static vars */ -unsigned long SHT3x::_lastMsRead = 0; -uint16_t SHT3x::_t_sensor = (uint16_t)(-1); -uint16_t SHT3x::_rh_sensor = (uint16_t)(-1); +unsigned long SCD4x::_lastMsRead = 0; +uint16_t SCD4x::_co2_sensor = (uint16_t)(-1); +uint16_t SCD4x::_t_sensor = (uint16_t)(-1); +uint16_t SCD4x::_rh_sensor = (uint16_t)(-1); /**************************************************************************/ @@ -99,17 +96,20 @@ uint16_t SHT3x::_rh_sensor = (uint16_t)(-1); @brief send back units */ /**************************************************************************/ -const char * SHT3x::sensorUnits( uint8_t idx ) { +const char * SCD4x::sensorUnits( uint8_t idx ) { switch( _measureType ) { - case sht3xMeasureType_t::temperature: - return _t_units; + case scd4xMeasureType_t::co2: + return units_co2; break; - case sht3xMeasureType_t::humidity: - return _rh_units; + case scd4xMeasureType_t::temperature: + return units_temp; + break; + case scd4xMeasureType_t::humidity: + return units_rh; break; default: - log_error(F("\n[SHT3x] unknown kind of measureType ?!?")); log_flush(); + log_error(F("\n[SCD4x] unknown kind of measureType ?!?")); log_flush(); return nullptr; } } @@ -120,7 +120,7 @@ const char * SHT3x::sensorUnits( uint8_t idx ) { @brief Setups the HW */ /**************************************************************************/ -boolean SHT3x::begin( uint8_t addr=-1) { +boolean SCD4x::begin( uint8_t addr=-1) { // get i2caddr if( (addr < (uint8_t)(I2C_ADDR_START)) or (addr > (uint8_t)(I2C_ADDR_STOP)) ) return false; _i2caddr = addr; @@ -134,7 +134,6 @@ boolean SHT3x::begin( uint8_t addr=-1) { */ // define defaults parameters - setResolution( _resolution ); /* start lastmsg time measurement. * This way, we get sure to have at least a first acquisition! */ @@ -147,16 +146,17 @@ boolean SHT3x::begin( uint8_t addr=-1) { /* * Power modes: ON or powerOFF */ -void SHT3x::powerOFF( void ) +void SCD4x::powerOFF( void ) { // device does not feature continuous integration so nothing to start or stop } -void SHT3x::powerON( void ) +void SCD4x::powerON( void ) { // device does not feature continuous integration so nothing to start or stop } +TO BE CONTINUED /**************************************************************************/ /*! @@ -505,5 +505,3 @@ bool SHT3x::_check_identity( uint8_t a ) { return true; } - -#endif /* 0 */ diff --git a/neosensor/libraries/neocampus_drivers/SCD4x.h b/neosensor/libraries/neocampus_drivers/SCD4x.h index b8fe40fa..ca37674a 100644 --- a/neosensor/libraries/neocampus_drivers/SCD4x.h +++ b/neosensor/libraries/neocampus_drivers/SCD4x.h @@ -50,7 +50,7 @@ * - CO2, temp and humidity are measured and sent in a single 9bytes frame * 16bits C02 + CRC + 16bits T + CRC + 16bits RH + CRC * - every 16bits frames are CRC protected - * - CRC8 0x31, initial=0xFF for 16bits data (first is ) + * - CRC8 0x31, initial=0xFF, final xor=0x00 for 16bits data (first is ) */ enum class sht3xCmd_t : uint16_t { @@ -74,73 +74,37 @@ enum class sht3xCmd_t : uint16_t { // low-power operations start_low_power_periodoc_measurement = 0x21ac, // 30s measurement delay get_data_ready_status = 0xe4b8, // execution time: 1ms - -TO BE CONTINUED - -//Advanced features -#define SCD4x_COMMAND_PERSIST_SETTINGS 0x3615 // execution time: 800ms -#define SCD4x_COMMAND_GET_SERIAL_NUMBER 0x3682 // execution time: 1ms -#define SCD4x_COMMAND_PERFORM_SELF_TEST 0x3639 // execution time: 10000ms -#define SCD4x_COMMAND_PERFORM_FACTORY_RESET 0x3632 // execution time: 1200ms -#define SCD4x_COMMAND_REINIT 0x3646 // execution time: 20ms - -//Low power single shot - SCD41 only -#define SCD4x_COMMAND_MEASURE_SINGLE_SHOT 0x219d // execution time: 5000ms -#define SCD4x_COMMAND_MEASURE_SINGLE_SHOT_RHT_ONLY 0x2196 // execution time: 50ms - - - - soft_reset = 0X30A2, // software reset - heater_enable = 0x306D, // on-chip heater enable - heater_disable = 0x3066, // on-chip heater disable - get_status = 0xF32D, // read Status Register - clear_status = 0x3041, // clear Status Register - meas_highRes_stretch = 0x2C06, // Measurement High Repeatability (resolution) with Clock Stretch Enabled - meas_medRes_stretch = 0x2C0D, // Measurement Medium Repeatability (resolution) with Clock Stretch Enabled - meas_lowRes_stretch = 0x2C10, // Measurement Low Repeatability (resolution) with Clock Stretch Enabled - meas_highRes = 0x2400, // Measurement High Repeatability (resolution) WITHOUT clock stretching - meas_medRes = 0x240B, // Measurement Medium Repeatability (resolution) WITHOUT clock stretching - meas_lowRes = 0x2416, // Measurement Low Repeatability (resolution) WITHOUT clock stretching + // stop_periodic_measurement to stop low_power periodic measurement + + // advanced features + persist_settings = 0x3615, // execution time: 800ms + get_serial_number = 0x3682, // execution time: 1ms + perform_self_test = 0x3639, // execution time: 10000ms + perform_factory_reset = 0x3632, // execution time: 1200ms + reinit = 0x3646, // execution time: 20ms + + // low-power single shot - SCD41 only + measure_single_shot = 0x219d, // execution time: 5000ms + measure_single_shot_rht_only = 0x2196, // execution time: 50ms }; -// status -#define SHT3X_STATUS_REG_MASK 0xFC1F // removed bit 9:5 because of their unspecified value -#define SHT3X_STATUS_REG_DEFL 0x8010 // expected default value (apply MASK for value checking) - // type of measure -enum class sht3xMeasureType_t : uint8_t { +enum class scd4xMeasureType_t : uint8_t { + co2 = 0x00, humidity = 0x10, temperature = 0x20 }; -// resolution -enum class sht3xResolution_t : uint8_t { - high_res, - medium_res, - low_res -}; -#define SHT3X_DEFL_RESOLUTION sht3xResolution_t::high_res - -// integration time (ms) -enum class sht3xIntegration_t : uint8_t { - ms_integrate_high = 16, // integraion time (ms) for high resolution measure - ms_integrate_medium = 7, // integraion time (ms) for medium resolution measure - ms_integrate_low = 5 // integraion time (ms) for low resolution measure -}; - -#define SHT3X_INTEGRATION_TIME_CTE 5 // additionnal ms delay to all timings (total <= 255 ---uint8_t) - /* * Class */ -class SHT3x : public generic_driver { +class SCD4x : public generic_driver { public: - SHT3x( sht3xMeasureType_t ); + SCD4x( scd4xMeasureType_t ); - boolean begin( uint8_t ); // start with an i2c address - bool setResolution( sht3xResolution_t ); + boolean begin( uint8_t ); // start with an i2c address void powerON( void ); // switch ON void powerOFF( void ); // switch OFF @@ -150,17 +114,18 @@ class SHT3x : public generic_driver { String subID( uint8_t=0 ) { return String(_i2caddr); }; // read sensor's values + boolean getCO2( float* ); // retroieve co2 boolean getRH( float* ); // retrieve humidity boolean getTemp( float* ); // retrieve temperature // --- static methods / constants ----------------------- - + // list of possibles I2C addrs static const uint8_t i2c_addrs[]; // device detection static boolean is_device( uint8_t ); - + private: // -- private methods bool _readSensor( uint16_t* ); // low-level function to read value registers @@ -171,22 +136,23 @@ class SHT3x : public generic_driver { // --- private attributes uint8_t _i2caddr; - sht3xResolution_t _resolution; - sht3xMeasureType_t _measureType; - static const char *_t_units; - static const char *_rh_units; - uint8_t _integrationTime; // ms time to integrate a measure (for non continuous mode) - /* both TEMP and RH are read at the same time ==> hence we store them + scd4xMeasureType_t _measureType; + static const char *units_co2; + static const char *units_temp; + static const char *units_rh; + uint16_t _integrationTime; // ms time to integrate a measure + /* CO2, TEMP and RH are read at the same time ==> hence we store them as shared attributes across all instances */ static unsigned long _lastMsRead; // last time data have been read (elapsed ms from beginning) - static uint16_t _t_sensor; // shared across all instances (for both humidity and temperature modules) - static uint16_t _rh_sensor; // shared across all instances (for both humidity and temperature modules) + static uint16_t _co2_sensor; // shared across all instances + static uint16_t _t_sensor; // shared across all instances + static uint16_t _rh_sensor; // shared across all instances // CRC computation static const uint8_t _crc8_polynom; // crc P(x)=x^8+x^5+x^4+1 (0x31) 1.00110001, init=0xFF -#ifdef SHT3X_CRC_LOOKUP_TABLE +#ifdef SCD4X_CRC_LOOKUP_TABLE static const uint8_t _crc8_table[256]; -#endif /* SHT3X_CRC_LOOKUP_TABLE */ +#endif /* SCD4X_CRC_LOOKUP_TABLE */ }; #endif /* _SCD4X_H_ */ -- GitLab