Skip to content

Commit cc72272

Browse files
committed
add read measurement convenience method again
1 parent ff925f3 commit cc72272

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

scd4x_i2c.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ int16_t scd4x_read_measurement_raw(uint16_t* co2_concentration,
159159
return local_error;
160160
}
161161

162+
int16_t scd4x_read_measurement(uint16_t* co2, int32_t* temperature_m_deg_c,
163+
int32_t* humidity_m_percent_rh) {
164+
int16_t error;
165+
uint16_t temperature;
166+
uint16_t humidity;
167+
error = scd4x_read_measurement_raw(co2, &temperature, &humidity);
168+
if (error) {
169+
return error;
170+
}
171+
*temperature_m_deg_c = ((21875 * (int32_t)temperature) >> 13) - 45000;
172+
*humidity_m_percent_rh = ((12500 * (int32_t)humidity) >> 13);
173+
return NO_ERROR;
174+
}
175+
162176
int16_t scd4x_stop_periodic_measurement() {
163177
int16_t local_error = NO_ERROR;
164178
uint8_t* buffer_ptr = communication_buffer;

scd4x_i2c.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,21 @@ int16_t scd4x_read_measurement_raw(uint16_t* co2_concentration,
195195
uint16_t* temperature,
196196
uint16_t* relative_humidity);
197197

198+
/**
199+
* @brief Read sensor output and convert to pyhsical unit.
200+
*
201+
* See @ref scd4x_read_measurement_raw() for more details.
202+
*
203+
* @param[out] co2 CO₂ concentration in ppm
204+
* @param[out] temperature_m_deg_c Temperature in milli degrees celsius (°C *
205+
* 1000)
206+
* @param[out] humidity_m_percent_rh Relative humidity in milli percent RH
207+
* (%RH * 1000)
208+
* @return 0 on success, an error code otherwise
209+
*/
210+
int16_t scd4x_read_measurement(uint16_t* co2, int32_t* temperature_m_deg_c,
211+
int32_t* humidity_m_percent_rh);
212+
198213
/**
199214
* @brief Stop periodic measurement to change the sensor configuration or to
200215
* save power.

0 commit comments

Comments
 (0)