+ switch (imu_type) {
+ case imu_type_telemega_v1_v2:
+ case imu_type_telemega_v3:
+ case imu_type_easymega_v1:
+ return gyro_y;
+ case imu_type_easymega_v2:
+ case imu_type_telemega_v4:
+ case imu_type_easytimer_v1:
+ return gyro_x;
+ default:
+ return AltosLib.MISSING;
+ }
+ }
+
+ private int gyro_pitch(int imu_type) {
+ if (gyro_pitch != AltosLib.MISSING)
+ return gyro_pitch;
+
+ switch (imu_type) {
+ case imu_type_telemega_v1_v2:
+ case imu_type_telemega_v3:
+ case imu_type_easymega_v1:
+ return gyro_x;
+ case imu_type_easymega_v2:
+ return -gyro_y;
+ case imu_type_telemega_v4:
+ case imu_type_easytimer_v1:
+ return -gyro_y;
+ default:
+ return AltosLib.MISSING;
+ }
+ }
+
+ private int gyro_yaw(int imu_type) {
+ if (gyro_yaw != AltosLib.MISSING)
+ return gyro_yaw;
+
+ return gyro_z;
+ }
+
+ private int mag_across(int imu_type) {
+ if (mag_across != AltosLib.MISSING)
+ return mag_across;
+
+ switch (imu_type) {
+ case imu_type_telemega_v1_v2:
+ case imu_type_telemega_v3:
+ case imu_type_easymega_v1:
+ return mag_x;
+ case imu_type_easymega_v2:
+ return -mag_y;
+ case imu_type_telemega_v4:
+ case imu_type_easytimer_v1:
+ return mag_y;
+ default:
+ return AltosLib.MISSING;
+ }
+ }
+
+ private int mag_along(int imu_type) {
+ if (mag_along != AltosLib.MISSING)
+ return mag_along;
+
+ switch (imu_type) {
+ case imu_type_telemega_v1_v2:
+ case imu_type_telemega_v3:
+ case imu_type_easymega_v1:
+ return mag_y;
+ case imu_type_easymega_v2:
+ case imu_type_telemega_v4:
+ case imu_type_easytimer_v1:
+ return mag_x;
+ default:
+ return AltosLib.MISSING;
+ }
+ }
+
+ private int mag_through(int imu_type) {
+ if (mag_through != AltosLib.MISSING)
+ return mag_through;
+
+ return mag_z;
+ }
+
+ private static boolean is_primary_accel(int imu_type) {
+ switch (imu_type) {
+ case imu_type_easytimer_v1:
+ case imu_type_easytimer_v2:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ static public void provide_data(AltosDataListener listener, AltosLink link, int imu_type) throws InterruptedException {
+ try {
+ AltosIMU imu = new AltosIMU(link);
+ AltosCalData cal_data = listener.cal_data();
+
+ System.out.printf("imu_model %d mag_model %d\n", imu.imu_model, imu.mag_model);
+ if (imu_type != AltosLib.MISSING)
+ cal_data.set_imu_type(imu_type);
+ if (imu != null) {
+ if (imu.imu_model != AltosLib.MISSING)
+ cal_data.set_imu_model(imu.imu_model);
+ if (imu.mag_model != AltosLib.MISSING)
+ cal_data.set_mag_model(imu.mag_model);
+
+ if (imu.gyro_roll(imu_type) != AltosLib.MISSING) {
+ cal_data.set_gyro_zero(0, 0, 0);
+ listener.set_gyro(cal_data.gyro_roll(imu.gyro_roll(imu_type)),
+ cal_data.gyro_pitch(imu.gyro_pitch(imu_type)),
+ cal_data.gyro_yaw(imu.gyro_yaw(imu_type)));
+ }
+ listener.set_accel_ground(cal_data.accel_along(imu.accel_along(imu_type)),
+ cal_data.accel_across(imu.accel_across(imu_type)),
+ cal_data.accel_through(imu.accel_through(imu_type)));
+ listener.set_accel(cal_data.accel_along(imu.accel_along(imu_type)),
+ cal_data.accel_across(imu.accel_across(imu_type)),
+ cal_data.accel_through(imu.accel_through(imu_type)));
+ if (is_primary_accel(imu_type)) {
+ int accel = imu.accel_along(imu_type);
+ if (!cal_data.adxl375_inverted)
+ accel = -accel;
+ if (cal_data.pad_orientation == 1)
+ accel = -accel;
+ listener.set_acceleration(cal_data.acceleration(accel));
+ }
+ if (imu.mag_along(imu_type) != AltosLib.MISSING) {
+ listener.set_mag(cal_data.mag_along(imu.mag_along(imu_type)),
+ cal_data.mag_across(imu.mag_across(imu_type)),
+ cal_data.mag_through(imu.mag_through(imu_type)));
+ }
+ }
+ } catch (TimeoutException te) {
+ }
+ }
+
+ public AltosIMU() {