Shows the last received RSSI value.
Signed-off-by: Keith Packard <keithp@keithp.com>
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 */
# 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)
}
}
+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)
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
*/
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);
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
/* 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
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 */
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
}
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;
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))
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();
}
}
}
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();
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;
}
}
#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;
/* 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)
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]);
#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)
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];
_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
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);
}
(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)
{
_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);