first cut at turnon scripts for EasyTimer v2
[fw/altos] / src / drivers / ao_lco_bits.c
1 /*
2  * Copyright © 2018 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  */
14
15 #include <ao.h>
16 #include <ao_lco.h>
17 #include <ao_radio_cmac.h>
18
19 uint8_t         ao_lco_debug;
20
21 int8_t          ao_lco_pad;
22 int16_t         ao_lco_box;
23
24 uint8_t         ao_lco_armed;                                   /* arm active */
25 uint8_t         ao_lco_firing;                                  /* fire active */
26
27 int16_t         ao_lco_min_box, ao_lco_max_box;
28
29 uint8_t         ao_lco_pretending;
30
31 #if AO_LCO_DRAG
32 uint8_t         ao_lco_drag_race;
33 #endif
34
35 struct ao_pad_query     ao_pad_query;                           /* latest query response */
36
37 static uint8_t          ao_lco_channels[AO_PAD_MAX_BOXES];      /* pad channels available on each box */
38 static uint16_t         ao_lco_tick_offset[AO_PAD_MAX_BOXES];   /* 16 bit offset from local to remote tick count */
39 static uint8_t          ao_lco_selected[AO_PAD_MAX_BOXES];      /* pads selected to fire */
40
41 uint8_t         ao_lco_valid[AO_PAD_MAX_BOXES];         /* AO_LCO_VALID bits per box */
42
43 static const AO_LED_TYPE        continuity_led[AO_LED_CONTINUITY_NUM] = {
44 #ifdef AO_LED_CONTINUITY_0
45         AO_LED_CONTINUITY_0,
46 #endif
47 #ifdef AO_LED_CONTINUITY_1
48         AO_LED_CONTINUITY_1,
49 #endif
50 #ifdef AO_LED_CONTINUITY_2
51         AO_LED_CONTINUITY_2,
52 #endif
53 #ifdef AO_LED_CONTINUITY_3
54         AO_LED_CONTINUITY_3,
55 #endif
56 #ifdef AO_LED_CONTINUITY_4
57         AO_LED_CONTINUITY_4,
58 #endif
59 #ifdef AO_LED_CONTINUITY_5
60         AO_LED_CONTINUITY_5,
61 #endif
62 #ifdef AO_LED_CONTINUITY_6
63         AO_LED_CONTINUITY_6,
64 #endif
65 #ifdef AO_LED_CONTINUITY_7
66         AO_LED_CONTINUITY_7,
67 #endif
68 };
69
70 /* Set LEDs to match remote box status */
71 void
72 ao_lco_igniter_status(void)
73 {
74         uint8_t         c;
75         uint8_t         t = 0;
76
77         for (;;) {
78 #if AO_LCO_DRAG
79                 if (ao_lco_drag_race)
80                         ao_sleep_for(&ao_pad_query, AO_MS_TO_TICKS(50));
81                 else
82 #endif
83                         ao_sleep(&ao_pad_query);
84                 if (ao_lco_box_pseudo(ao_lco_box)) {
85                         ao_led_off(AO_LED_GREEN|AO_LED_AMBER|AO_LED_RED);
86                         continue;
87                 }
88                 PRINTD("RSSI %d VALID %d\n", ao_radio_cmac_rssi, ao_lco_valid[ao_lco_box]);
89                 if (!(ao_lco_valid[ao_lco_box] & AO_LCO_VALID_LAST)) {
90                         ao_led_on(AO_LED_RED);
91                         ao_led_off(AO_LED_GREEN|AO_LED_AMBER);
92                         continue;
93                 }
94                 if (ao_radio_cmac_rssi < -90) {
95                         ao_led_on(AO_LED_AMBER);
96                         ao_led_off(AO_LED_RED|AO_LED_GREEN);
97                 } else {
98                         ao_led_on(AO_LED_GREEN);
99                         ao_led_off(AO_LED_RED|AO_LED_AMBER);
100                 }
101                 if (ao_pad_query.arm_status)
102                         ao_led_on(AO_LED_REMOTE_ARM);
103                 else
104                         ao_led_off(AO_LED_REMOTE_ARM);
105
106                 for (c = 0; c < AO_LED_CONTINUITY_NUM; c++) {
107                         uint8_t status;
108
109                         if (ao_pad_query.channels & (1 << c))
110                                 status = ao_pad_query.igniter_status[c];
111                         else
112                                 status = AO_PAD_IGNITER_STATUS_NO_IGNITER_RELAY_OPEN;
113
114 #if AO_LCO_DRAG
115                         if (ao_lco_drag_race && (ao_lco_selected[ao_lco_box] & (1 << c))) {
116                                 uint8_t on = 0;
117                                 if (status == AO_PAD_IGNITER_STATUS_GOOD_IGNITER_RELAY_OPEN) {
118                                         if (t)
119                                                 on = 1;
120                                 } else {
121                                         if (t == 1)
122                                                 on = 1;
123                                 }
124                                 if (on)
125                                         ao_led_on(continuity_led[c]);
126                                 else
127                                         ao_led_off(continuity_led[c]);
128                         } else
129 #endif
130                         {
131                                 if (status == AO_PAD_IGNITER_STATUS_GOOD_IGNITER_RELAY_OPEN)
132                                         ao_led_on(continuity_led[c]);
133                                 else
134                                         ao_led_off(continuity_led[c]);
135                         }
136                 }
137                 t = (t + 1) & 3;
138         }
139 }
140
141 uint8_t
142 ao_lco_pad_present(int16_t box, int8_t pad)
143 {
144         /* voltage measurement is always valid */
145         if (ao_lco_pad_pseudo(pad))
146                 return 1;
147         if (!ao_lco_channels[box])
148                 return 0;
149         if (pad > AO_PAD_MAX_CHANNELS)
150                 return 0;
151         return (ao_lco_channels[box] >> (pad - 1)) & 1;
152 }
153
154 int8_t
155 ao_lco_pad_first(int16_t box)
156 {
157         int8_t  pad;
158
159         for (pad = 1; pad <= AO_PAD_MAX_CHANNELS; pad++)
160                 if (ao_lco_pad_present(box, pad))
161                         return pad;
162         return 0;
163 }
164
165 static uint8_t
166 ao_lco_get_channels(int16_t box, struct ao_pad_query *query)
167 {
168         int8_t                  r;
169
170         r = ao_lco_query((uint16_t) box, query, &ao_lco_tick_offset[box]);
171         if (r == AO_RADIO_CMAC_OK) {
172                 ao_lco_channels[box] = query->channels;
173                 ao_lco_valid[box] = AO_LCO_VALID_LAST | AO_LCO_VALID_EVER;
174         } else
175                 ao_lco_valid[box] &= (uint8_t) ~AO_LCO_VALID_LAST;
176         PRINTD("ao_lco_get_channels(%d) rssi %d valid %d ret %d offset %d\n", box, ao_radio_cmac_rssi, ao_lco_valid[box], r, ao_lco_tick_offset[box]);
177         ao_wakeup(&ao_pad_query);
178         return ao_lco_valid[box];
179 }
180
181 void
182 ao_lco_update(void)
183 {
184         if (ao_lco_box_pseudo(ao_lco_box)) {
185                 ao_lco_show();
186                 return;
187         }
188
189         uint8_t previous_valid = ao_lco_valid[ao_lco_box];
190
191         if (ao_lco_get_channels(ao_lco_box, &ao_pad_query) & AO_LCO_VALID_LAST) {
192                 if (!(previous_valid & AO_LCO_VALID_EVER)) {
193                         if (!ao_lco_pad_pseudo(ao_lco_pad))
194                                 ao_lco_set_pad(ao_lco_pad_first(ao_lco_box));
195                 }
196                 if (ao_lco_pad_pseudo(ao_lco_pad))
197                         ao_lco_show();
198         }
199 }
200
201 uint8_t ao_lco_box_mask[AO_LCO_MASK_SIZE(AO_PAD_MAX_BOXES)];
202
203 static void
204 ao_lco_box_reset_present(void)
205 {
206         ao_lco_min_box = 0xff;
207         ao_lco_max_box = 0x00;
208         ao_lco_pretending = 0;
209         memset(ao_lco_box_mask, 0, sizeof (ao_lco_box_mask));
210 }
211
212 static void
213 ao_lco_box_set_present(int16_t box)
214 {
215         if (box < ao_lco_min_box)
216                 ao_lco_min_box = box;
217         if (box > ao_lco_max_box)
218                 ao_lco_max_box = box;
219         if (box >= AO_PAD_MAX_BOXES)
220                 return;
221         ao_lco_box_mask[AO_LCO_MASK_ID(box)] |= (uint8_t) (1 << AO_LCO_MASK_SHIFT(box));
222 }
223
224 void
225 ao_lco_set_pad(int8_t new_pad)
226 {
227         ao_lco_pad = new_pad;
228         ao_lco_show();
229 }
230
231 void
232 ao_lco_set_box(int16_t new_box)
233 {
234         ao_lco_box = new_box;
235         if (!ao_lco_box_pseudo(ao_lco_box)) {
236                 if (ao_lco_box < AO_PAD_MAX_BOXES) {
237                         if (ao_lco_pretending)
238                                 ao_lco_channels[ao_lco_box] = 0xff;
239                         else
240                                 ao_lco_channels[ao_lco_box] = 0;
241                 }
242         }
243         ao_lco_pad = 1;
244         ao_lco_show();
245 }
246
247 void
248 ao_lco_step_pad(int8_t dir)
249 {
250         int16_t new_pad;
251
252         switch (ao_lco_box) {
253 #ifdef AO_LCO_HAS_CONTRAST
254         case AO_LCO_CONTRAST: {
255                 int32_t contrast = ao_lco_get_contrast();
256
257                 contrast = (contrast + AO_LCO_CONTRAST_STEP - 1) / AO_LCO_CONTRAST_STEP;
258                 contrast += dir;
259                 contrast *= AO_LCO_CONTRAST_STEP;
260                 if (contrast < AO_LCO_MIN_CONTRAST)
261                         contrast = AO_LCO_MIN_CONTRAST;
262                 if (contrast > AO_LCO_MAX_CONTRAST)
263                         contrast = AO_LCO_MAX_CONTRAST;
264                 ao_lco_set_contrast(contrast);
265                 ao_lco_show();
266                 break;
267         }
268 #endif
269 #ifdef AO_LCO_HAS_BACKLIGHT
270         case AO_LCO_BACKLIGHT: {
271                 int32_t backlight = ao_lco_get_backlight();
272
273                 backlight = (backlight + AO_LCO_BACKLIGHT_STEP - 1) / AO_LCO_BACKLIGHT_STEP;
274                 backlight += dir;
275                 backlight *= AO_LCO_BACKLIGHT_STEP;
276                 if (backlight < AO_LCO_MIN_BACKLIGHT)
277                         backlight = AO_LCO_MIN_BACKLIGHT;
278                 if (backlight > AO_LCO_MAX_BACKLIGHT)
279                         backlight = AO_LCO_MAX_BACKLIGHT;
280                 ao_lco_set_backlight(backlight);
281                 ao_lco_show();
282                 break;
283         }
284 #endif
285 #ifdef AO_LCO_HAS_INFO
286         case AO_LCO_INFO: {
287 #if AO_LCO_MIN_INFO_PAGE < AO_LCO_MAX_INFO_PAGE
288                 int32_t info_page = ao_lco_get_info_page();
289
290                 info += dir;
291                 if (info_page < AO_LCO_MIN_INFO_PAGE)
292                         info_page = AO_LCO_MIN_INFO_PAGE;
293                 if (info_page > AO_LCO_MAX_INFO_PAGE)
294                         info_page = AO_LCO_MAX_INFO_PAGE;
295                 ao_lco_set_info_page();
296 #endif
297                 break;
298         }
299 #endif
300         default:
301                 new_pad = (int16_t) ao_lco_pad;
302                 do {
303                         new_pad += dir;
304                         if (new_pad > AO_PAD_MAX_CHANNELS)
305                                 new_pad = AO_LCO_PAD_FIRST;
306                         if (new_pad < AO_LCO_PAD_FIRST)
307                                 new_pad = AO_PAD_MAX_CHANNELS;
308                         if (new_pad == ao_lco_pad)
309                                 break;
310                 } while (!ao_lco_pad_present(ao_lco_box, (int8_t) new_pad));
311                 PRINTD("New pad %d\n", new_pad);
312                 ao_lco_set_pad((int8_t) new_pad);
313                 break;
314         }
315 }
316
317 uint8_t
318 ao_lco_box_present(int16_t box)
319 {
320         if (ao_lco_box_pseudo(box))
321                 return 1;
322         if (box >= AO_PAD_MAX_BOXES)
323                 return 0;
324         return (ao_lco_box_mask[AO_LCO_MASK_ID(box)] >> AO_LCO_MASK_SHIFT(box)) & 1;
325 }
326
327 void
328 ao_lco_step_box(int8_t dir)
329 {
330         int16_t new_box = ao_lco_box;
331
332         do {
333                 new_box += dir;
334                 if (new_box > ao_lco_max_box)
335                         new_box = AO_LCO_BOX_FIRST;
336                 else if (new_box < AO_LCO_BOX_FIRST)
337                         new_box = ao_lco_max_box;
338                 if (new_box == ao_lco_box)
339                         break;
340         } while (!ao_lco_box_present(new_box));
341         PRINTD("New box %d\n", new_box);
342         ao_lco_set_box(new_box);
343 }
344
345 void
346 ao_lco_set_armed(uint8_t armed)
347 {
348         if (ao_lco_box_pseudo(ao_lco_box))
349                 return;
350
351         ao_lco_armed = armed;
352         PRINTD("Armed %d\n", ao_lco_armed);
353         if (ao_lco_armed) {
354 #if AO_LCO_DRAG
355                 if (ao_lco_drag_race) {
356                         int16_t box;
357
358                         for (box = ao_lco_min_box; box <= ao_lco_max_box; box++)
359                                 if (ao_lco_selected[box])
360                                         break;
361                         if (box > ao_lco_max_box)
362                                 ao_lco_armed = 0;
363                 } else
364 #endif
365                 {
366                         memset(ao_lco_selected, 0, sizeof (ao_lco_selected));
367                         if (ao_lco_pad != 0)
368                                 ao_lco_selected[ao_lco_box] = (1 << (ao_lco_pad - 1));
369                         else
370                                 ao_lco_armed = 0;
371                 }
372         }
373         ao_wakeup(&ao_lco_armed);
374 }
375
376 void
377 ao_lco_set_firing(uint8_t firing)
378 {
379         ao_lco_firing = firing;
380         PRINTD("Firing %d\n", ao_lco_firing);
381         ao_wakeup(&ao_lco_armed);
382 }
383
384 #if 0
385 static int16_t fake_boxes[] = {
386         1, 2, 3, 5, 8, 11, 13, 17, 19, 23, 29, 31, 37, 62, 97
387 };
388 #define ARRAYSIZE(a)    (sizeof(a) / sizeof((a)[0]))
389 #define NFAKE ARRAYSIZE(fake_boxes)
390
391 static bool
392 is_fake(int16_t box)
393 {
394         unsigned i;
395         for (i = 0; i < NFAKE; i++)
396                 if (fake_boxes[i] == box)
397                         return true;
398         return false;
399 }
400 #else
401 #define is_fake(b)      false
402 #endif
403
404 void
405 ao_lco_search(void)
406 {
407         int8_t          r;
408         int8_t          try;
409         int16_t         box;
410         uint16_t        boxes = 0;
411
412         ao_lco_box_reset_present();
413 #ifdef AO_LCO_SEARCH_API
414         ao_lco_search_start();
415 #else
416         ao_lco_show_box(0);
417         ao_lco_show_pad(0);
418 #endif
419         for (box = 0; box < AO_PAD_MAX_BOXES; box++) {
420 #ifdef AO_LCO_SEARCH_API
421                 ao_lco_search_box_check(box);
422 #else
423                 if ((box % 10) == 0)
424                         ao_lco_show_box(box);
425 #endif
426                 for (try = 0; try < 3; try++) {
427                         ao_lco_tick_offset[box] = 0;
428                         r = ao_lco_query((uint16_t) box, &ao_pad_query, &ao_lco_tick_offset[box]);
429                         PRINTD("box %d result %d offset %d\n", box, r, ao_lco_tick_offset[box]);
430                         if (r == AO_RADIO_CMAC_OK || is_fake(box)) {
431                                 ++boxes;
432                                 ao_lco_box_set_present(box);
433 #ifdef AO_LCO_SEARCH_API
434                                 ao_lco_search_box_present(box);
435 #else
436                                 ao_lco_show_pad((int8_t) (boxes % 10));
437 #endif
438                                 ao_delay(AO_MS_TO_TICKS(30));
439                                 break;
440                         }
441                 }
442         }
443         if (ao_lco_min_box <= ao_lco_max_box)
444                 ao_lco_box = ao_lco_min_box;
445         else
446                 ao_lco_min_box = ao_lco_max_box = ao_lco_box = 0;
447         memset(ao_lco_valid, 0, sizeof (ao_lco_valid));
448         memset(ao_lco_channels, 0, sizeof (ao_lco_channels));
449 #ifdef AO_LCO_SEARCH_API
450         ao_lco_search_done();
451 #endif
452         ao_lco_set_box(ao_lco_min_box);
453 }
454
455 void
456 ao_lco_pretend(void)
457 {
458         int16_t box;
459
460         ao_lco_pretending = 1;
461         ao_lco_min_box = 1;
462         ao_lco_max_box = AO_PAD_MAX_BOXES - 1;
463         for (box = ao_lco_min_box; box <= ao_lco_max_box; box++)
464                 ao_lco_box_set_present(box);
465         ao_lco_box = ao_lco_min_box;
466         memset(ao_lco_valid, 0, sizeof (ao_lco_valid));
467         memset(ao_lco_channels, 0, sizeof (ao_lco_channels));
468         ao_lco_set_box(ao_lco_min_box);
469 }
470
471 void
472 ao_lco_monitor(void)
473 {
474         AO_TICK_TYPE    delay;
475         int16_t         box;
476
477         for (;;) {
478                 PRINTD("monitor armed %d firing %d\n",
479                        ao_lco_armed, ao_lco_firing);
480
481                 if (ao_lco_armed && ao_lco_firing) {
482                         ao_lco_ignite(AO_PAD_FIRE);
483                 } else {
484                         ao_lco_update();
485                         if (ao_lco_armed) {
486                                 for (box = ao_lco_min_box; box <= ao_lco_max_box; box++) {
487                                         if (ao_lco_selected[box]) {
488                                                 PRINTD("Arming box %d pads %x\n",
489                                                        box, ao_lco_selected[box]);
490                                                 if (ao_lco_valid[box] & AO_LCO_VALID_EVER) {
491                                                         ao_lco_arm((uint16_t) box, ao_lco_selected[box], ao_lco_tick_offset[box]);
492                                                         ao_delay(AO_MS_TO_TICKS(10));
493                                                 }
494                                         }
495                                 }
496                         }
497                 }
498                 if (ao_lco_armed && ao_lco_firing)
499                         delay = AO_MS_TO_TICKS(100);
500                 else
501                         delay = AO_SEC_TO_TICKS(1);
502                 ao_sleep_for(&ao_lco_armed, delay);
503         }
504 }
505
506 #if AO_LCO_DRAG
507
508 int8_t                  ao_lco_drag_beep_count;
509 static uint8_t          ao_lco_drag_beep_on;
510 static AO_TICK_TYPE     ao_lco_drag_beep_time;
511 static AO_TICK_TYPE     ao_lco_drag_warn_time;
512
513 #define AO_LCO_DRAG_BEEP_TIME   AO_MS_TO_TICKS(50)
514 #define AO_LCO_DRAG_WARN_TIME   AO_SEC_TO_TICKS(5)
515
516 /* Request 'beeps' additional drag race beeps */
517 void
518 ao_lco_drag_add_beeps(int8_t beeps)
519 {
520         PRINTD("beep %d\n", beeps);
521         if (ao_lco_drag_beep_count == 0)
522                 ao_lco_drag_beep_time = ao_time();
523         ao_lco_drag_beep_count += beeps;
524         ao_wakeup(&ao_lco_drag_beep_count);
525 }
526
527 /* Toggle current pad in drag set */
528 void
529 ao_lco_toggle_drag(void)
530 {
531         if (ao_lco_drag_race && !ao_lco_pad_pseudo(ao_lco_pad) && !ao_lco_box_pseudo(ao_lco_box)) {
532                 ao_lco_selected[ao_lco_box] ^= (uint8_t) (1 << (ao_lco_pad - 1));
533                 PRINTD("Toggle box %d pad %d (pads now %x) to drag race\n",
534                        ao_lco_pad, ao_lco_box, ao_lco_selected[ao_lco_box]);
535                 ao_lco_drag_add_beeps(ao_lco_pad);
536         }
537 }
538
539 /* Check whether it's time to change the beeper status, then either
540  * turn it on or off as necessary and bump the remaining beep counts
541  */
542
543 AO_TICK_TYPE
544 ao_lco_drag_beep_check(AO_TICK_TYPE now, AO_TICK_TYPE delay)
545 {
546         PRINTD("beep check count %d delta %ld\n",
547                ao_lco_drag_beep_count,
548                (long) (AO_TICK_SIGNED) (now - ao_lco_drag_beep_time));
549         if (ao_lco_drag_beep_count) {
550                 if ((AO_TICK_SIGNED) (now - ao_lco_drag_beep_time) >= 0) {
551                         if (ao_lco_drag_beep_on) {
552                                 ao_beep(0);
553                                 PRINTD("beep stop\n");
554                                 ao_lco_drag_beep_on = 0;
555                                 if (ao_lco_drag_beep_count) {
556                                         --ao_lco_drag_beep_count;
557                                         if (ao_lco_drag_beep_count)
558                                                 ao_lco_drag_beep_time = now + AO_LCO_DRAG_BEEP_TIME;
559                                 }
560                         } else {
561                                 ao_beep(AO_BEEP_HIGH);
562                                 PRINTD("beep start\n");
563                                 ao_lco_drag_beep_on = 1;
564                                 ao_lco_drag_beep_time = now + AO_LCO_DRAG_BEEP_TIME;
565                         }
566                 }
567         }
568
569         if (ao_lco_drag_beep_count) {
570                 AO_TICK_TYPE beep_delay = 0;
571
572                 if (ao_lco_drag_beep_time > now)
573                         beep_delay = ao_lco_drag_beep_time - now;
574
575                 if (delay > beep_delay)
576                         delay = beep_delay;
577         }
578         return delay;
579 }
580
581 void
582 ao_lco_drag_enable(void)
583 {
584         if (!ao_lco_drag_race) {
585                 PRINTD("Drag enable\n");
586                 ao_lco_drag_race = 1;
587                 memset(ao_lco_selected, 0, sizeof (ao_lco_selected));
588 #ifdef AO_LED_DRAG
589                 ao_led_on(AO_LED_DRAG);
590 #endif
591                 ao_lco_drag_add_beeps(5);
592                 ao_lco_show();
593         }
594 }
595
596 void
597 ao_lco_drag_disable(void)
598 {
599         if (ao_lco_drag_race) {
600                 PRINTD("Drag disable\n");
601                 ao_lco_drag_race = 0;
602 #ifdef AO_LED_DRAG
603                 ao_led_off(AO_LED_DRAG);
604 #endif
605                 memset(ao_lco_selected, 0, sizeof (ao_lco_selected));
606                 ao_lco_drag_add_beeps(2);
607                 ao_lco_show();
608         }
609 }
610
611 /* add a beep if it's time to warn the user that drag race mode is
612  * active
613  */
614
615 AO_TICK_TYPE
616 ao_lco_drag_warn_check(AO_TICK_TYPE now, AO_TICK_TYPE delay)
617 {
618         if (ao_lco_drag_race) {
619                 AO_TICK_TYPE    warn_delay;
620
621                 if ((AO_TICK_SIGNED) (now - ao_lco_drag_warn_time) >= 0) {
622                         ao_lco_drag_add_beeps(1);
623                         ao_lco_drag_warn_time = now + AO_LCO_DRAG_WARN_TIME;
624                 }
625                 warn_delay = ao_lco_drag_warn_time - now;
626                 if (delay > warn_delay)
627                         delay = warn_delay;
628         }
629         return delay;
630 }
631 #endif /* AO_LCO_DRAG */
632
633 /* task function for beeping while arm is active */
634 void
635 ao_lco_arm_warn(void)
636 {
637         for (;;) {
638                 while (!ao_lco_armed) {
639 #ifdef AO_LED_FIRE
640                         ao_led_off(AO_LED_FIRE);
641 #endif
642                         ao_sleep(&ao_lco_armed);
643                 }
644 #ifdef AO_LED_FIRE
645                 ao_led_on(AO_LED_FIRE);
646 #endif
647                 ao_beep_for(AO_BEEP_MID, AO_MS_TO_TICKS(200));
648                 ao_delay(AO_MS_TO_TICKS(200));
649         }
650 }