altos: Fix LCO display while searching
[fw/altos] / src / drivers / ao_lco_bits.c
index b2124d1b533e786140b925b5b27bc7f97874bcc5..6c5182f29add29a76679a9ddb62d17394fd477aa 100644 (file)
@@ -170,11 +170,10 @@ ao_lco_update(void)
        if (ao_lco_get_channels(ao_lco_box, &ao_pad_query) & AO_LCO_VALID_LAST) {
                if (!(previous_valid & AO_LCO_VALID_EVER)) {
                        if (ao_lco_pad != AO_LCO_PAD_VOLTAGE)
-                               ao_lco_pad = ao_lco_pad_first(ao_lco_box);
-                       ao_lco_set_display();
+                               ao_lco_set_pad(ao_lco_pad_first(ao_lco_box));
                }
                if (ao_lco_pad == AO_LCO_PAD_VOLTAGE)
-                       ao_lco_set_display();
+                       ao_lco_show_display();
        }
 }
 
@@ -200,6 +199,25 @@ ao_lco_box_set_present(uint8_t box)
        ao_lco_box_mask[AO_LCO_MASK_ID(box)] |= 1 << AO_LCO_MASK_SHIFT(box);
 }
 
+void
+ao_lco_set_pad(uint8_t new_pad)
+{
+       ao_lco_pad = new_pad;
+       ao_lco_show_display();
+}
+
+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;
+       ao_lco_pad = 1;
+       ao_lco_show_display();
+}
+
 void
 ao_lco_step_pad(int8_t dir)
 {
@@ -215,10 +233,7 @@ ao_lco_step_pad(int8_t dir)
                if (new_pad == ao_lco_pad)
                        break;
        } while (!ao_lco_pad_present(ao_lco_box, new_pad));
-       if (new_pad != ao_lco_pad) {
-               ao_lco_pad = new_pad;
-               ao_lco_set_display();
-       }
+       ao_lco_set_pad(new_pad);
 }
 
 void
@@ -254,17 +269,6 @@ ao_lco_set_firing(uint8_t firing)
        ao_wakeup(&ao_lco_armed);
 }
 
-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));
-               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);
-       }
-}
-
 void
 ao_lco_search(void)
 {
@@ -276,8 +280,10 @@ ao_lco_search(void)
        ao_lco_box_reset_present();
        ao_lco_set_pad(0);
        for (box = 0; box < AO_PAD_MAX_BOXES; box++) {
-               if ((box % 10) == 0)
-                       ao_lco_set_box(box);
+               if ((box % 10) == 0) {
+                       ao_lco_box = box;
+                       ao_lco_show_display();
+               }
                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]);
@@ -297,8 +303,7 @@ ao_lco_search(void)
                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));
-       ao_lco_pad = 1;
-       ao_lco_set_display();
+       ao_lco_set_box(ao_lco_min_box);
 }
 
 void
@@ -336,6 +341,8 @@ ao_lco_monitor(void)
        }
 }
 
+#if AO_LCO_DRAG
+
 uint8_t                        ao_lco_drag_beep_count;
 static uint8_t         ao_lco_drag_beep_on;
 static uint16_t                ao_lco_drag_beep_time;
@@ -355,6 +362,18 @@ ao_lco_drag_add_beeps(uint8_t beeps)
        ao_wakeup(&ao_lco_drag_beep_count);
 }
 
+/* Toggle current pad in drag set */
+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));
+               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);
+       }
+}
+
 /* Check whether it's time to change the beeper status, then either
  * turn it on or off as necessary and bump the remaining beep counts
  */
@@ -408,7 +427,7 @@ ao_lco_drag_enable(void)
                ao_led_on(AO_LED_DRAG);
 #endif
                ao_lco_drag_add_beeps(5);
-               ao_lco_set_display();
+               ao_lco_show_display();
        }
 }
 
@@ -423,7 +442,7 @@ ao_lco_drag_disable(void)
 #endif
                memset(ao_lco_selected, 0, sizeof (ao_lco_selected));
                ao_lco_drag_add_beeps(2);
-               ao_lco_set_display();
+               ao_lco_show_display();
        }
 }
 
@@ -447,6 +466,7 @@ ao_lco_drag_warn_check(uint16_t now, uint16_t delay)
        }
        return delay;
 }
+#endif /* AO_LCO_DRAG */
 
 /* task function for beeping while arm is active */
 void