Skip to content

Commit e9c5f96

Browse files
committed
Merge branch 'LKD-458-fix-embedded-data-ready-interface' into 'master'
Rename getDataReadyStatus() to getDataReadyFlag() See merge request MSO-SW/drivers/embedded/embedded-i2c-scd4x!15
2 parents 8808fe9 + 3f333bc commit e9c5f96

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

scd4x_i2c.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,11 @@ int16_t scd4x_start_low_power_periodic_measurement() {
290290
return sensirion_i2c_write_data(SCD4X_I2C_ADDRESS, &buffer[0], offset);
291291
}
292292

293-
int16_t scd4x_get_data_ready_status(uint16_t* data_ready) {
293+
int16_t scd4x_get_data_ready_flag(bool* data_ready_flag) {
294294
int16_t error;
295295
uint8_t buffer[3];
296296
uint16_t offset = 0;
297+
uint16_t local_data_ready = 0;
297298
offset = sensirion_i2c_add_command_to_buffer(&buffer[0], offset, 0xE4B8);
298299

299300
error = sensirion_i2c_write_data(SCD4X_I2C_ADDRESS, &buffer[0], offset);
@@ -307,7 +308,8 @@ int16_t scd4x_get_data_ready_status(uint16_t* data_ready) {
307308
if (error) {
308309
return error;
309310
}
310-
*data_ready = sensirion_common_bytes_to_uint16_t(&buffer[0]);
311+
local_data_ready = sensirion_common_bytes_to_uint16_t(&buffer[0]);
312+
*data_ready_flag = (local_data_ready & 0x07FF) != 0;
311313
return NO_ERROR;
312314
}
313315

scd4x_i2c.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int16_t scd4x_start_periodic_measurement(void);
5959
* scd4x_read_measurement_ticks() - read sensor output. The measurement data can
6060
* only be read out once per signal update interval as the buffer is emptied
6161
* upon read-out. If no data is available in the buffer, the sensor returns a
62-
* NACK. To avoid a NACK response the get_data_ready_status can be issued to
62+
* NACK. To avoid a NACK response the get_data_ready_flag can be issued to
6363
* check data status. The I2C master can abort the read transfer with a NACK
6464
* followed by a STOP condition after any data byte if the user is not
6565
* interested in subsequent data.
@@ -258,14 +258,14 @@ int16_t scd4x_set_automatic_self_calibration(uint16_t asc_enabled);
258258
int16_t scd4x_start_low_power_periodic_measurement(void);
259259

260260
/**
261-
* scd4x_get_data_ready_status() - Check whether new measurement data is
261+
* scd4x_get_data_ready_flag() - Check whether new measurement data is
262262
* available for read-out.
263263
*
264-
* @param data_ready If last 11 bits are 0 data not ready, else data ready
264+
* @param data_ready_flag True if data available, otherwise false.
265265
*
266266
* @return 0 on success, an error code otherwise
267267
*/
268-
int16_t scd4x_get_data_ready_status(uint16_t* data_ready);
268+
int16_t scd4x_get_data_ready_flag(bool* data_ready_flag);
269269

270270
/**
271271
* scd4x_persist_settings() - Configuration settings such as the temperature

scd4x_i2c_example_usage.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,16 @@ int main(void) {
7272

7373
for (;;) {
7474
// Read Measurement
75-
sensirion_i2c_hal_sleep_usec(5000000);
75+
sensirion_i2c_hal_sleep_usec(100000);
76+
bool data_ready_flag = false;
77+
error = scd4x_get_data_ready_flag(&data_ready_flag);
78+
if (error) {
79+
printf("Error executing scd4x_get_data_ready_flag(): %i\n", error);
80+
continue;
81+
}
82+
if (!data_ready_flag) {
83+
continue;
84+
}
7685

7786
uint16_t co2;
7887
int32_t temperature;

tests/scd4x_i2c_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ TEST (SCD4X_Tests, SCD4X_Test_start_low_power_periodic_measurement) {
200200
CHECK_EQUAL_ZERO_TEXT(error, "scd4x_stop_periodic_measurement");
201201
}
202202

203-
TEST (SCD4X_Tests, SCD4X_Test_get_data_ready_status) {
203+
TEST (SCD4X_Tests, SCD4X_Test_get_data_ready_flag) {
204204
int16_t error;
205-
uint16_t data_ready;
206-
error = scd4x_get_data_ready_status(&data_ready);
207-
CHECK_EQUAL_ZERO_TEXT(error, "scd4x_get_data_ready_status");
205+
bool data_ready;
206+
error = scd4x_get_data_ready_flag(&data_ready);
207+
CHECK_EQUAL_ZERO_TEXT(error, "scd4x_get_data_ready_flag");
208208
printf("data_ready: %i\n", data_ready);
209209
}
210210

0 commit comments

Comments
 (0)