11 #if RI_SHTCX_ENABLED || DOXYGEN
32 #define LOW_POWER_SLEEP_MS_MIN (1000U)
33 #define SHTCX_PROBE_RETRIES_MAX (5U)
35 static inline uint32_t US_TO_MS_ROUNDUP (uint32_t us)
37 return (us / 1000) + 2;
41 #define RETURN_SUCCESS_ON_VALID(param) do {\
42 if(RD_SENSOR_CFG_DEFAULT == param ||\
43 RD_SENSOR_CFG_MIN == param ||\
44 RD_SENSOR_CFG_MAX == param ||\
45 RD_SENSOR_CFG_NO_CHANGE == param \
50 #define VERIFY_SENSOR_SLEEPS() do { \
51 uint8_t MACRO_MODE = 0; \
52 ri_shtcx_mode_get(&MACRO_MODE); \
53 if(RD_SENSOR_CFG_SLEEP != MACRO_MODE) { return RD_ERROR_INVALID_STATE; } \
56 static uint64_t m_tsample;
57 static bool m_autorefresh;
58 static int32_t m_temperature;
59 static int32_t m_humidity;
60 static bool m_is_init;
61 static const char m_sensor_name[] =
"SHTCX";
64 #define STATUS_ERR_BAD_DATA (-1)
65 #define STATUS_CRC_FAIL (-2)
66 #define STATUS_UNKNOWN_DEVICE (-3)
67 #define STATUS_WAKEUP_FAILED (-4)
68 #define STATUS_SLEEP_FAILED (-5)
76 static rd_status_t SHTCX_TO_RUUVI_ERROR (
const int16_t rslt)
106 sensor->
name = m_sensor_name;
114 err_code = SHTCX_TO_RUUVI_ERROR (shtc1_probe());
134 shtc1_enable_low_power_mode (0);
152 err_code |= SHTCX_TO_RUUVI_ERROR (shtc1_sleep());
167 shtc1_enable_low_power_mode (1);
168 err_code |= SHTCX_TO_RUUVI_ERROR (shtc1_sleep());
174 m_autorefresh =
false;
207 uint8_t original = *resolution;
226 uint8_t original = *scale;
242 if (NULL == dsp || NULL == parameter) {
return RD_ERROR_NULL; }
260 if (NULL == dsp || NULL == parameter) {
return RD_ERROR_NULL; }
280 m_autorefresh =
false;
282 err_code |= SHTCX_TO_RUUVI_ERROR (shtc1_sleep());
287 uint8_t current_mode;
297 m_autorefresh =
false;
300 err_code |= SHTCX_TO_RUUVI_ERROR (shtc1_wake_up());
302 err_code |= SHTCX_TO_RUUVI_ERROR (shtc1_measure_blocking_read (&m_temperature,
304 err_code |= SHTCX_TO_RUUVI_ERROR (shtc1_sleep());
309 m_autorefresh =
true;
350 m_autorefresh =
false;
354 m_autorefresh =
true;
362 env_values[0] = m_humidity / 1000.0f;
363 env_values[1] = m_temperature / 1000.0f;
366 d_environmental.
data = env_values;
367 d_environmental.
valid = env_fields;
368 d_environmental.
fields = env_fields;
#define RD_ERROR_INVALID_PARAM
Invalid Parameter.
#define RD_ERROR_NULL
Null Pointer.
uint32_t rd_status_t
bitfield for representing errors
#define RD_ERROR_INVALID_DATA
Invalid Data.
#define RD_INT32_INVALID
Signal that value should not be used.
#define RD_ERROR_NOT_SUPPORTED
Not supported.
#define RD_SUCCESS
Internal Error.
#define RD_ERROR_NOT_FOUND
Not found.
#define RD_UINT64_INVALID
Signal that value should not be used.
#define RD_ERROR_INVALID_STATE
Invalid state, operation disallowed in this state.
#define RD_ERROR_INTERNAL
Internal Error.
#define LOW_POWER_SLEEP_MS_MIN
#define STATUS_OK
SHTC driver ok.
rd_status_t ri_shtcx_uninit(rd_sensor_t *sensor, rd_bus_t bus, uint8_t handle)
rd_sensor_init_fp
rd_status_t ri_shtcx_scale_set(uint8_t *scale)
rd_sensor_setup_fp
rd_status_t ri_shtcx_samplerate_set(uint8_t *samplerate)
rd_sensor_setup_fp
#define RETURN_SUCCESS_ON_VALID(param)
Macro for checking "ignored" parameters NO_CHANGE, MIN, MAX, DEFAULT.
rd_status_t ri_shtcx_dsp_get(uint8_t *dsp, uint8_t *parameter)
#define STATUS_UNKNOWN_DEVICE
Invalid WHOAMI.
#define STATUS_SLEEP_FAILED
Device didn't go to sleep.
void sensirion_sleep_usec(uint32_t useconds)
Implement sleep function for SHTC driver.
rd_status_t ri_shtcx_dsp_set(uint8_t *dsp, uint8_t *parameter)
rd_sensor_setup_fp
#define STATUS_WAKEUP_FAILED
Device didn't wake up.
#define STATUS_CRC_FAIL
SHTC driver CRC error.
rd_status_t ri_shtcx_init(rd_sensor_t *sensor, rd_bus_t bus, uint8_t handle)
rd_sensor_init_fp
rd_status_t ri_shtcx_scale_get(uint8_t *scale)
rd_sensor_setup_fp
rd_status_t ri_shtcx_data_get(rd_sensor_data_t *const p_data)
rd_sensor_data_fp
#define VERIFY_SENSOR_SLEEPS()
Macro for checking that sensor is in sleep mode before configuration.
#define STATUS_ERR_BAD_DATA
SHTC driver data invald.
rd_status_t ri_shtcx_samplerate_get(uint8_t *samplerate)
rd_sensor_setup_fp
rd_status_t ri_shtcx_resolution_get(uint8_t *resolution)
rd_sensor_setup_fp
#define SHTCX_PROBE_RETRIES_MAX
rd_status_t ri_shtcx_mode_get(uint8_t *mode)
rd_sensor_setup_fp
rd_status_t ri_shtcx_mode_set(uint8_t *mode)
rd_sensor_setup_fp
rd_status_t ri_shtcx_resolution_set(uint8_t *resolution)
rd_sensor_setup_fp
#define RD_SENSOR_DSP_LAST
Return last value from sensor. Parameter: No effect. Use default.
#define RD_SENSOR_ERR_NOT_SUPPORTED
Error code, given parameter is not supported by sensor.
bool rd_sensor_is_init(const rd_sensor_t *const sensor)
Check if given sensor structure is already initialized.
#define RD_SENSOR_CFG_SLEEP
Sensor should go to sleep immediately.
#define RD_SENSOR_CFG_MAX
Configure largest supported and implemented value.
#define RD_SENSOR_CFG_DEFAULT
Default value, always valid for the sensor.
void rd_sensor_uninitialize(rd_sensor_t *const p_sensor)
Mark sensor as uninitialized by calling the generic initialization. Will not clear the name of the se...
rd_status_t rd_sensor_configuration_get(const rd_sensor_t *sensor, rd_sensor_configuration_t *config)
Implementation of ref rd_configuration_fp.
void rd_sensor_initialize(rd_sensor_t *const p_sensor)
Initialize sensor struct with non-null pointers which return RD_ERROR_NOT_INITIALIZED.
void rd_sensor_data_populate(rd_sensor_data_t *const target, const rd_sensor_data_t *const provided, const rd_sensor_data_fields_t requested)
Populate given target data with data provided by sensor as requested.
rd_status_t rd_sensor_configuration_set(const rd_sensor_t *sensor, rd_sensor_configuration_t *config)
Implementation of ref rd_configuration_fp.
#define RD_SENSOR_CFG_MIN
Configure smallest supported and implemented value.
#define RD_SENSOR_CFG_CONTINUOUS
Sensor will keep sampling at defined sample rate.
#define RD_SENSOR_CFG_NO_CHANGE
Do not change configured value.
rd_bus_t
Type of bus sensor uses.
uint64_t rd_sensor_timestamp_get(void)
Calls the timestamp function and returns its value.
#define RD_SENSOR_CFG_SINGLE
Sensor should go to sleep after single measurement.
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
Ruuvi sensor interface Lifecycle: Beta
Interface for I2C operations.
#define RI_SHTCX_WAKEUP_US
Time from wakeup cmd to rdy.
rd_status_t ri_delay_us(uint32_t time)
Delay a given number of microseconds.
rd_status_t ri_delay_ms(uint32_t time)
Delay a given number of milliseconds.
unsigned int humidity_rh
Relative humidity, %.
unsigned int temperature_c
Temperature, celcius.
Generic sensor data struct.
float * data
Data of sensor. Must contain as many elements as fields has bits set.
uint64_t timestamp_ms
Timestamp of the event, rd_sensor_timestamp_get.
rd_sensor_data_fields_t valid
Listing of valid data in this sample.
rd_sensor_data_fields_t fields
Description of datafields which may be contained in this sample.
Interface to sensor. Some sensors can implement additional functions. The additional functions are de...
rd_sensor_data_fp data_get
rd_sensor_data_fp
rd_configuration_fp configuration_set
rd_configuration_fp
rd_sensor_setup_fp samplerate_get
rd_sensor_setup_fp
rd_sensor_setup_fp resolution_get
rd_sensor_setup_fp
rd_sensor_init_fp uninit
rd_sensor_init_fp
rd_configuration_fp configuration_get
rd_configuration_fp
rd_sensor_dsp_fp dsp_get
rd_sensor_dsp_fp
rd_sensor_data_fields_t provides
Description of data fields the sensor is able to provide.
rd_sensor_dsp_fp dsp_set
rd_sensor_dsp_fp
rd_sensor_setup_fp mode_set
rd_sensor_setup_fp
const char * name
Sensor human-readable name. Should be at most 8 bytes long.
rd_sensor_setup_fp mode_get
rd_sensor_setup_fp
rd_sensor_setup_fp samplerate_set
rd_sensor_setup_fp
rd_sensor_init_fp init
rd_sensor_init_fp
rd_sensor_setup_fp scale_set
rd_sensor_setup_fp
rd_sensor_setup_fp resolution_set
rd_sensor_setup_fp
rd_sensor_setup_fp scale_get
rd_sensor_setup_fp
Union to access sensor data.
uint32_t bitfield
Bitfield used to access sensor data.
rd_sensor_data_bitfield_t datas
Structured data field.