altos/telelco: Add per-box RSSI display screen
authorKeith Packard <keithp@keithp.com>
Sun, 28 Jan 2024 07:48:51 +0000 (23:48 -0800)
committerKeith Packard <keithp@keithp.com>
Thu, 1 Feb 2024 01:50:19 +0000 (17:50 -0800)
Shows the last received RSSI value.

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

index f931872b5b0ac14fcb61a35d2b7b2dc3fbc181fa..c9fc1230a5732e311253c7ea07510c3614931dd1 100644 (file)
@@ -38,7 +38,7 @@ extern uint8_t        ao_lco_debug;
 extern uint8_t ao_lco_drag_race;       /* true when drag race mode enabled */
 #endif
 
-extern uint8_t ao_lco_pad;             /* Currently selected pad */
+extern int8_t  ao_lco_pad;             /* Currently selected pad */
 extern int16_t ao_lco_box;             /* Currently selected box */
 
 extern uint8_t ao_lco_armed;           /* armed mode active */
@@ -74,6 +74,8 @@ extern struct ao_pad_query    ao_pad_query;   /* Last received QUERY from pad */
 # endif
 #endif
 #define AO_LCO_PAD_VOLTAGE     0               /* Pad number to show box voltage */
+#define AO_LCO_PAD_RSSI                -1              /* Pad number to show box RSSI */
+#define AO_LCO_PAD_FIRST       AO_LCO_PAD_RSSI
 
 static inline bool
 ao_lco_box_pseudo(int16_t box)
@@ -104,6 +106,19 @@ ao_lco_box_pseudo(int16_t box)
        }
 }
 
+static inline bool
+ao_lco_pad_pseudo(int8_t pad)
+{
+       switch (pad) {
+       case AO_LCO_PAD_VOLTAGE:
+               return true;
+       case AO_LCO_PAD_RSSI:
+               return true;
+       default:
+               return false;
+       }
+}
+
 extern int16_t ao_lco_min_box, ao_lco_max_box;
 
 #define AO_LCO_MASK_SIZE(n)    (((n) + 7) >> 3)
@@ -112,6 +127,11 @@ extern int16_t     ao_lco_min_box, ao_lco_max_box;
 
 extern uint8_t ao_lco_box_mask[AO_LCO_MASK_SIZE(AO_PAD_MAX_BOXES)];
 
+#define AO_LCO_VALID_LAST      1
+#define AO_LCO_VALID_EVER      2
+
+extern uint8_t ao_lco_valid[AO_PAD_MAX_BOXES];         /* AO_LCO_VALID bits per box */
+
 /*
  * Shared functions
  */
@@ -123,13 +143,13 @@ void
 ao_lco_update(void);
 
 uint8_t
-ao_lco_pad_present(int16_t box, uint8_t pad);
+ao_lco_pad_present(int16_t box, int8_t pad);
 
-uint8_t
+int8_t
 ao_lco_pad_first(int16_t box);
 
 void
-ao_lco_set_pad(uint8_t new_pad);
+ao_lco_set_pad(int8_t new_pad);
 
 void
 ao_lco_step_pad(int8_t dir);
@@ -158,7 +178,7 @@ ao_lco_search(void);
 void
 ao_lco_monitor(void);
 
-extern uint8_t                 ao_lco_drag_beep_count;
+extern int8_t                  ao_lco_drag_beep_count;
 
 /* enable drag race mode */
 void
@@ -178,7 +198,7 @@ ao_lco_drag_warn_check(AO_TICK_TYPE now, AO_TICK_TYPE delay);
 
 /* Request 'beeps' additional drag race beeps */
 void
-ao_lco_drag_add_beeps(uint8_t beeps);
+ao_lco_drag_add_beeps(int8_t beeps);
 
 /* task function for beeping while arm is active */
 void
index 2821d1195cdd4e8b31d79567a1f21b823d51c5e1..06fc929fd6c50cc151e3c38c111acc8db5d165ac 100644 (file)
@@ -18,7 +18,7 @@
 
 uint8_t                ao_lco_debug;
 
-uint8_t                ao_lco_pad;
+int8_t         ao_lco_pad;
 int16_t                ao_lco_box;
 
 uint8_t                ao_lco_armed;                                   /* arm active */
@@ -38,10 +38,7 @@ static uint8_t               ao_lco_channels[AO_PAD_MAX_BOXES];      /* pad channels available on
 static uint16_t                ao_lco_tick_offset[AO_PAD_MAX_BOXES];   /* 16 bit 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 */
+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
@@ -142,10 +139,10 @@ ao_lco_igniter_status(void)
 }
 
 uint8_t
-ao_lco_pad_present(int16_t box, uint8_t pad)
+ao_lco_pad_present(int16_t box, int8_t pad)
 {
        /* voltage measurement is always valid */
-       if (pad == AO_LCO_PAD_VOLTAGE)
+       if (ao_lco_pad_pseudo(pad))
                return 1;
        if (!ao_lco_channels[box])
                return 0;
@@ -154,10 +151,10 @@ ao_lco_pad_present(int16_t box, uint8_t pad)
        return (ao_lco_channels[box] >> (pad - 1)) & 1;
 }
 
-uint8_t
+int8_t
 ao_lco_pad_first(int16_t box)
 {
-       uint8_t pad;
+       int8_t  pad;
 
        for (pad = 1; pad <= AO_PAD_MAX_CHANNELS; pad++)
                if (ao_lco_pad_present(box, pad))
@@ -193,10 +190,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)
+                       if (!ao_lco_pad_pseudo(ao_lco_pad))
                                ao_lco_set_pad(ao_lco_pad_first(ao_lco_box));
                }
-               if (ao_lco_pad == AO_LCO_PAD_VOLTAGE)
+               if (ao_lco_pad_pseudo(ao_lco_pad))
                        ao_lco_show();
        }
 }
@@ -225,7 +222,7 @@ ao_lco_box_set_present(int16_t box)
 }
 
 void
-ao_lco_set_pad(uint8_t new_pad)
+ao_lco_set_pad(int8_t new_pad)
 {
        ao_lco_pad = new_pad;
        ao_lco_show();
@@ -305,14 +302,14 @@ ao_lco_step_pad(int8_t dir)
                do {
                        new_pad += dir;
                        if (new_pad > AO_PAD_MAX_CHANNELS)
-                               new_pad = AO_LCO_PAD_VOLTAGE;
-                       if (new_pad < 0)
+                               new_pad = AO_LCO_PAD_FIRST;
+                       if (new_pad < AO_LCO_PAD_FIRST)
                                new_pad = AO_PAD_MAX_CHANNELS;
                        if (new_pad == ao_lco_pad)
                                break;
-               } while (!ao_lco_pad_present(ao_lco_box, (uint8_t) new_pad));
+               } while (!ao_lco_pad_present(ao_lco_box, (int8_t) new_pad));
                PRINTD("New pad %d\n", new_pad);
-               ao_lco_set_pad((uint8_t) new_pad);
+               ao_lco_set_pad((int8_t) new_pad);
                break;
        }
 }
@@ -488,7 +485,7 @@ ao_lco_monitor(void)
 
 #if AO_LCO_DRAG
 
-uint8_t                        ao_lco_drag_beep_count;
+int8_t                 ao_lco_drag_beep_count;
 static uint8_t         ao_lco_drag_beep_on;
 static AO_TICK_TYPE    ao_lco_drag_beep_time;
 static AO_TICK_TYPE    ao_lco_drag_warn_time;
@@ -498,7 +495,7 @@ static AO_TICK_TYPE ao_lco_drag_warn_time;
 
 /* Request 'beeps' additional drag race beeps */
 void
-ao_lco_drag_add_beeps(uint8_t beeps)
+ao_lco_drag_add_beeps(int8_t beeps)
 {
        PRINTD("beep %d\n", beeps);
        if (ao_lco_drag_beep_count == 0)
@@ -511,7 +508,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 && !ao_lco_box_pseudo(ao_lco_box)) {
+       if (ao_lco_drag_race && !ao_lco_pad_pseudo(ao_lco_pad) && !ao_lco_box_pseudo(ao_lco_box)) {
                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 dbee0bc2ed269223195ca8bad6a236c797c6a0d1..1236384349d5ea6cf8963a8c9d8a446fd554c61d 100644 (file)
@@ -59,8 +59,8 @@ static const struct ao_transform show_transform = {
 #define VALUE_Y                (int16_t) (LABEL_Y + BIG_FONT.ascent + 5)
 #define BOX_X          2
 #define PAD_X          90
-#define BOX_LABEL_X    30
-#define VOLT_LABEL_X   25
+#define BOX_LABEL_X    26
+#define VALUE_LABEL_X  64
 #define RSSI_LABEL_X   15
 #define PAD_LABEL_X    95
 #define SEP_X          (PAD_X - 8)
@@ -101,7 +101,7 @@ static uint8_t      ao_lco_event_debug;
 static uint8_t ao_lco_display_mutex;
 
 static void
-_ao_lco_show_pad(uint8_t pad)
+_ao_lco_show_pad(int8_t pad)
 {
        char    str[5];
 
@@ -124,11 +124,13 @@ static void
 _ao_lco_show_voltage(uint16_t decivolts, const char *label)
 {
        char    str[7];
+       int16_t width;
 
        PRINTD("voltage %d\n", decivolts);
        snprintf(str, sizeof(str), "%2d.%d", decivolts / 10, decivolts % 10);
        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);
+       width = ao_text_width(&SMALL_FONT, label);
+       ao_text(&fb, &SMALL_FONT, VALUE_LABEL_X - width/2, LABEL_Y, label, AO_BLACK, AO_COPY);
 }
 
 static void
@@ -139,7 +141,7 @@ _ao_lco_batt_voltage(void)
 
        ao_adc_single_get(&packet);
        decivolt = ao_battery_decivolt(packet.v_batt);
-       _ao_lco_show_voltage((uint16_t) decivolt, "LCO battery");
+       _ao_lco_show_voltage((uint16_t) decivolt, "LCO Battery");
        ao_st7565_update(&fb);
 }
 
@@ -203,6 +205,30 @@ _ao_lco_show_info(void)
                     (int) (ao_config.frequency % 1000));
 }
 
+static void
+_ao_lco_show_rssi(void)
+{
+       char label[20];
+       int16_t width;
+       snprintf(label, sizeof(label), "Box %d RSSI", ao_lco_box);
+       width = ao_text_width(&SMALL_FONT, label);
+       ao_text(&fb, &SMALL_FONT, VALUE_LABEL_X - width / 2, LABEL_Y, label, AO_BLACK, AO_COPY);
+       if (!(ao_lco_valid[ao_lco_box] & AO_LCO_VALID_LAST))
+               strcpy(label, "---");
+       else
+               snprintf(label, sizeof(label), "%d", ao_radio_cmac_rssi);
+       width = ao_text_width(&VOLT_FONT, label);
+       ao_text(&fb, &VOLT_FONT, VALUE_LABEL_X - width / 2, VALUE_Y, label, AO_BLACK, AO_COPY);
+}
+
+static void
+_ao_lco_show_pad_battery(void)
+{
+       char label[20];
+       snprintf(label, sizeof(label), "Box %d Battery", ao_lco_box);
+       _ao_lco_show_voltage(ao_pad_query.battery, label);
+}
+
 void
 ao_lco_show(void)
 {
@@ -222,9 +248,14 @@ ao_lco_show(void)
                _ao_lco_show_info();
                break;
        default:
-               if (ao_lco_pad == AO_LCO_PAD_VOLTAGE) {
-                       _ao_lco_show_voltage(ao_pad_query.battery, "Pad battery");
-               } else {
+               switch (ao_lco_pad) {
+               case AO_LCO_PAD_RSSI:
+                       _ao_lco_show_rssi();
+                       break;
+               case AO_LCO_PAD_VOLTAGE:
+                       _ao_lco_show_pad_battery();
+                       break;
+               default:
                        _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);