diff --git a/components/flow3r_bsp/flow3r_bsp_imu.h b/components/flow3r_bsp/flow3r_bsp_imu.h index 06489bf12d8ac73a67f083631b7ac668529528d3..b119db2b327854d0005547934ee5f6cffeb70199 100644 --- a/components/flow3r_bsp/flow3r_bsp_imu.h +++ b/components/flow3r_bsp/flow3r_bsp_imu.h @@ -14,6 +14,15 @@ typedef struct { uint8_t dev_addr; } flow3r_bsp_imu_t; +// Init the IMU to default settings +// +// 100 Hz sample rate, 2 g range esp_err_t flow3r_bsp_imu_init(flow3r_bsp_imu_t *imu); + +// Query the IMU for an accelerometer reading. +// +// This directly calls the I2C bus and need to lock the bus for that. +// Returns ESP_ERR_NOT_FOUND if there is no new reading available. +// Return values in m/s. esp_err_t flow3r_bsp_imu_read_acc_mps(flow3r_bsp_imu_t *imu, float *x, float *y, float *z); diff --git a/components/micropython/usermodule/mp_imu.c b/components/micropython/usermodule/mp_imu.c index fa08f821b4d0de6ac02e9460a0f6eb7540e1e862..7289f30a95828f5aa9f98fe3684430a3fe154867 100644 --- a/components/micropython/usermodule/mp_imu.c +++ b/components/micropython/usermodule/mp_imu.c @@ -4,20 +4,14 @@ #include "py/runtime.h" STATIC mp_obj_t mp_imu_acc_read(void) { - float x, y, z; + static float x, y, z; - esp_err_t ret = st3m_imu_read_acc_mps(&x, &y, &z); + // Will not overwrite old data if there is an error + st3m_imu_read_acc_mps(&x, &y, &z); - if (ret == ESP_OK) { - mp_obj_t items[3] = { mp_obj_new_float(x), mp_obj_new_float(y), - mp_obj_new_float(z) }; - return mp_obj_new_tuple(3, items); - } else if (ret == ESP_ERR_NOT_FOUND) { - return mp_const_none; - } - - // TODO: raise exception here - return mp_const_none; + mp_obj_t items[3] = { mp_obj_new_float(x), mp_obj_new_float(y), + mp_obj_new_float(z) }; + return mp_obj_new_tuple(3, items); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_imu_acc_read_obj, mp_imu_acc_read);