1
- #include " mpu6050.hpp"
2
- #include " pico/binary_info.h"
3
- #include " hardware/i2c.h"
4
- #include " mpu6050_i2c.h"
5
-
6
- /* MPU6050::MPU6050() : //TODO: is there a good way to do this
7
- chip_temp(*temp) {
8
- accel = {0., 0., 0.};
9
- gyro = {0., 0., 0.};
10
- temp = {};
11
- MPU6050(accel, gyro, temp);
12
- } */
13
-
14
- MPU6050::MPU6050 (float *accel_out, float *gyro_out) :
15
- accel(accel_out), gyro(gyro_out), chip_temp(temp) {
16
- accel_scale = 0 ;
17
- gyro_scale = 0 ;
18
- // I2C init
19
- i2c_init (i2c_default, 400 * 1000 ); // Max bus speed 400 kHz
20
- gpio_set_function (PICO_DEFAULT_I2C_SDA_PIN, GPIO_FUNC_I2C);
21
- gpio_set_function (PICO_DEFAULT_I2C_SCL_PIN, GPIO_FUNC_I2C);
22
- gpio_pull_up (PICO_DEFAULT_I2C_SDA_PIN);
23
- gpio_pull_up (PICO_DEFAULT_I2C_SCL_PIN);
24
- }
25
-
26
- void MPU6050::power (uint8_t CLKSEL, bool temp_disable, bool sleep, bool cycle) {
27
- mpu6050_power (CLKSEL, temp_disable, sleep, cycle);
28
- }
29
-
30
- void MPU6050::reset (void ) {
31
- mpu6050_reset ();
32
- }
33
-
34
- void MPU6050::setscale_accel (uint8_t scale_num) {
35
- accel_scale = scale_num & 3 ;
36
- mpu6050_setscale_accel ((MPU6050_Scale)accel_scale);
37
- }
38
-
39
- void MPU6050::setscale_gyro (uint8_t scale_num) {
40
- gyro_scale = scale_num & 3 ;
41
- mpu6050_setscale_gyro ((MPU6050_Scale)gyro_scale);
42
- }
43
-
44
- void MPU6050::read (void ) {
45
- mpu6050_read (accel, gyro, &temp, (MPU6050_Scale)accel_scale, (MPU6050_Scale)gyro_scale);
46
- }
1
+ #include " mpu6050.hpp"
2
+ #include " pico/binary_info.h"
3
+ #include " hardware/i2c.h"
4
+ #include " mpu6050_i2c.h"
5
+
6
+ /* MPU6050::MPU6050() : //TODO: smart pointers
7
+ chip_temp(*temp) {
8
+ accel = {0., 0., 0.};
9
+ gyro = {0., 0., 0.};
10
+ temp = {};
11
+ MPU6050(accel, gyro, temp);
12
+ } */
13
+
14
+ MPU6050::MPU6050 (float *accel_out, float *gyro_out) :
15
+ accel(accel_out), gyro(gyro_out), chip_temp(temp) {
16
+ accel_scale = 0 ;
17
+ gyro_scale = 0 ;
18
+ setup_MPU6050_i2c ();
19
+ }
20
+
21
+ void MPU6050::power (uint8_t CLKSEL, bool temp_disable, bool sleep, bool cycle) {
22
+ mpu6050_power (CLKSEL, temp_disable, sleep, cycle);
23
+ }
24
+
25
+ void MPU6050::reset (void ) {
26
+ mpu6050_reset ();
27
+ }
28
+
29
+ void MPU6050::setscale_accel (uint8_t scale_num) {
30
+ accel_scale = scale_num & 3 ;
31
+ mpu6050_setscale_accel ((MPU6050_Scale)accel_scale);
32
+ }
33
+
34
+ void MPU6050::setscale_gyro (uint8_t scale_num) {
35
+ gyro_scale = scale_num & 3 ;
36
+ mpu6050_setscale_gyro ((MPU6050_Scale)gyro_scale);
37
+ }
38
+
39
+ void MPU6050::read (void ) {
40
+ mpu6050_read (accel, gyro, &temp, (MPU6050_Scale)accel_scale, (MPU6050_Scale)gyro_scale);
41
+ }
47
42
0 commit comments