altos: Send SPI message at flight state changes
authorKeith Packard <keithp@keithp.com>
Sat, 13 Aug 2011 04:41:25 +0000 (21:41 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 14 Aug 2011 01:46:12 +0000 (18:46 -0700)
Get the companion board starting its data logging as soon as possible
after boost starts.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/ao.h
src/ao_companion.c

index de47f3df2f22242e344e6454101f01de5ff89790..b14b65f2f3fd4e5e90752fefb3547818e58a9bf2 100644 (file)
--- a/src/ao.h
+++ b/src/ao.h
@@ -1581,6 +1581,7 @@ ao_btm_init(void);
 
 #define AO_COMPANION_SETUP             1
 #define AO_COMPANION_FETCH             2
+#define AO_COMPANION_NOTIFY            3
 
 struct ao_companion_command {
        uint8_t         command;
index f54f5251afb92135065306493ab77c2ba7e8e689..f0ce3f129c306bfa1a44c0d6350f8bbd5a983a90 100644 (file)
@@ -68,13 +68,24 @@ ao_companion_get_data(void)
        COMPANION_DESELECT();
 }
 
+static void
+ao_companion_notify(void)
+{
+       COMPANION_SELECT();
+       ao_companion_send_command(AO_COMPANION_NOTIFY);
+       COMPANION_DESELECT();
+}
+
 void
 ao_companion(void)
 {
        ao_companion_running = ao_companion_get_setup();
        while (ao_companion_running) {
-               ao_delay(ao_companion_setup.update_period);
-               ao_companion_get_data();
+               ao_alarm(ao_companion_setup.update_period);
+               if (ao_sleep(DATA_TO_XDATA(&ao_flight_state)))
+                       ao_companion_get_data();
+               else
+                       ao_companion_notify();
        }
        ao_exit();
 }