altos: Added check for out of bounds accel
authorMike Beattie <mike@ethernal.org>
Sat, 15 Jan 2011 11:10:30 +0000 (00:10 +1300)
committerKeith Packard <keithp@keithp.com>
Sun, 16 Jan 2011 22:35:29 +0000 (14:35 -0800)
Chose invalid flight mode instead of idle to give user feedback.

Signed-off-by: Mike Beattie <mike@ethernal.org>
src/ao_flight.c

index 5a9a8d8..01dbb11 100644 (file)
@@ -237,9 +237,18 @@ ao_flight(void)
                                ao_flight_state = ao_flight_pad;
                                ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
                        } else {
-                               ao_flight_state = ao_flight_idle;
+                               if (ao_flight_accel < ao_config.accel_plus_g - ACCEL_NOSE_UP ||
+                                   ao_flight_accel > ao_config.accel_minus_g + ACCEL_NOSE_UP)
+                               {
+                                       /* Detected an accel value outside -1.5g to 1.5g
+                                        * -> invalid mode
+                                        */
+                                       ao_flight_state = ao_flight_invalid;
+                               } else {
+                                       ao_flight_state = ao_flight_idle;
+                               }
 
-                               /* Turn on packet system in idle mode
+                               /* Turn on packet system in idle or invalid mode
                                 */
                                ao_packet_slave_start();
                                ao_wakeup(DATA_TO_XDATA(&ao_flight_state));