+ while (ao_flight_adc != ao_adc_head) {
+ __pdata uint8_t ticks;
+ __pdata int16_t ao_vel_change;
+ ao_flight_prev_tick = ao_flight_tick;
+
+ /* Capture a sample */
+ ao_raw_accel = ao_adc_ring[ao_flight_adc].accel;
+ ao_raw_pres = ao_adc_ring[ao_flight_adc].pres;
+ ao_flight_tick = ao_adc_ring[ao_flight_adc].tick;
+
+ /* Update velocity
+ *
+ * The accelerometer is mounted so that
+ * acceleration yields negative values
+ * while deceleration yields positive values,
+ * so subtract instead of add.
+ */
+ ticks = ao_flight_tick - ao_flight_prev_tick;
+ ao_vel_change = (((ao_raw_accel + ao_raw_accel_prev) >> 1) - ao_ground_accel);
+ ao_raw_accel_prev = ao_raw_accel;
+
+ /* one is a common interval */
+ if (ticks == 1)
+ ao_flight_vel -= (int32_t) ao_vel_change;
+ else
+ ao_flight_vel -= (int32_t) ao_vel_change * (int32_t) ticks;
+
+ ao_flight_adc = ao_adc_ring_next(ao_flight_adc);
+ }