Skip to content
Snippets Groups Projects
Verified Commit f071178d authored by Jakub Vaněk's avatar Jakub Vaněk
Browse files

Turn ICM20608 off after being garbage-collected

parent 878a3add
Branches jv-robosoutez
No related tags found
No related merge requests found
Pipeline #66472 passed
......@@ -17,7 +17,7 @@ static void ICM20608_print(const mp_print_t *print, mp_obj_t self_in);
// Called on ICM20608 init
STATIC mp_obj_t ICM20608_make_new(const mp_obj_type_t* type, size_t n_args, size_t n_kw, const mp_obj_t* args) {
ICM20608_obj_t *self = m_new_obj(ICM20608_obj_t);
ICM20608_obj_t *self = m_new_obj_with_finaliser(ICM20608_obj_t);
self->base.type = type;
self->icm = (ICM20608G_t*)malloc(sizeof(ICM20608G_t));
opencube_lock_i2c_or_raise();
......@@ -31,7 +31,11 @@ static void ICM20608_print(const mp_print_t *print, mp_obj_t self_in) {
}
STATIC mp_obj_t ICM20608_read_value(mp_obj_t self_in) {
ICM20608_obj_t *self = MP_OBJ_TO_PTR(self_in);
ICM20608_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->icm == NULL) {
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("ICM20608 has been deinitialized already"));
}
float accel_x, accel_y, accel_z, gyro_x, gyro_y, gyro_z;
opencube_lock_i2c_or_raise();
ICM20608G_read_data(self->icm,
......@@ -63,6 +67,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(ICM20608_deinit_obj, ICM20608_deinit);
STATIC const mp_rom_map_elem_t ICM20608_locals_dict[] = {
{ MP_ROM_QSTR(MP_QSTR_read_value), MP_ROM_PTR(&ICM20608_read_value_obj) },
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&ICM20608_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&ICM20608_deinit_obj) },
};
STATIC MP_DEFINE_CONST_DICT(ICM20608_locals_dict_obj, ICM20608_locals_dict);
......
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