altos: Make fewer LCO variables public
authorKeith Packard <keithp@keithp.com>
Wed, 4 Jul 2018 19:34:38 +0000 (12:34 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 4 Jul 2018 19:34:38 +0000 (12:34 -0700)
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>
src/drivers/ao_lco.c
src/drivers/ao_lco.h
src/drivers/ao_lco_bits.c

index 47752f1f11647ee79f77ac133345b3faedf8c417..e892c8c045d3ad584edfc87c5149750f4935f7bf 100644 (file)
@@ -34,8 +34,7 @@
 #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;
index e528c2ad22b313080717e0987f0c2298e901d210..2958fbccc33cae7ec874b1edfaa66dc63e5f4aaf 100644 (file)
 #define AO_LCO_DRAG    1
 #endif
 
-#if AO_LCO_DRAG
-#define AO_LCO_BOX_DRAG                0x1000
-#endif
-
 #define DEBUG  1
 
 #if DEBUG
@@ -38,25 +34,21 @@ extern uint8_t      ao_lco_debug;
 #define PRINTD(...) 
 #endif
 
+#if AO_LCO_DRAG
 extern uint8_t ao_lco_drag_race;       /* TRUE when drag race mode enabled */
+#endif
+
 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 */
 
-#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;
-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)
index 197bf8aa3c6c5b974092e232e827a0b5458b7429..6e50e44db4f8bec93edf71a42ab72a8f940f64c2 100644 (file)
@@ -20,20 +20,28 @@ uint8_t             ao_lco_debug;
 
 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_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
@@ -68,9 +76,11 @@ ao_lco_igniter_status(void)
        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);
                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)) {
@@ -98,6 +108,7 @@ ao_lco_igniter_status(void)
                        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) {
@@ -111,7 +122,9 @@ ao_lco_igniter_status(void)
                                        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
@@ -210,9 +223,7 @@ 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
+       if (ao_lco_box < AO_PAD_MAX_BOXES)
                ao_lco_channels[ao_lco_box] = 0;
        ao_lco_pad = 1;
        ao_lco_show();
@@ -242,6 +253,7 @@ ao_lco_set_armed(uint8_t armed)
        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;
 
@@ -250,7 +262,9 @@ ao_lco_set_armed(uint8_t armed)
                                        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));