Skip to content

Commit 67837ff

Browse files
committed
pybricks.hubs.MoveHub.imu: update acceleration
Make it more similar to the other hubs, but without vectors.
1 parent 3f23016 commit 67837ff

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

pybricks/hubs/pb_type_movehub.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,26 +131,23 @@ static void motion_spi_write(uint8_t reg, uint8_t value) {
131131
GPIOA->BSRR = GPIO_BSRR_BS_4;
132132
}
133133

134-
STATIC mp_obj_t hubs_MoveHub_IMU_accel(mp_obj_t self_in) {
135-
hubs_MoveHub_IMU_obj_t *self = MP_OBJ_TO_PTR(self_in);
136-
(void)self;
134+
STATIC mp_obj_t hubs_MoveHub_IMU_acceleration(mp_obj_t self_in) {
137135

138136
uint8_t data[3];
139137
motion_spi_read(OUT_X_H, &data[0]);
140138
motion_spi_read(OUT_Y_H, &data[1]);
141139
motion_spi_read(OUT_Z_H, &data[2]);
142140

143141
mp_obj_t values[3];
144-
values[0] = mp_obj_new_int((int8_t)data[0]);
145-
values[1] = mp_obj_new_int((int8_t)data[1]);
146-
values[2] = mp_obj_new_int((int8_t)data[2]);
147-
142+
for (uint8_t i = 0; i < 3; i++) {
143+
values[i] = MP_OBJ_NEW_SMALL_INT((((int8_t)data[i]) * 10) >> 6);
144+
}
148145
return mp_obj_new_tuple(3, values);
149146
}
150-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(hubs_MoveHub_IMU_accel_obj, hubs_MoveHub_IMU_accel);
147+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(hubs_MoveHub_IMU_acceleration_obj, hubs_MoveHub_IMU_acceleration);
151148

152149
STATIC const mp_rom_map_elem_t hubs_MoveHub_IMU_locals_dict_table[] = {
153-
{ MP_ROM_QSTR(MP_QSTR_accel), MP_ROM_PTR(&hubs_MoveHub_IMU_accel_obj) },
150+
{ MP_ROM_QSTR(MP_QSTR_acceleration), MP_ROM_PTR(&hubs_MoveHub_IMU_acceleration_obj) },
154151
};
155152
STATIC MP_DEFINE_CONST_DICT(hubs_MoveHub_IMU_locals_dict, hubs_MoveHub_IMU_locals_dict_table);
156153

0 commit comments

Comments
 (0)