The lco common code doesn't need to share its internal values with the
world; make most of them static.
Signed-off-by: Keith Packard <keithp@keithp.com>
#define AO_LCO_DRAG_RACE_START_TIME AO_SEC_TO_TICKS(5)
#define AO_LCO_DRAG_RACE_STOP_TIME AO_SEC_TO_TICKS(2)
#define AO_LCO_DRAG_RACE_START_TIME AO_SEC_TO_TICKS(5)
#define AO_LCO_DRAG_RACE_STOP_TIME AO_SEC_TO_TICKS(2)
-#define AO_LCO_VALID_LAST 1
-#define AO_LCO_VALID_EVER 2
+#define AO_LCO_BOX_DRAG 0x1000
/* UI values */
static uint16_t ao_lco_fire_tick;
/* UI values */
static uint16_t ao_lco_fire_tick;
#define AO_LCO_DRAG 1
#endif
#define AO_LCO_DRAG 1
#endif
-#if AO_LCO_DRAG
-#define AO_LCO_BOX_DRAG 0x1000
-#endif
-
#define DEBUG 1
#if DEBUG
#define DEBUG 1
#if DEBUG
#define PRINTD(...)
#endif
#define PRINTD(...)
#endif
extern uint8_t ao_lco_drag_race; /* TRUE when drag race mode enabled */
extern uint8_t ao_lco_drag_race; /* TRUE when drag race mode enabled */
extern uint8_t ao_lco_pad; /* Currently selected pad */
extern int16_t ao_lco_box; /* Currently selected box */
extern uint8_t ao_lco_pad; /* Currently selected pad */
extern int16_t ao_lco_box; /* Currently selected box */
-extern uint8_t ao_lco_armed;
-extern uint8_t ao_lco_firing;
+extern uint8_t ao_lco_armed; /* armed mode active */
+extern uint8_t ao_lco_firing; /* fire button pressed */
extern struct ao_pad_query ao_pad_query; /* Last received QUERY from pad */
extern struct ao_pad_query ao_pad_query; /* Last received QUERY from pad */
-#define AO_LCO_VALID_LAST 1
-#define AO_LCO_VALID_EVER 2
-
#define AO_LCO_PAD_VOLTAGE 0 /* Pad number to show box voltage */
extern uint8_t ao_lco_min_box, ao_lco_max_box;
#define AO_LCO_PAD_VOLTAGE 0 /* Pad number to show box voltage */
extern uint8_t ao_lco_min_box, ao_lco_max_box;
-extern uint8_t ao_lco_selected[AO_PAD_MAX_BOXES];
-extern uint8_t ao_lco_valid[AO_PAD_MAX_BOXES];
-extern uint8_t ao_lco_channels[AO_PAD_MAX_BOXES];
-extern uint16_t ao_lco_tick_offset[AO_PAD_MAX_BOXES];
#define AO_LCO_MASK_SIZE(n) (((n) + 7) >> 3)
#define AO_LCO_MASK_ID(n) ((n) >> 3)
#define AO_LCO_MASK_SIZE(n) (((n) + 7) >> 3)
#define AO_LCO_MASK_ID(n) ((n) >> 3)
uint8_t ao_lco_pad;
int16_t ao_lco_box;
uint8_t ao_lco_pad;
int16_t ao_lco_box;
-uint8_t ao_lco_drag_race;
-uint8_t ao_lco_armed; /* arm active */
-uint8_t ao_lco_firing; /* fire active */
+uint8_t ao_lco_armed; /* arm active */
+uint8_t ao_lco_firing; /* fire active */
uint8_t ao_lco_min_box, ao_lco_max_box;
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];
-struct ao_pad_query ao_pad_query;
+#if AO_LCO_DRAG
+uint8_t ao_lco_drag_race;
+#endif
+
+struct ao_pad_query ao_pad_query; /* latest query response */
-static AO_LED_TYPE continuity_led[AO_LED_CONTINUITY_NUM] = {
+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]; /* offset from local to remote tick count */
+static uint8_t ao_lco_selected[AO_PAD_MAX_BOXES]; /* pads selected to fire */
+
+#define AO_LCO_VALID_LAST 1
+#define AO_LCO_VALID_EVER 2
+
+static uint8_t ao_lco_valid[AO_PAD_MAX_BOXES]; /* AO_LCO_VALID bits per box */
+
+static const AO_LED_TYPE continuity_led[AO_LED_CONTINUITY_NUM] = {
#ifdef AO_LED_CONTINUITY_0
AO_LED_CONTINUITY_0,
#endif
#ifdef AO_LED_CONTINUITY_0
AO_LED_CONTINUITY_0,
#endif
uint8_t t = 0;
for (;;) {
uint8_t t = 0;
for (;;) {
if (ao_lco_drag_race)
ao_sleep_for(&ao_pad_query, AO_MS_TO_TICKS(50));
else
if (ao_lco_drag_race)
ao_sleep_for(&ao_pad_query, AO_MS_TO_TICKS(50));
else
ao_sleep(&ao_pad_query);
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_sleep(&ao_pad_query);
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)) {
else
status = AO_PAD_IGNITER_STATUS_NO_IGNITER_RELAY_OPEN;
else
status = AO_PAD_IGNITER_STATUS_NO_IGNITER_RELAY_OPEN;
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) {
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]);
ao_led_on(continuity_led[c]);
else
ao_led_off(continuity_led[c]);
if (status == AO_PAD_IGNITER_STATUS_GOOD_IGNITER_RELAY_OPEN)
ao_led_on(continuity_led[c]);
else
if (status == AO_PAD_IGNITER_STATUS_GOOD_IGNITER_RELAY_OPEN)
ao_led_on(continuity_led[c]);
else
ao_lco_set_box(uint16_t new_box)
{
ao_lco_box = new_box;
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
+ if (ao_lco_box < AO_PAD_MAX_BOXES)
ao_lco_channels[ao_lco_box] = 0;
ao_lco_pad = 1;
ao_lco_show();
ao_lco_channels[ao_lco_box] = 0;
ao_lco_pad = 1;
ao_lco_show();
ao_lco_armed = armed;
PRINTD("Armed %d\n", ao_lco_armed);
if (ao_lco_armed) {
ao_lco_armed = armed;
PRINTD("Armed %d\n", ao_lco_armed);
if (ao_lco_armed) {
if (ao_lco_drag_race) {
uint8_t box;
if (ao_lco_drag_race) {
uint8_t box;
break;
if (box > ao_lco_max_box)
ao_lco_armed = 0;
break;
if (box > ao_lco_max_box)
ao_lco_armed = 0;
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));
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));