From 0d545981dca8a838e93b5e2915e2d50852cfbfd0 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Mon, 18 Nov 2024 10:34:26 +0000 Subject: [PATCH 1/3] SCD4X: Bump submodule to master. --- drivers/scd4x/src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scd4x/src b/drivers/scd4x/src index bcbb21903..3b413b9c8 160000 --- a/drivers/scd4x/src +++ b/drivers/scd4x/src @@ -1 +1 @@ -Subproject commit bcbb2190324d9d39ae38619dd4a8931a0b8cf049 +Subproject commit 3b413b9c804dd7c4df11178e9cf2501b6f61fa2e From b79814cae300eb155a499ce450029924a5a220f0 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Mon, 18 Nov 2024 10:42:56 +0000 Subject: [PATCH 2/3] SCD4X: scd4x_get_data_ready_status to scd4x_get_data_ready_flag. The function name and behaviour has changed, moving the bitwise check into the API and making it an implementation detail. --- micropython/modules/breakout_scd41/breakout_scd41.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/micropython/modules/breakout_scd41/breakout_scd41.cpp b/micropython/modules/breakout_scd41/breakout_scd41.cpp index efc7bfc2e..f867f77b8 100644 --- a/micropython/modules/breakout_scd41/breakout_scd41.cpp +++ b/micropython/modules/breakout_scd41/breakout_scd41.cpp @@ -69,15 +69,15 @@ mp_obj_t scd41_get_data_ready() { mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG); return mp_const_none; } - uint16_t data_ready = 0; - int error = scd4x_get_data_ready_status(&data_ready); + bool data_ready = false; + int error = scd4x_get_data_ready_flag(&data_ready); if(error) { mp_raise_msg(&mp_type_RuntimeError, READ_FAIL_MSG); return mp_const_none; } // The datasheet doesn't really say *which* bit might be 1 if data is ready... // so check if the least significant eleven bits are != 0 - return (data_ready & 0x7ff) ? mp_const_true : mp_const_false; + return data_ready ? mp_const_true : mp_const_false; } mp_obj_t scd41_set_temperature_offset(mp_obj_t offset) { From 185bea2065a793c60e6fbbb67689c1f2e20c59a7 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Mon, 18 Nov 2024 10:55:48 +0000 Subject: [PATCH 3/3] SCD4X: Support low power periodic measurements. --- micropython/modules/breakout_scd41/breakout_scd41.c | 2 ++ .../modules/breakout_scd41/breakout_scd41.cpp | 13 +++++++++++++ micropython/modules/breakout_scd41/breakout_scd41.h | 1 + 3 files changed, 16 insertions(+) diff --git a/micropython/modules/breakout_scd41/breakout_scd41.c b/micropython/modules/breakout_scd41/breakout_scd41.c index 1ef15d871..9f7d8b8f5 100755 --- a/micropython/modules/breakout_scd41/breakout_scd41.c +++ b/micropython/modules/breakout_scd41/breakout_scd41.c @@ -13,6 +13,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(scd41_init_obj, 0, scd41_init); // Start/Stop measurement, no args (module-level, so no "self") static MP_DEFINE_CONST_FUN_OBJ_0(scd41_start_periodic_measurement_obj, scd41_start_periodic_measurement); +static MP_DEFINE_CONST_FUN_OBJ_0(scd41_start_low_power_periodic_measurement_obj, scd41_start_low_power_periodic_measurement); static MP_DEFINE_CONST_FUN_OBJ_0(scd41_stop_periodic_measurement_obj, scd41_stop_periodic_measurement); static MP_DEFINE_CONST_FUN_OBJ_0(scd41_get_data_ready_obj, scd41_get_data_ready); @@ -30,6 +31,7 @@ static const mp_map_elem_t scd41_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_breakout_scd41) }, { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&scd41_init_obj) }, { MP_ROM_QSTR(MP_QSTR_start), MP_ROM_PTR(&scd41_start_periodic_measurement_obj) }, + { MP_ROM_QSTR(MP_QSTR_start_low_power), MP_ROM_PTR(&scd41_start_low_power_periodic_measurement_obj) }, { MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&scd41_stop_periodic_measurement_obj) }, { MP_ROM_QSTR(MP_QSTR_measure), MP_ROM_PTR(&scd41_read_measurement_obj) }, { MP_ROM_QSTR(MP_QSTR_ready), MP_ROM_PTR(&scd41_get_data_ready_obj) }, diff --git a/micropython/modules/breakout_scd41/breakout_scd41.cpp b/micropython/modules/breakout_scd41/breakout_scd41.cpp index f867f77b8..46c4cdd88 100644 --- a/micropython/modules/breakout_scd41/breakout_scd41.cpp +++ b/micropython/modules/breakout_scd41/breakout_scd41.cpp @@ -64,6 +64,19 @@ mp_obj_t scd41_start_periodic_measurement() { return mp_const_none; } +mp_obj_t scd41_start_low_power_periodic_measurement() { + if(!scd41_initialised) { + mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG); + return mp_const_none; + } + int error = scd4x_start_low_power_periodic_measurement(); + if(error) { + mp_raise_msg(&mp_type_RuntimeError, FAIL_MSG); + } + + return mp_const_none; +} + mp_obj_t scd41_get_data_ready() { if(!scd41_initialised) { mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG); diff --git a/micropython/modules/breakout_scd41/breakout_scd41.h b/micropython/modules/breakout_scd41/breakout_scd41.h index a02c24486..478100cd9 100644 --- a/micropython/modules/breakout_scd41/breakout_scd41.h +++ b/micropython/modules/breakout_scd41/breakout_scd41.h @@ -5,6 +5,7 @@ // Declare the functions we'll make available in Python extern mp_obj_t scd41_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); extern mp_obj_t scd41_start_periodic_measurement(); +extern mp_obj_t scd41_start_low_power_periodic_measurement(); extern mp_obj_t scd41_stop_periodic_measurement(); extern mp_obj_t scd41_read_measurement(); extern mp_obj_t scd41_get_data_ready();