Rewrite mgos_imu_*_create_i2c() to its new API format

This commit is contained in:
Pim van Pelt
2019-03-28 16:21:27 +01:00
parent d0ad1bdc91
commit 26827db6b6

View File

@ -19,20 +19,31 @@ static struct mgos_imu *s_imu = NULL;
#endif
bool test_imu_create(void) {
struct mgos_imu_acc_opts acc_opts;
struct mgos_imu_gyro_opts gyro_opts;
struct mgos_imu_mag_opts mag_opts;
if (!(s_imu = mgos_imu_create())) {
LOG(LL_ERROR, ("Cannot create IMU"));
return false;
}
if (ACC_I2CADDR > 0 && !mgos_imu_accelerometer_create_i2c(s_imu, mgos_i2c_get_global(), ACC_I2CADDR, ACC_TYPE)) {
acc_opts.type = ACC_TYPE;
acc_opts.scale = 16.0; // G
acc_opts.odr = 100; // Hz
if (ACC_I2CADDR > 0 && !mgos_imu_accelerometer_create_i2c(s_imu, mgos_i2c_get_global(), ACC_I2CADDR, &acc_opts))
LOG(LL_ERROR, ("Cannot create accelerometer on IMU"));
}
if (GYRO_I2CADDR > 0 && !mgos_imu_gyroscope_create_i2c(s_imu, mgos_i2c_get_global(), GYRO_I2CADDR, GYRO_TYPE)) {
gyro_opts.type = ACC_TYPE;
gyro_opts.scale = 2000; // deg/sec
gyro_opts.odr = 100; // Hz
if (GYRO_I2CADDR > 0 && !mgos_imu_gyroscope_create_i2c(s_imu, mgos_i2c_get_global(), GYRO_I2CADDR, &gyro_opts))
LOG(LL_ERROR, ("Cannot create gyroscope on IMU"));
}
if (MAG_I2CADDR > 0 && !mgos_imu_magnetometer_create_i2c(s_imu, mgos_i2c_get_global(), MAG_I2CADDR, MAG_TYPE)) {
mag_opts.type = MAG_TYPE;
mag_opts.scale = 12.0; // Gauss
mag_opts.odr = 10; // Hz
if (MAG_I2CADDR > 0 && !mgos_imu_magnetometer_create_i2c(s_imu, mgos_i2c_get_global(), MAG_I2CADDR, &mag_opts))
LOG(LL_ERROR, ("Cannot create magnetometer on IMU"));
}
return true;
}