Skip to content

Commit efe1719

Browse files
committed
Merge branch 'LKD458-fix-raspberry-data-ready-interface' into 'master'
Rename getDataReadyStatus() to getDataReadyFlag() See merge request MSO-SW/drivers/raspberry-pi/raspberry-pi-i2c-scd4x!13
2 parents 86cb930 + 5fb51aa commit efe1719

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
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 & 0x7FF) != 0;
311313
return NO_ERROR;
312314
}
313315

scd4x_i2c.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,11 @@ int16_t scd4x_start_low_power_periodic_measurement(void);
260260
* scd4x_get_data_ready_status() - Check whether new measurement data is
261261
* available for read-out.
262262
*
263-
* @param data_ready If last 11 bits are 0 data not ready, else data ready
263+
* @param data_ready_flag true if data is available, false otherwise.
264264
*
265265
* @return 0 on success, an error code otherwise
266266
*/
267-
int16_t scd4x_get_data_ready_status(uint16_t* data_ready);
267+
int16_t scd4x_get_data_ready_flag(bool* data_ready_flag);
268268

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

scd4x_i2c_example_usage.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,17 @@ int main(void) {
7171
printf("Waiting for first measurement... (5 sec)\n");
7272

7373
for (;;) {
74-
// Read Measurement
75-
sensirion_i2c_hal_sleep_usec(5000000);
76-
74+
// Read Measurement if data is available
75+
bool data_ready_flag = false;
76+
sensirion_i2c_hal_sleep_usec(100000);
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+
}
7785
uint16_t co2;
7886
float temperature;
7987
float humidity;

0 commit comments

Comments
 (0)