uint8_t ao_lco_debug;
uint8_t ao_lco_pad;
-int16_t ao_lco_box;
+uint16_t ao_lco_box;
+
+uint8_t ao_lco_armed; /* arm active */
+uint8_t ao_lco_firing; /* fire active */
+
+uint16_t ao_lco_min_box, ao_lco_max_box;
+
+uint8_t ao_lco_pretending;
+
+#if AO_LCO_DRAG
uint8_t ao_lco_drag_race;
+#endif
+
+struct ao_pad_query ao_pad_query; /* latest query response */
-uint8_t ao_lco_armed; /* arm active */
-uint8_t ao_lco_firing; /* fire active */
+static uint8_t ao_lco_channels[AO_PAD_MAX_BOXES]; /* pad channels available on each box */
+static uint16_t ao_lco_tick_offset[AO_PAD_MAX_BOXES]; /* 16 bit offset from local to remote tick count */
+static uint8_t ao_lco_selected[AO_PAD_MAX_BOXES]; /* pads selected to fire */
-uint8_t ao_lco_min_box, ao_lco_max_box;
-uint8_t ao_lco_selected[AO_PAD_MAX_BOXES];
-uint8_t ao_lco_valid[AO_PAD_MAX_BOXES];
-uint8_t ao_lco_channels[AO_PAD_MAX_BOXES];
-uint16_t ao_lco_tick_offset[AO_PAD_MAX_BOXES];
+#define AO_LCO_VALID_LAST 1
+#define AO_LCO_VALID_EVER 2
-struct ao_pad_query ao_pad_query;
+static uint8_t ao_lco_valid[AO_PAD_MAX_BOXES]; /* AO_LCO_VALID bits per box */
-static AO_LED_TYPE continuity_led[AO_LED_CONTINUITY_NUM] = {
+static const AO_LED_TYPE continuity_led[AO_LED_CONTINUITY_NUM] = {
#ifdef AO_LED_CONTINUITY_0
AO_LED_CONTINUITY_0,
#endif
uint8_t t = 0;
for (;;) {
+#if AO_LCO_DRAG
if (ao_lco_drag_race)
ao_sleep_for(&ao_pad_query, AO_MS_TO_TICKS(50));
else
+#endif
ao_sleep(&ao_pad_query);
+ if (ao_lco_box_pseudo(ao_lco_box)) {
+ ao_led_off(AO_LED_GREEN|AO_LED_AMBER|AO_LED_RED);
+ continue;
+ }
PRINTD("RSSI %d VALID %d\n", ao_radio_cmac_rssi, ao_lco_valid[ao_lco_box]);
if (!(ao_lco_valid[ao_lco_box] & AO_LCO_VALID_LAST)) {
ao_led_on(AO_LED_RED);
else
status = AO_PAD_IGNITER_STATUS_NO_IGNITER_RELAY_OPEN;
+#if AO_LCO_DRAG
if (ao_lco_drag_race && (ao_lco_selected[ao_lco_box] & (1 << c))) {
uint8_t on = 0;
if (status == AO_PAD_IGNITER_STATUS_GOOD_IGNITER_RELAY_OPEN) {
ao_led_on(continuity_led[c]);
else
ao_led_off(continuity_led[c]);
- } else {
+ } else
+#endif
+ {
if (status == AO_PAD_IGNITER_STATUS_GOOD_IGNITER_RELAY_OPEN)
ao_led_on(continuity_led[c]);
else
}
uint8_t
-ao_lco_pad_present(uint8_t box, uint8_t pad)
+ao_lco_pad_present(uint16_t box, uint8_t pad)
{
/* voltage measurement is always valid */
if (pad == AO_LCO_PAD_VOLTAGE)
}
uint8_t
-ao_lco_pad_first(uint8_t box)
+ao_lco_pad_first(uint16_t box)
{
uint8_t pad;
}
static uint8_t
-ao_lco_get_channels(uint8_t box, struct ao_pad_query *query)
+ao_lco_get_channels(uint16_t box, struct ao_pad_query *query)
{
int8_t r;
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;
+ ao_lco_valid[box] &= (uint8_t) ~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];
void
ao_lco_update(void)
{
+ if (ao_lco_box_pseudo(ao_lco_box)) {
+ ao_lco_show();
+ return;
+ }
+
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) {
ao_lco_set_pad(ao_lco_pad_first(ao_lco_box));
}
if (ao_lco_pad == AO_LCO_PAD_VOLTAGE)
- ao_lco_show_display();
+ ao_lco_show();
}
}
{
ao_lco_min_box = 0xff;
ao_lco_max_box = 0x00;
+ ao_lco_pretending = 0;
memset(ao_lco_box_mask, 0, sizeof (ao_lco_box_mask));
}
static void
-ao_lco_box_set_present(uint8_t box)
+ao_lco_box_set_present(uint16_t box)
{
if (box < ao_lco_min_box)
ao_lco_min_box = box;
ao_lco_max_box = box;
if (box >= AO_PAD_MAX_BOXES)
return;
- ao_lco_box_mask[AO_LCO_MASK_ID(box)] |= 1 << AO_LCO_MASK_SHIFT(box);
+ ao_lco_box_mask[AO_LCO_MASK_ID(box)] |= (uint8_t) (1 << AO_LCO_MASK_SHIFT(box));
}
void
ao_lco_set_pad(uint8_t new_pad)
{
ao_lco_pad = new_pad;
- ao_lco_show_display();
+ ao_lco_show();
}
void
ao_lco_set_box(uint16_t new_box)
{
ao_lco_box = new_box;
-#if AO_LCO_DRAG
- if (ao_lco_box != AO_LCO_BOX_DRAG)
-#endif
- ao_lco_channels[ao_lco_box] = 0;
+ if (!ao_lco_box_pseudo(ao_lco_box)) {
+ if (ao_lco_box < AO_PAD_MAX_BOXES) {
+ if (ao_lco_pretending)
+ ao_lco_channels[ao_lco_box] = 0xff;
+ else
+ ao_lco_channels[ao_lco_box] = 0;
+ }
+ }
ao_lco_pad = 1;
- ao_lco_show_display();
+ ao_lco_show();
}
void
ao_lco_step_pad(int8_t dir)
{
- int8_t new_pad;
+ int16_t new_pad;
- new_pad = ao_lco_pad;
+ new_pad = (int16_t) ao_lco_pad;
do {
new_pad += dir;
if (new_pad > AO_PAD_MAX_CHANNELS)
new_pad = AO_PAD_MAX_CHANNELS;
if (new_pad == ao_lco_pad)
break;
- } while (!ao_lco_pad_present(ao_lco_box, new_pad));
- ao_lco_set_pad(new_pad);
+ } while (!ao_lco_pad_present(ao_lco_box, (uint8_t) new_pad));
+ PRINTD("New pad %d\n", new_pad);
+ ao_lco_set_pad((uint8_t) new_pad);
+}
+
+uint8_t
+ao_lco_box_present(uint16_t box)
+{
+ if (ao_lco_box_pseudo(box))
+ return 1;
+ if (box >= AO_PAD_MAX_BOXES)
+ return 0;
+ return (ao_lco_box_mask[AO_LCO_MASK_ID(box)] >> AO_LCO_MASK_SHIFT(box)) & 1;
+}
+
+void
+ao_lco_step_box(int8_t dir)
+{
+ int32_t new_box = (int32_t) ao_lco_box;
+
+ do {
+ new_box += dir;
+ if (new_box > ao_lco_max_box)
+ new_box = AO_LCO_BOX_FIRST;
+ else if (new_box < 0)
+ new_box = ao_lco_max_box;
+ if (new_box == ao_lco_box)
+ break;
+ } while (!ao_lco_box_present((uint16_t) new_box));
+ PRINTD("New box %ld\n", new_box);
+ ao_lco_set_box((uint16_t) new_box);
}
void
ao_lco_set_armed(uint8_t armed)
{
+ if (ao_lco_box_pseudo(ao_lco_box))
+ return;
+
ao_lco_armed = armed;
PRINTD("Armed %d\n", ao_lco_armed);
if (ao_lco_armed) {
+#if AO_LCO_DRAG
if (ao_lco_drag_race) {
- uint8_t box;
+ uint16_t box;
for (box = ao_lco_min_box; box <= ao_lco_max_box; box++)
if (ao_lco_selected[box])
break;
if (box > ao_lco_max_box)
ao_lco_armed = 0;
- } else {
+ } else
+#endif
+ {
memset(ao_lco_selected, 0, sizeof (ao_lco_selected));
if (ao_lco_pad != 0)
ao_lco_selected[ao_lco_box] = (1 << (ao_lco_pad - 1));
{
int8_t r;
int8_t try;
- uint8_t box;
- uint8_t boxes = 0;
+ uint16_t box;
+ uint16_t boxes = 0;
ao_lco_box_reset_present();
- ao_lco_set_pad(0);
+#ifdef AO_LCO_SEARCH_API
+ ao_lco_search_start();
+#else
+ ao_lco_show_box(0);
+ ao_lco_show_pad(0);
+#endif
for (box = 0; box < AO_PAD_MAX_BOXES; box++) {
- if ((box % 10) == 0) {
- ao_lco_box = box;
- ao_lco_show_display();
- }
+#ifdef AO_LCO_SEARCH_API
+ ao_lco_search_box_check(box);
+#else
+ if ((box % 10) == 0)
+ ao_lco_show_box(box);
+#endif
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]);
if (r == AO_RADIO_CMAC_OK) {
++boxes;
ao_lco_box_set_present(box);
- ao_lco_set_pad(boxes % 10);
+#ifdef AO_LCO_SEARCH_API
+ ao_lco_search_box_present(box);
+#else
+ ao_lco_show_pad((uint8_t) (boxes % 10));
+#endif
ao_delay(AO_MS_TO_TICKS(30));
break;
}
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));
+#ifdef AO_LCO_SEARCH_API
+ ao_lco_search_done();
+#endif
+ ao_lco_set_box(ao_lco_min_box);
+}
+
+void
+ao_lco_pretend(void)
+{
+ uint16_t box;
+
+ ao_lco_pretending = 1;
+ ao_lco_min_box = 1;
+ ao_lco_max_box = AO_PAD_MAX_BOXES - 1;
+ for (box = ao_lco_min_box; box <= ao_lco_max_box; box++)
+ ao_lco_box_set_present(box);
+ ao_lco_box = ao_lco_min_box;
+ memset(ao_lco_valid, 0, sizeof (ao_lco_valid));
+ memset(ao_lco_channels, 0, sizeof (ao_lco_channels));
ao_lco_set_box(ao_lco_min_box);
}
void
ao_lco_monitor(void)
{
- uint16_t delay;
- uint8_t box;
+ AO_TICK_TYPE delay;
+ uint16_t box;
for (;;) {
PRINTD("monitor armed %d firing %d\n",
uint8_t ao_lco_drag_beep_count;
static uint8_t ao_lco_drag_beep_on;
-static uint16_t ao_lco_drag_beep_time;
-static uint16_t ao_lco_drag_warn_time;
+static AO_TICK_TYPE ao_lco_drag_beep_time;
+static AO_TICK_TYPE ao_lco_drag_warn_time;
#define AO_LCO_DRAG_BEEP_TIME AO_MS_TO_TICKS(50)
#define AO_LCO_DRAG_WARN_TIME AO_SEC_TO_TICKS(5)
void
ao_lco_toggle_drag(void)
{
- if (ao_lco_drag_race && ao_lco_pad != AO_LCO_PAD_VOLTAGE) {
- ao_lco_selected[ao_lco_box] ^= (1 << (ao_lco_pad - 1));
+ if (ao_lco_drag_race && ao_lco_pad != AO_LCO_PAD_VOLTAGE && !ao_lco_box_pseudo(ao_lco_box)) {
+ ao_lco_selected[ao_lco_box] ^= (uint8_t) (1 << (ao_lco_pad - 1));
PRINTD("Toggle box %d pad %d (pads now %x) to drag race\n",
ao_lco_pad, ao_lco_box, ao_lco_selected[ao_lco_box]);
ao_lco_drag_add_beeps(ao_lco_pad);
* turn it on or off as necessary and bump the remaining beep counts
*/
-uint16_t
-ao_lco_drag_beep_check(uint16_t now, uint16_t delay)
+AO_TICK_TYPE
+ao_lco_drag_beep_check(AO_TICK_TYPE now, AO_TICK_TYPE delay)
{
- PRINTD("beep check count %d delta %d\n",
+ PRINTD("beep check count %d delta %ld\n",
ao_lco_drag_beep_count,
- (int16_t) (now - ao_lco_drag_beep_time));
+ (long) (AO_TICK_SIGNED) (now - ao_lco_drag_beep_time));
if (ao_lco_drag_beep_count) {
- if ((int16_t) (now - ao_lco_drag_beep_time) >= 0) {
+ if ((AO_TICK_SIGNED) (now - ao_lco_drag_beep_time) >= 0) {
if (ao_lco_drag_beep_on) {
ao_beep(0);
PRINTD("beep stop\n");
}
if (ao_lco_drag_beep_count) {
- uint16_t beep_delay = 0;
+ AO_TICK_TYPE beep_delay = 0;
if (ao_lco_drag_beep_time > now)
beep_delay = ao_lco_drag_beep_time - now;
ao_led_on(AO_LED_DRAG);
#endif
ao_lco_drag_add_beeps(5);
- ao_lco_show_display();
+ ao_lco_show();
}
}
#endif
memset(ao_lco_selected, 0, sizeof (ao_lco_selected));
ao_lco_drag_add_beeps(2);
- ao_lco_show_display();
+ ao_lco_show();
}
}
* active
*/
-uint16_t
-ao_lco_drag_warn_check(uint16_t now, uint16_t delay)
+AO_TICK_TYPE
+ao_lco_drag_warn_check(AO_TICK_TYPE now, AO_TICK_TYPE delay)
{
if (ao_lco_drag_race) {
- uint16_t warn_delay;
+ AO_TICK_TYPE warn_delay;
- if ((int16_t) (now - ao_lco_drag_warn_time) >= 0) {
+ if ((AO_TICK_SIGNED) (now - ao_lco_drag_warn_time) >= 0) {
ao_lco_drag_add_beeps(1);
ao_lco_drag_warn_time = now + AO_LCO_DRAG_WARN_TIME;
}