altos/telelco-v3.0: Fix up search UI
authorKeith Packard <keithp@keithp.com>
Mon, 8 Jan 2024 03:57:03 +0000 (19:57 -0800)
committerKeith Packard <keithp@keithp.com>
Thu, 1 Feb 2024 01:50:19 +0000 (17:50 -0800)
Present a progress bar. Show the detected box numbers.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/draw/ao_draw.h
src/draw/ao_text.c
src/drivers/ao_lco.h
src/drivers/ao_lco_bits.c
src/telelco-v3.0/ao_lco_v3.c
src/telelco-v3.0/ao_pins.h

index b5cc19c45a99ab402e6286ae242435149072dc77..6b0bc2cefe72e19a0c3246c3b42d390110c2a30d 100644 (file)
@@ -160,7 +160,7 @@ ao_poly(struct ao_bitmap            *dst,
        uint32_t                        fill,
        uint8_t                         rop);
 
-void
+int16_t
 ao_text(struct ao_bitmap       *dst,
        const struct ao_font    *font,
        int16_t                 x,
index 718f3374b10f1d2a64d947e9f1d8daa52f028867..8f5307ab99e474a76292dc2fe45378f49bbf8b5b 100644 (file)
@@ -24,7 +24,7 @@ static struct ao_bitmap       src_bitmap = {
        .base = ao_glyph_temp,
 };
 
-void
+int16_t
 ao_text(struct ao_bitmap       *dst,
        const struct ao_font    *font,
        int16_t                 x,
@@ -76,4 +76,5 @@ ao_text(struct ao_bitmap      *dst,
                        0, 0, rop);
                x += advance;
        }
+       return x;
 }
index 03c810be49fe7f0bfe6a9210323ff342735ad93d..75ff5684ba863bc32b872d622b232fc3b7ea0a91 100644 (file)
@@ -46,6 +46,7 @@ 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_LCO_VOLTAGE     0               /* Box number to show LCO voltage */
 #define AO_LCO_PAD_VOLTAGE     0               /* Pad number to show box voltage */
 
 extern uint16_t        ao_lco_min_box, ao_lco_max_box;
@@ -81,6 +82,9 @@ ao_lco_step_pad(int8_t dir);
 void
 ao_lco_set_box(uint16_t new_box);
 
+void
+ao_lco_step_box(int8_t dir);
+
 void
 ao_lco_set_armed(uint8_t armed);
 
@@ -144,4 +148,20 @@ ao_lco_init(void);
 uint8_t
 ao_lco_box_present(uint16_t box);
 
+#ifdef AO_LCO_SEARCH_API
+
+void
+ao_lco_search_start(void);
+
+void
+ao_lco_search_box_check(uint16_t box);
+
+void
+ao_lco_search_box_present(uint16_t box);
+
+void
+ao_lco_search_done(void);
+
+#endif /* AO_LCO_SEARCH_API */
+
 #endif /* _AO_LCO_H_ */
index acdea87e3328759d8b292864ee02e28be3497e64..eca39d5bfe2e7aed9699293f3c15d02b6bc3135d 100644 (file)
@@ -84,6 +84,10 @@ ao_lco_igniter_status(void)
                else
 #endif
                        ao_sleep(&ao_pad_query);
+               if (ao_lco_box == AO_LCO_LCO_VOLTAGE) {
+                       ao_led_off(AO_LED_GREEN|AO_LED_AMBER|AO_LED_RED);
+                       continue;
+               }
                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_led_on(AO_LED_RED);
@@ -180,6 +184,11 @@ ao_lco_get_channels(uint16_t box, struct ao_pad_query *query)
 void
 ao_lco_update(void)
 {
+       if (ao_lco_box == AO_LCO_LCO_VOLTAGE) {
+               ao_lco_show();
+               return;
+       }
+
        uint8_t previous_valid = ao_lco_valid[ao_lco_box];
 
        if (ao_lco_get_channels(ao_lco_box, &ao_pad_query) & AO_LCO_VALID_LAST) {
@@ -226,11 +235,14 @@ void
 ao_lco_set_box(uint16_t new_box)
 {
        ao_lco_box = new_box;
-       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;
+       if (ao_lco_box != AO_LCO_LCO_VOLTAGE)
+       {
+               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();
@@ -254,9 +266,39 @@ ao_lco_step_pad(int8_t dir)
        ao_lco_set_pad((uint8_t) new_pad);
 }
 
+uint8_t
+ao_lco_box_present(uint16_t box)
+{
+       if (box == AO_LCO_LCO_VOLTAGE)
+               return 1;
+       if (box >= AO_PAD_MAX_BOXES)
+               return 0;
+       return (ao_lco_box_mask[AO_LCO_MASK_ID(box)] >> AO_LCO_MASK_SHIFT(box)) & 1;
+}
+
+void
+ao_lco_step_box(int8_t dir)
+{
+       int32_t new_box = (int32_t) ao_lco_box;
+
+       do {
+               new_box += dir;
+               if (new_box > ao_lco_max_box)
+                       new_box = AO_LCO_LCO_VOLTAGE;
+               else if (new_box < 0)
+                       new_box = ao_lco_max_box;
+               if (new_box == ao_lco_box)
+                       break;
+       } while (!ao_lco_box_present((uint16_t) new_box));
+       ao_lco_set_box((uint16_t) new_box);
+}
+
 void
 ao_lco_set_armed(uint8_t armed)
 {
+       if (ao_lco_box == AO_LCO_LCO_VOLTAGE)
+               return;
+
        ao_lco_armed = armed;
        PRINTD("Armed %d\n", ao_lco_armed);
        if (ao_lco_armed) {
@@ -299,11 +341,19 @@ ao_lco_search(void)
        uint16_t        boxes = 0;
 
        ao_lco_box_reset_present();
+#ifdef AO_LCO_SEARCH_API
+       ao_lco_search_start();
+#else
        ao_lco_show_box(0);
        ao_lco_show_pad(0);
+#endif
        for (box = 0; box < AO_PAD_MAX_BOXES; box++) {
+#ifdef AO_LCO_SEARCH_API
+               ao_lco_search_box_check(box);
+#else
                if ((box % 10) == 0)
                        ao_lco_show_box(box);
+#endif
                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]);
@@ -311,7 +361,11 @@ ao_lco_search(void)
                        if (r == AO_RADIO_CMAC_OK) {
                                ++boxes;
                                ao_lco_box_set_present(box);
+#ifdef AO_LCO_SEARCH_API
+                               ao_lco_search_box_present(box);
+#else
                                ao_lco_show_pad((uint8_t) (boxes % 10));
+#endif
                                ao_delay(AO_MS_TO_TICKS(30));
                                break;
                        }
@@ -323,6 +377,9 @@ 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));
+#ifdef AO_LCO_SEARCH_API
+       ao_lco_search_done();
+#endif
        ao_lco_set_box(ao_lco_min_box);
 }
 
@@ -402,7 +459,7 @@ ao_lco_drag_add_beeps(uint8_t beeps)
 void
 ao_lco_toggle_drag(void)
 {
-       if (ao_lco_drag_race && ao_lco_pad != AO_LCO_PAD_VOLTAGE) {
+       if (ao_lco_drag_race && ao_lco_pad != AO_LCO_PAD_VOLTAGE && ao_lco_box != AO_LCO_LCO_VOLTAGE) {
                ao_lco_selected[ao_lco_box] ^= (uint8_t) (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]);
index 5fe5047251a1d8cbed177264b371a22b69971093..2bd3c5009e198fc971dd1a73e417de59b6d1f333 100644 (file)
@@ -63,8 +63,7 @@ static const struct ao_transform logo_transform = {
 #define SCAN_HEIGHT    3
 #define FOUND_Y                63
 #define FOUND_X                6
-#define FOUND_WIDTH    17
-#define MAX_VALID      (WIDTH / FOUND_WIDTH)
+#define FOUND_WIDTH    (WIDTH - 6)
 
 #define AO_LCO_DRAG_RACE_START_TIME    AO_SEC_TO_TICKS(5)
 #define AO_LCO_DRAG_RACE_STOP_TIME     AO_SEC_TO_TICKS(2)
@@ -79,61 +78,65 @@ static uint8_t      ao_lco_event_debug;
 
 static uint8_t ao_lco_display_mutex;
 
-void
-ao_lco_show_pad(uint8_t pad)
+static void
+_ao_lco_show_pad(uint8_t pad)
 {
        char    str[5];
 
-       ao_mutex_get(&ao_lco_display_mutex);
        snprintf(str, sizeof(str), "%d", pad);
        ao_text(&fb, &BIG_FONT, PAD_X, VALUE_Y, str, AO_BLACK, AO_COPY);
        ao_text(&fb, &SMALL_FONT, PAD_LABEL_X, LABEL_Y, "Pad", AO_BLACK, AO_COPY);
-       ao_rect(&fb, SEP_X, 0, 2, HEIGHT, AO_BLACK, AO_COPY);
-       ao_mutex_put(&ao_lco_display_mutex);
 }
-void
-ao_lco_show_box(uint16_t box)
+
+static void
+_ao_lco_show_box(uint16_t box)
 {
        char    str[7];
 
-       ao_mutex_get(&ao_lco_display_mutex);
        snprintf(str, sizeof(str), "%2d", box);
        ao_text(&fb, &BIG_FONT, BOX_X, VALUE_Y, str, AO_BLACK, AO_COPY);
        ao_text(&fb, &SMALL_FONT, BOX_LABEL_X, LABEL_Y, "Box", AO_BLACK, AO_COPY);
-       ao_mutex_put(&ao_lco_display_mutex);
 }
 
 static void
-ao_lco_show_voltage(uint16_t decivolts, const char *label)
+_ao_lco_show_voltage(uint16_t decivolts, const char *label)
 {
        char    str[7];
 
        PRINTD("voltage %d\n", decivolts);
        snprintf(str, sizeof(str), "%2d.%d", decivolts / 10, decivolts % 10);
-       ao_mutex_get(&ao_lco_display_mutex);
-       ao_rect(&fb, 0, 0, WIDTH, HEIGHT, AO_WHITE, AO_COPY);
        ao_text(&fb, &VOLT_FONT, BOX_X, VALUE_Y, str, AO_BLACK, AO_COPY);
        ao_text(&fb, &SMALL_FONT, VOLT_LABEL_X, LABEL_Y, label, AO_BLACK, AO_COPY);
-       ao_mutex_put(&ao_lco_display_mutex);
+}
+
+static void
+_ao_lco_batt_voltage(void)
+{
+       struct ao_adc   packet;
+       int16_t         decivolt;
+
+       ao_adc_single_get(&packet);
+       decivolt = ao_battery_decivolt(packet.v_batt);
+       _ao_lco_show_voltage((uint16_t) decivolt, "LCO battery");
+       ao_st7565_update(&fb);
 }
 
 void
 ao_lco_show(void)
 {
-       if (ao_lco_pad == AO_LCO_PAD_VOLTAGE) {
-               ao_lco_show_voltage(ao_pad_query.battery, "Pad battery");
+       ao_mutex_get(&ao_lco_display_mutex);
+       ao_rect(&fb, 0, 0, WIDTH, HEIGHT, AO_WHITE, AO_COPY);
+       if (ao_lco_box == AO_LCO_LCO_VOLTAGE) {
+               _ao_lco_batt_voltage();
+       } else if (ao_lco_pad == AO_LCO_PAD_VOLTAGE) {
+               _ao_lco_show_voltage(ao_pad_query.battery, "Pad battery");
        } else {
-               ao_lco_show_pad(ao_lco_pad);
-               ao_lco_show_box(ao_lco_box);
+               _ao_lco_show_pad(ao_lco_pad);
+               _ao_lco_show_box(ao_lco_box);
+               ao_rect(&fb, SEP_X, 0, 2, HEIGHT, AO_BLACK, AO_COPY);
        }
-}
-
-uint8_t
-ao_lco_box_present(uint16_t box)
-{
-       if (box >= AO_PAD_MAX_BOXES)
-               return 0;
-       return (ao_lco_box_mask[AO_LCO_MASK_ID(box)] >> AO_LCO_MASK_SHIFT(box)) & 1;
+       ao_st7565_update(&fb);
+       ao_mutex_put(&ao_lco_display_mutex);
 }
 
 static void
@@ -158,22 +161,6 @@ ao_lco_set_select(void)
        }
 }
 
-static void
-ao_lco_step_box(int8_t dir)
-{
-       int32_t new_box = (int32_t) ao_lco_box;
-
-       do {
-               new_box += dir;
-               if (new_box > ao_lco_max_box)
-                       new_box = ao_lco_min_box;
-               else if (new_box < ao_lco_min_box)
-                       new_box = ao_lco_max_box;
-               if (new_box == ao_lco_box)
-                       break;
-       } while (!ao_lco_box_present((uint16_t) new_box));
-       ao_lco_set_box((uint16_t) new_box);
-}
 
 static struct ao_task  ao_lco_drag_task;
 
@@ -267,32 +254,62 @@ ao_lco_input(void)
 static void
 ao_lco_display_test(void)
 {
-       ao_mutex_get(&ao_lco_display_mutex);
-       ao_rect(&fb, 0, 0, WIDTH, HEIGHT, AO_WHITE, AO_COPY);
-       ao_logo(&fb, &logo_transform, &LOGO_FONT, AO_BLACK, AO_COPY);
-       ao_mutex_put(&ao_lco_display_mutex);
        ao_led_on(AO_LEDS_AVAILABLE);
-       ao_delay(AO_MS_TO_TICKS(1000));
+       ao_rect(&fb, 0, 0, WIDTH, HEIGHT, AO_BLACK, AO_COPY);
+       ao_st7565_update(&fb);
+       ao_delay(AO_MS_TO_TICKS(250));
        ao_led_off(AO_LEDS_AVAILABLE);
 }
 
+static struct ao_task ao_lco_input_task;
+static struct ao_task ao_lco_monitor_task;
+static struct ao_task ao_lco_arm_warn_task;
+static struct ao_task ao_lco_igniter_status_task;
+
+static int16_t found_x;
+
+void
+ao_lco_search_start(void)
+{
+       ao_rect(&fb, 0, 0, WIDTH, HEIGHT, AO_WHITE, AO_COPY);
+       ao_logo(&fb, &logo_transform, &LOGO_FONT, AO_BLACK, AO_COPY);
+       found_x = FOUND_X;
+}
+
+void
+ao_lco_search_box_check(uint16_t box)
+{
+       if (box > 0)
+               ao_rect(&fb, SCAN_X, SCAN_Y, (int16_t) box, SCAN_HEIGHT, AO_BLACK, AO_COPY);
+       ao_st7565_update(&fb);
+}
+
+void
+ao_lco_search_box_present(uint16_t box)
+{
+       char    str[8];
+       if (found_x < FOUND_WIDTH)
+       {
+               snprintf(str, sizeof(str), "%s%02u", found_x ? ", " : "", box);
+               found_x = ao_text(&fb, &TINY_FONT, found_x, FOUND_Y, str, AO_BLACK, AO_COPY);
+       }
+}
+
+void
+ao_lco_search_done(void)
+{
+       ao_st7565_update(&fb);
+}
+
 static void
 ao_lco_batt_voltage(void)
 {
-       struct ao_adc   packet;
-       int16_t         decivolt;
-
-       ao_adc_single_get(&packet);
-       decivolt = ao_battery_decivolt(packet.v_batt);
-       ao_lco_show_voltage((uint16_t) decivolt, "LCO battery");
+       ao_rect(&fb, 0, 0, WIDTH, HEIGHT, AO_WHITE, AO_COPY);
+       _ao_lco_batt_voltage();
+       ao_st7565_update(&fb);
        ao_delay(AO_MS_TO_TICKS(1000));
 }
 
-static struct ao_task ao_lco_input_task;
-static struct ao_task ao_lco_monitor_task;
-static struct ao_task ao_lco_arm_warn_task;
-static struct ao_task ao_lco_igniter_status_task;
-
 static void
 ao_lco_main(void)
 {
index 6402ed4965096ce0ab851d12402aed49e7a6e7e2..a68793cda10ea953d85f96a58e7682c791cd38d4 100644 (file)
@@ -288,4 +288,6 @@ struct ao_adc {
  */
 #define AO_ADC_REFERENCE_DV    33
 
+#define AO_LCO_SEARCH_API
+
 #endif /* _AO_PINS_H_ */