altos: Move comment in ao_sleep_for next to related code
[fw/altos] / src / kernel / ao_flight.c
index 24099347ce4466589592c4d49ffc78775de867fe..9ba02bb8b24e8cc9b872e3e84a205daf1bba96db 100644 (file)
 #error Please define HAS_USB
 #endif
 
+#if HAS_FAKE_FLIGHT
+#include <ao_fake_flight.h>
+#endif
+
 #ifndef HAS_TELEMETRY
 #define HAS_TELEMETRY  HAS_RADIO
 #endif
@@ -56,10 +60,10 @@ __xdata uint8_t                     ao_sensor_errors;
  * resting
  */
 static __data uint16_t         ao_interval_end;
-static __data int16_t          ao_interval_min_height;
-static __data int16_t          ao_interval_max_height;
+static __data ao_v_t           ao_interval_min_height;
+static __data ao_v_t           ao_interval_max_height;
 #if HAS_ACCEL
-static __data int16_t          ao_coast_avg_accel;
+static __data ao_v_t           ao_coast_avg_accel;
 #endif
 
 __pdata uint8_t                        ao_flight_force_idle;
@@ -130,7 +134,10 @@ ao_flight(void)
                                /* Disable the USB controller in flight mode
                                 * to save power
                                 */
-                               ao_usb_disable();
+#if HAS_FAKE_FLIGHT
+                               if (!ao_fake_flight_active)
+#endif
+                                       ao_usb_disable();
 #endif
 
 #if !HAS_ACCEL && PACKET_HAS_SLAVE
@@ -170,7 +177,6 @@ ao_flight(void)
 
                        break;
                case ao_flight_pad:
-
                        /* pad to boost:
                         *
                         * barometer: > 20m vertical motion
@@ -364,8 +370,10 @@ ao_flight(void)
                                {
                                        ao_flight_state = ao_flight_landed;
 
+#if HAS_ADC
                                        /* turn off the ADC capture */
                                        ao_timer_set_adc_interval(0);
+#endif
 
                                        ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
                                }
@@ -392,14 +400,14 @@ ao_flight(void)
 }
 
 #if HAS_FLIGHT_DEBUG
-static inline int int_part(int16_t i)  { return i >> 4; }
-static inline int frac_part(int16_t i) { return ((i & 0xf) * 100 + 8) / 16; }
+static inline int int_part(ao_v_t i)   { return i >> 4; }
+static inline int frac_part(ao_v_t i)  { return ((i & 0xf) * 100 + 8) / 16; }
 
 static void
 ao_flight_dump(void)
 {
 #if HAS_ACCEL
-       int16_t accel;
+       ao_v_t  accel;
 
        accel = ((ao_config.accel_plus_g - ao_sample_accel) * ao_accel_scale) >> 16;
 #endif