Skip to content
Snippets Groups Projects
Commit 6c30041b authored by schneider's avatar schneider
Browse files

imu: don't forward imu errors into mpy

parent a359276a
No related branches found
No related tags found
1 merge request!25BMI270 acc support
Pipeline #5919 passed
......@@ -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);
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment