Rewrite mgos_imu_*_create_i2c() to its new API format
This commit is contained in:
23
tests/imu.c
23
tests/imu.c
@ -19,20 +19,31 @@ static struct mgos_imu *s_imu = NULL;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool test_imu_create(void) {
|
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())) {
|
if (!(s_imu = mgos_imu_create())) {
|
||||||
LOG(LL_ERROR, ("Cannot create IMU"));
|
LOG(LL_ERROR, ("Cannot create IMU"));
|
||||||
return false;
|
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"));
|
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"));
|
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"));
|
LOG(LL_ERROR, ("Cannot create magnetometer on IMU"));
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user