main.cpp 628 Bytes
Newer Older
1
2

#include "mbed.h"
3
4
5
6
7
8
9
10
#include "mbed_trace.h"
#include "GyroAttr.h"

#define TRACE_GROUP  "Main"

I2C i2c(I2C_SDA, I2C_SCL);
BMI160_I2C *imu = NULL;
GyroAttr *gyro = NULL;
11
12

int main() {
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
    char *js = NULL;

    mbed_trace_init();

    i2c.frequency(400000);
    imu = new BMI160_I2C(i2c, BMI160_I2C::I2C_ADRS_SDO_LO);
    gyro = new GyroAttr(imu);

    gyro->sensor_init();
    gyro->start_sensor_update(500);

    while(true) {

        js = cJSON_PrintUnformatted(gyro->get_gyro());

        if (js) {
            printf("%s\n", js);
            free(js);
        }

        ThisThread::sleep_for(2000);

    }

37
    return 0;
38

39
}