+#if HAS_GYRO
+__pdata int32_t ao_sample_accel_along_sum;
+__pdata int32_t ao_sample_accel_across_sum;
+__pdata int32_t ao_sample_accel_through_sum;
+__pdata int32_t ao_sample_pitch_sum;
+__pdata int32_t ao_sample_yaw_sum;
+__pdata int32_t ao_sample_roll_sum;
+#endif
+
+static void
+ao_sample_preflight_add(void)
+{
+#if HAS_ACCEL
+ ao_sample_accel_sum += ao_sample_accel;
+#endif
+ ao_sample_pres_sum += ao_sample_pres;
+#if HAS_GYRO
+ ao_sample_accel_along_sum += ao_sample_accel_along;
+ ao_sample_accel_across_sum += ao_sample_accel_across;
+ ao_sample_accel_through_sum += ao_sample_accel_through;
+ ao_sample_pitch_sum += ao_sample_pitch;
+ ao_sample_yaw_sum += ao_sample_yaw;
+ ao_sample_roll_sum += ao_sample_roll;
+#endif
+ ++nsamples;
+}
+
+static void
+ao_sample_preflight_set(void)
+{
+#if HAS_ACCEL
+ ao_ground_accel = ao_sample_accel_sum >> 9;
+ ao_sample_accel_sum = 0;
+#endif
+ ao_ground_pres = ao_sample_pres_sum >> 9;
+ ao_ground_height = pres_to_altitude(ao_ground_pres);
+ ao_sample_pres_sum = 0;
+#if HAS_GYRO
+ ao_ground_accel_along = ao_sample_accel_along_sum >> 9;
+ ao_ground_accel_across = ao_sample_accel_across_sum >> 9;
+ ao_ground_accel_through = ao_sample_accel_through_sum >> 9;
+ ao_ground_pitch = ao_sample_pitch_sum >> 9;
+ ao_ground_yaw = ao_sample_yaw_sum >> 9;
+ ao_ground_roll = ao_sample_roll_sum >> 9;
+ ao_sample_accel_along_sum = 0;
+ ao_sample_accel_across_sum = 0;
+ ao_sample_accel_through_sum = 0;
+ ao_sample_pitch_sum = 0;
+ ao_sample_yaw_sum = 0;
+ ao_sample_roll_sum = 0;
+ ao_sample_angle = 0;
+#endif
+ nsamples = 0;
+}