From 7577b4d6aed44672063ac406f53e5a2c308446bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Izzo?= Date: Sat, 13 Feb 2021 13:27:06 +0100 Subject: [PATCH] Improved algorithm for keeping track of active satellites --- openrtx/include/interfaces/graphics.h | 3 ++- openrtx/include/state.h | 2 +- openrtx/src/gps.c | 11 ++--------- openrtx/src/graphics.c | 24 +++++++++++++----------- openrtx/src/ui/ui_menu.c | 3 ++- 5 files changed, 20 insertions(+), 23 deletions(-) diff --git a/openrtx/include/interfaces/graphics.h b/openrtx/include/interfaces/graphics.h index e519bbb0..fd003a92 100644 --- a/openrtx/include/interfaces/graphics.h +++ b/openrtx/include/interfaces/graphics.h @@ -267,8 +267,9 @@ void gfx_drawSmeter(point_t start, uint16_t width, uint16_t height, float rssi, * @param width: Bar graph width * @param height: Bar graph height * @param sats: pointer to the array of satellites data + * @param active_sats: bitset representing which sats are part of the fix */ -void gfx_drawGPSgraph(point_t start, uint16_t width, uint16_t height, sat_t *sats); +void gfx_drawGPSgraph(point_t start, uint16_t width, uint16_t height, sat_t *sats, uint16_t active_sats); /** * Function to draw a compass of arbitrary size. diff --git a/openrtx/include/state.h b/openrtx/include/state.h index b4dc6f28..1945ce4d 100644 --- a/openrtx/include/state.h +++ b/openrtx/include/state.h @@ -35,7 +35,6 @@ typedef struct uint8_t elevation; // Elevation in degrees uint16_t azimuth; // Azimuth in degrees uint8_t snr; // Quality of the signal in range 0-99 - bool active; // True if this satellite is part of the fix } sat_t; @@ -50,6 +49,7 @@ typedef struct uint8_t satellites_tracked; // Number of tracked satellites uint8_t satellites_in_view; // Satellites in view sat_t satellites[12]; // Details about satellites in view + uint16_t active_sats; // Bitmap representing which sats are part of the fix float latitude; // Latitude coordinates float longitude; // Longitude coordinates float altitude; // Antenna altitude above mean sea level (geoid) in m diff --git a/openrtx/src/gps.c b/openrtx/src/gps.c index 654de64e..18b1e344 100644 --- a/openrtx/src/gps.c +++ b/openrtx/src/gps.c @@ -58,6 +58,7 @@ void gps_taskFunc(char *line, int len, gps_t *state) case MINMEA_SENTENCE_GSA: { + state->active_sats = 0; struct minmea_sentence_gsa frame; if (minmea_parse_gsa(&frame, line)) { @@ -66,14 +67,7 @@ void gps_taskFunc(char *line, int len, gps_t *state) { if (frame.sats[i] != 0) { - for (int j = 0; j < 12; j++) - { - if (state->satellites[j].id == frame.sats[i]) - { - state->satellites[j].active = true; - break; - } - } + state->active_sats |= 1 << frame.sats[i]; } } } @@ -92,7 +86,6 @@ void gps_taskFunc(char *line, int len, gps_t *state) state->satellites[index].elevation = frame.sats[i].elevation; state->satellites[index].azimuth = frame.sats[i].azimuth; state->satellites[index].snr = frame.sats[i].snr; - state->satellites[index].active = false; } // Zero out unused satellite slots if (frame.msg_nr == frame.total_msgs && frame.total_msgs < 3) diff --git a/openrtx/src/graphics.c b/openrtx/src/graphics.c index 8013f57b..ad5c1c37 100644 --- a/openrtx/src/graphics.c +++ b/openrtx/src/graphics.c @@ -641,7 +641,8 @@ void gfx_drawSmeter(point_t start, uint16_t width, uint16_t height, float rssi, void gfx_drawGPSgraph(point_t start, uint16_t width, uint16_t height, - sat_t *sats) + sat_t *sats, + uint16_t active_sats) { color_t white = {255, 255, 255, 255}; color_t yellow = {250, 180, 19 , 255}; @@ -655,11 +656,11 @@ void gfx_drawGPSgraph(point_t start, bar_height = (height - 8) * sats[i].snr / 100 + 1; point_t bar_pos = {start.x + 2 + i * (bar_width + 2), start.y + (height - 8) - bar_height}; - color_t bar_color = (sats[i].active) ? yellow : white; + color_t bar_color = (active_sats & 1 << sats[i].id) ? yellow : white; gfx_drawRect(bar_pos, bar_width, bar_height, bar_color, true); snprintf(id_buf, 5, "%2d ", sats[i].id); point_t id_pos = {bar_pos.x, start.y + height}; - gfx_print(id_pos, id_buf, FONT_SIZE_5PT, TEXT_ALIGN_LEFT, white); + gfx_print(id_pos, id_buf, FONT_SIZE_5PT, TEXT_ALIGN_LEFT, bar_color); } uint8_t bars_width = 9 + 11 * (bar_width + 2); point_t left_line_end = {start.x, start.y + height - 9}; @@ -683,19 +684,20 @@ void gfx_drawGPScompass(point_t start, gfx_drawCircle(circle_pos, radius, white); point_t n_box = {start.x + radius - 5, start.y}; gfx_drawRect(n_box, 13, 13, black, true); + float needle_radius = radius - 4; if (active) { // Needle deg = -deg; deg -= 90.0f; - point_t p1 = {circle_pos.x + radius * COS(deg), - circle_pos.y + radius * SIN(deg)}; - point_t p2 = {circle_pos.x + radius * COS(deg + 145.0f), - circle_pos.y + radius * SIN(deg + 145.0f)}; - point_t p3 = {circle_pos.x + radius / 2 * COS(deg + 180.0f), - circle_pos.y + radius / 2 * SIN(deg + 180.0f)}; - point_t p4 = {circle_pos.x + radius * COS(deg - 145.0f), - circle_pos.y + radius * SIN(deg - 145.0f)}; + point_t p1 = {circle_pos.x + needle_radius * COS(deg), + circle_pos.y + needle_radius * SIN(deg)}; + point_t p2 = {circle_pos.x + needle_radius * COS(deg + 145.0f), + circle_pos.y + needle_radius * SIN(deg + 145.0f)}; + point_t p3 = {circle_pos.x + needle_radius / 2 * COS(deg + 180.0f), + circle_pos.y + needle_radius / 2 * SIN(deg + 180.0f)}; + point_t p4 = {circle_pos.x + needle_radius * COS(deg - 145.0f), + circle_pos.y + needle_radius * SIN(deg - 145.0f)}; gfx_drawLine(p1, p2, yellow); gfx_drawLine(p2, p3, yellow); gfx_drawLine(p3, p4, yellow); diff --git a/openrtx/src/ui/ui_menu.c b/openrtx/src/ui/ui_menu.c index 62d0263f..e069f3c1 100644 --- a/openrtx/src/ui/ui_menu.c +++ b/openrtx/src/ui/ui_menu.c @@ -316,7 +316,8 @@ void _ui_drawMenuGPS(ui_state_t* ui_state) gfx_drawGPSgraph(bar_pos, (SCREEN_WIDTH * 2 / 3) - layout.horizontal_pad, SCREEN_HEIGHT / 3, - last_state.gps_data.satellites); + last_state.gps_data.satellites, + last_state.gps_data.active_sats); } void _ui_drawMenuSettings(ui_state_t* ui_state)