From 1741039eb3633b3f010ac7fc9e6a055d02aa0a15 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 27 Jan 2024 23:48:51 -0800 Subject: [PATCH] altos/telelco: Add per-box RSSI display screen Shows the last received RSSI value. Signed-off-by: Keith Packard --- src/drivers/ao_lco.h | 32 +++++++++++++++++++----- src/drivers/ao_lco_bits.c | 35 ++++++++++++--------------- src/telelco-v3.0/ao_lco_v3.c | 47 ++++++++++++++++++++++++++++++------ 3 files changed, 81 insertions(+), 33 deletions(-) diff --git a/src/drivers/ao_lco.h b/src/drivers/ao_lco.h index f931872b..c9fc1230 100644 --- a/src/drivers/ao_lco.h +++ b/src/drivers/ao_lco.h @@ -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 diff --git a/src/drivers/ao_lco_bits.c b/src/drivers/ao_lco_bits.c index 2821d119..06fc929f 100644 --- a/src/drivers/ao_lco_bits.c +++ b/src/drivers/ao_lco_bits.c @@ -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]); diff --git a/src/telelco-v3.0/ao_lco_v3.c b/src/telelco-v3.0/ao_lco_v3.c index dbee0bc2..12363843 100644 --- a/src/telelco-v3.0/ao_lco_v3.c +++ b/src/telelco-v3.0/ao_lco_v3.c @@ -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); -- 2.30.2