Keep reporting flight state while it changes
authorKeith Packard <keithp@keithp.com>
Wed, 15 Apr 2009 04:24:25 +0000 (21:24 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 15 Apr 2009 04:24:25 +0000 (21:24 -0700)
ao_report.c

index 1cc883b..0753df4 100644 (file)
@@ -38,10 +38,12 @@ static const char * __xdata flight_reports[] = {
 #endif
 #define pause(time)    ao_delay(time)
 
+static __xdata enum ao_flight_state ao_report_state;
+
 static void
-ao_report_state(void)
+ao_report_beep(void)
 {
-       char *r = flight_reports[ao_flight_state];
+       char *r = flight_reports[ao_report_state];
        char c;
 
        if (!r)
@@ -53,22 +55,26 @@ ao_report_state(void)
                        signal(AO_MS_TO_TICKS(600));
                pause(AO_MS_TO_TICKS(200));
        }
+       pause(AO_MS_TO_TICKS(400));
 }
 
-static __xdata ao_report_wait;
-
 void
 ao_report_notify(void)
 {
-       ao_wakeup(&ao_report_wait);
+       ao_wakeup(&ao_report_state);
 }
 
 void
 ao_report(void)
 {
+       ao_report_state = ao_flight_state;
        for(;;) {
-               ao_report_state();
-               ao_sleep(&ao_report_wait);
+               ao_report_beep();
+               __critical {
+                       while (ao_report_state == ao_flight_state)
+                               ao_sleep(&ao_report_state);
+                       ao_report_state = ao_flight_state;
+               }
        }
 }