File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -131,16 +131,23 @@ static void motion_spi_write(uint8_t reg, uint8_t value) {
131131 GPIOA -> BSRR = GPIO_BSRR_BS_4 ;
132132}
133133
134+ static void motion_get_acceleration (int8_t * data ) {
135+ motion_spi_read (OUT_Y_H , (uint8_t * )& data [0 ]);
136+ motion_spi_read (OUT_Z_H , (uint8_t * )& data [2 ]);
137+ motion_spi_read (OUT_X_H , (uint8_t * )& data [1 ]);
138+ data [1 ] = - data [1 ];
139+ }
140+
134141STATIC mp_obj_t hubs_MoveHub_IMU_acceleration (mp_obj_t self_in ) {
135142
136- uint8_t data [3 ];
137- motion_spi_read (OUT_X_H , & data [0 ]);
138- motion_spi_read (OUT_Y_H , & data [1 ]);
139- motion_spi_read (OUT_Z_H , & data [2 ]);
143+ // Gets signed acceleration data
144+ int8_t data [3 ];
145+ motion_get_acceleration (data );
140146
147+ // Convert to appropriate units and return as tuple
141148 mp_obj_t values [3 ];
142149 for (uint8_t i = 0 ; i < 3 ; i ++ ) {
143- values [i ] = MP_OBJ_NEW_SMALL_INT (((( int8_t ) data [i ]) * 10 ) >> 6 );
150+ values [i ] = MP_OBJ_NEW_SMALL_INT ((data [i ] * 10 ) >> 6 );
144151 }
145152 return mp_obj_new_tuple (3 , values );
146153}
You can’t perform that action at this time.
0 commit comments