From 26827db6b6d50484d17a565b2f210f14fd716ec4 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Thu, 28 Mar 2019 16:21:27 +0100 Subject: [PATCH] Rewrite mgos_imu_*_create_i2c() to its new API format --- tests/imu.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/imu.c b/tests/imu.c index 38f1ce4..894422c 100644 --- a/tests/imu.c +++ b/tests/imu.c @@ -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; }