telelco-v0.2: Make config.pad_box override switches
[fw/altos] / src / drivers / ao_pad.c
index ed749d1cf756e4be62a961abab7e8bf69fc4d866..f3975dbc1b21b42d9e0265b51e79d0388fb71b08 100644 (file)
@@ -39,8 +39,8 @@ static __pdata uint16_t       ao_pad_packet_time;
 
 #if DEBUG
 static __pdata uint8_t ao_pad_debug;
-#define PRINTD(...) (ao_pad_debug ? (printf(__VA_ARGS__), 0) : 0)
-#define FLUSHD()    (ao_pad_debug ? (flush(), 0) : 0)
+#define PRINTD(...) do { if (ao_pad_debug) { printf(__VA_ARGS__); flush(); } } while(0)
+#define FLUSHD()
 #else
 #define PRINTD(...)
 #define FLUSHD()
@@ -139,13 +139,14 @@ ao_pad_run(void)
                        ao_pad_ignite = 0;
 
                        ao_delay(AO_PAD_FIRE_TIME);
+                       PRINTD("ao_pad_ignite now %d\n", ao_pad_ignite);
                }
 #ifdef AO_PAD_PORT_1
                ao_gpio_clr_bits(AO_PAD_PORT_0, pins0);
                ao_gpio_clr_bits(AO_PAD_PORT_1, pins1);
                PRINTD("turn off pins 0x%x 0x%x\n", pins0, pins1);
 #else
-               ao_gpio_set_bits(AO_PAD_PORT_0, pins0);
+               ao_gpio_clr_bits(AO_PAD_PORT_0, pins0);
                PRINTD("turn off pins 0x%x\n", pins0);
 #endif
        }
@@ -189,12 +190,15 @@ ao_pad_monitor(void)
 {
        uint8_t                 c;
        uint8_t                 sample;
-       __pdata uint8_t         prev = 0, cur = 0;
+       __pdata AO_LED_TYPE     prev = 0, cur = 0;
        __pdata uint8_t         beeping = 0;
        __xdata volatile struct ao_data *packet;
        __pdata uint16_t        arm_beep_time = 0;
 
        sample = ao_data_head;
+       ao_led_set(LEDS_AVAILABLE);
+       ao_delay(AO_MS_TO_TICKS(1000));
+       ao_led_set(0);
        for (;;) {
                __pdata int16_t                 pyro;
 
@@ -278,9 +282,9 @@ ao_pad_monitor(void)
                        query.igniter_status[c] = status;
                }
                if (cur != prev) {
-                       PRINTD("change leds from %02x to %02x\n",
-                              prev, cur);
-                       FLUSHD();
+//                     PRINTD("change leds from %02x to %02x\n",
+//                            prev, cur);
+//                     FLUSHD();
                        ao_led_set(cur);
                        prev = cur;
                }
@@ -330,6 +334,7 @@ ao_pad_read_box(void)
        uint8_t         byte = ao_74hc165_read();
        uint8_t         h, l;
 
+       PRINTD("box %02x\n", byte);
        h = byte >> 4;
        l = byte & 0xf;
        return h * 10 + l;
@@ -353,10 +358,6 @@ static int ao_pad_read_box(void) {
 }
 #else
 
-#if HAS_FIXED_PAD_BOX
-#define ao_pad_read_box()      ao_config.pad_box
-#endif
-
 #ifdef PAD_BOX
 #define ao_pad_read_box()      PAD_BOX
 #endif
@@ -370,7 +371,6 @@ ao_pad(void)
        int8_t  ret;
 
        ao_pad_box = 0;
-       ao_led_set(0);
        for (;;) {
                FLUSHD();
                while (ao_pad_disabled)
@@ -381,7 +381,11 @@ ao_pad(void)
                        continue;
                ao_pad_packet_time = ao_time();
 
-               ao_pad_box = ao_pad_read_box();
+               ao_pad_box = ao_config.pad_box;
+#ifndef HAS_FIXED_PAD_BOX
+               if (ao_pad_box == 0 || ao_pad_box == 0xff)
+                       ao_pad_box = ao_pad_read_box();
+#endif
 
                PRINTD ("tick %d box %d (me %d) cmd %d channels %02x\n",
                        command.tick, command.box, ao_pad_box, command.cmd, command.channels);