altos/telelco: Add some debug aids for TeleLCO event stuff
authorKeith Packard <keithp@keithp.com>
Thu, 19 Jan 2023 20:18:46 +0000 (12:18 -0800)
committerKeith Packard <keithp@keithp.com>
Thu, 19 Jan 2023 20:18:46 +0000 (12:18 -0800)
Use (debug & 2) to select just event debugging.
Add 'pretend' mode to cycle through all possible pad boxes.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/drivers/ao_lco.h
src/drivers/ao_lco_bits.c
src/telelco-v2.0/ao_lco_v2.c

index 65e9a8c9cb76c4a70a6650eb7145a75682056885..03c810be49fe7f0bfe6a9210323ff342735ad93d 100644 (file)
@@ -87,6 +87,9 @@ ao_lco_set_armed(uint8_t armed);
 void
 ao_lco_set_firing(uint8_t firing);
 
+void
+ao_lco_pretend(void);
+
 void
 ao_lco_toggle_drag(void);
 
index c88170b8c91dec772d36747715b955978d502de0..acdea87e3328759d8b292864ee02e28be3497e64 100644 (file)
@@ -26,6 +26,8 @@ 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
@@ -197,6 +199,7 @@ ao_lco_box_reset_present(void)
 {
        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));
 }
 
@@ -223,8 +226,12 @@ void
 ao_lco_set_box(uint16_t new_box)
 {
        ao_lco_box = new_box;
-       if (ao_lco_box < AO_PAD_MAX_BOXES)
-               ao_lco_channels[ao_lco_box] = 0;
+       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();
 }
@@ -288,8 +295,8 @@ ao_lco_search(void)
 {
        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_show_box(0);
@@ -304,7 +311,7 @@ ao_lco_search(void)
                        if (r == AO_RADIO_CMAC_OK) {
                                ++boxes;
                                ao_lco_box_set_present(box);
-                               ao_lco_show_pad(boxes % 10);
+                               ao_lco_show_pad((uint8_t) (boxes % 10));
                                ao_delay(AO_MS_TO_TICKS(30));
                                break;
                        }
@@ -319,6 +326,22 @@ ao_lco_search(void)
        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)
 {
index 3583be98f9ec23a7586c1d4d00ce46237bd34f27..78849bc9b43bc00f551a70133aef6fbdcd66327a 100644 (file)
@@ -33,6 +33,9 @@
 
 /* UI values */
 static uint8_t ao_lco_select_mode;
+static uint8_t ao_lco_event_debug;
+
+#define PRINTE(...) do { if (!ao_lco_debug && !ao_lco_event_debug) break; printf ("\r%5lu %s: ", (unsigned long) ao_tick_count, __func__); printf(__VA_ARGS__); flush(); } while(0)
 #define AO_LCO_SELECT_PAD      0
 #define AO_LCO_SELECT_BOX      1
 
@@ -176,7 +179,7 @@ ao_lco_input(void)
 
        for (;;) {
                ao_event_get(&event);
-               PRINTD("event type %d unit %d value %ld\n",
+               PRINTE("event type %d unit %d value %ld\n",
                       event.type, event.unit, (long) event.value);
                switch (event.type) {
                case AO_EVENT_QUADRATURE:
@@ -283,13 +286,16 @@ static void
 ao_lco_set_debug(void)
 {
        uint32_t r = ao_cmd_decimal();
-       if (ao_cmd_status == ao_cmd_success)
-               ao_lco_debug = r != 0;
+       if (ao_cmd_status == ao_cmd_success){
+               ao_lco_debug = r & 1;
+               ao_lco_event_debug = (r & 2) >> 1;
+       }
 }
 
 const struct ao_cmds ao_lco_cmds[] = {
        { ao_lco_set_debug,     "D <0 off, 1 on>\0Debug" },
        { ao_lco_search,        "s\0Search for pad boxes" },
+       { ao_lco_pretend,       "p\0Pretend there are lots of pad boxes" },
        { 0, NULL }
 };
 #endif