-static AO_LED_TYPE continuity_led[AO_LED_CONTINUITY_NUM] = {
-#ifdef AO_LED_CONTINUITY_0
- AO_LED_CONTINUITY_0,
-#endif
-#ifdef AO_LED_CONTINUITY_1
- AO_LED_CONTINUITY_1,
-#endif
-#ifdef AO_LED_CONTINUITY_2
- AO_LED_CONTINUITY_2,
-#endif
-#ifdef AO_LED_CONTINUITY_3
- AO_LED_CONTINUITY_3,
-#endif
-#ifdef AO_LED_CONTINUITY_4
- AO_LED_CONTINUITY_4,
-#endif
-#ifdef AO_LED_CONTINUITY_5
- AO_LED_CONTINUITY_5,
-#endif
-#ifdef AO_LED_CONTINUITY_6
- AO_LED_CONTINUITY_6,
-#endif
-#ifdef AO_LED_CONTINUITY_7
- AO_LED_CONTINUITY_7,
-#endif
-};
-
-static uint8_t
-ao_lco_get_channels(uint8_t box, struct ao_pad_query *query)
-{
- int8_t r;
-
- r = ao_lco_query(box, query, &ao_lco_tick_offset[box]);
- if (r == AO_RADIO_CMAC_OK) {
- ao_lco_channels[box] = query->channels;
- ao_lco_valid[box] = AO_LCO_VALID_LAST | AO_LCO_VALID_EVER;
- } else
- ao_lco_valid[box] &= ~AO_LCO_VALID_LAST;
- 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]);
- ao_wakeup(&ao_pad_query);
- return ao_lco_valid[box];
-}
-
-static void
-ao_lco_update(void)
-{
- uint8_t previous_valid = ao_lco_valid[ao_lco_box];
-
- if (ao_lco_get_channels(ao_lco_box, &ao_pad_query) & AO_LCO_VALID_LAST) {
- if (!(previous_valid & AO_LCO_VALID_EVER)) {
- if (ao_lco_pad != 0)
- ao_lco_pad = ao_lco_pad_first(ao_lco_box);
- ao_lco_set_display();
- }
- if (ao_lco_pad == 0)
- ao_lco_set_display();
- }
-}
-
-static void
-ao_lco_box_reset_present(void)
-{
- ao_lco_min_box = 0xff;
- ao_lco_max_box = 0x00;
- memset(ao_lco_box_mask, 0, sizeof (ao_lco_box_mask));
-}
-
-static void
-ao_lco_box_set_present(uint8_t box)
-{
- if (box < ao_lco_min_box)
- ao_lco_min_box = box;
- if (box > ao_lco_max_box)
- ao_lco_max_box = box;
- if (box >= AO_PAD_MAX_BOXES)
- return;
- ao_lco_box_mask[MASK_ID(box)] |= 1 << MASK_SHIFT(box);
-}
-
-static void
-ao_lco_search(void)
-{
- int8_t r;
- int8_t try;
- uint8_t box;
- uint8_t boxes = 0;
-
- ao_lco_box_reset_present();
- ao_lco_set_pad(0);
- for (box = 0; box < AO_PAD_MAX_BOXES; box++) {
- if ((box % 10) == 0)
- ao_lco_set_box(box);
- for (try = 0; try < 3; try++) {
- ao_lco_tick_offset[box] = 0;
- r = ao_lco_query(box, &ao_pad_query, &ao_lco_tick_offset[box]);
- PRINTD("box %d result %d offset %d\n", box, r, ao_lco_tick_offset[box]);
- if (r == AO_RADIO_CMAC_OK) {
- ++boxes;
- ao_lco_box_set_present(box);
- ao_lco_set_pad(boxes % 10);
- ao_delay(AO_MS_TO_TICKS(30));
- break;
- }
- }
- }
- if (ao_lco_min_box <= ao_lco_max_box)
- ao_lco_box = ao_lco_min_box;
- else
- ao_lco_min_box = ao_lco_max_box = ao_lco_box = 0;
- memset(ao_lco_valid, 0, sizeof (ao_lco_valid));
- memset(ao_lco_channels, 0, sizeof (ao_lco_channels));
- ao_lco_pad = 1;
- ao_lco_set_display();
-}
-