From 4746b336b9870bf98f0df237438ec4db9bbb7c69 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Tue, 10 Mar 2015 23:01:06 +0000 Subject: [PATCH] Tweak to GPS page to show when Space Vehicle updates are received via a ticker next to the bargraphs which updates each time SV info is received. Some code-size improvements optimizations could be done. --- src/main/io/display.c | 77 ++++++++++++++++++++++++++++++++----------- src/main/io/gps.c | 5 +++ src/main/io/gps.h | 1 + 3 files changed, 64 insertions(+), 19 deletions(-) diff --git a/src/main/io/display.c b/src/main/io/display.c index 11566c76b..2e8915da9 100644 --- a/src/main/io/display.c +++ b/src/main/io/display.c @@ -80,6 +80,9 @@ static rxConfig_t *rxConfig; static char lineBuffer[SCREEN_CHARACTER_COLUMN_COUNT + 1]; +#define HALF_SCREEN_CHARACTER_COLUMN_COUNT (SCREEN_CHARACTER_COLUMN_COUNT / 2) +#define IS_SCREEN_CHARACTER_COLUMN_COUNT_ODD (SCREEN_CHARACTER_COLUMN_COUNT & 1) + const char* pageTitles[] = { "CLEANFLIGHT", "ARMED", @@ -112,7 +115,7 @@ const uint8_t cyclePageIds[] = { #define CYCLE_PAGE_ID_COUNT (sizeof(cyclePageIds) / sizeof(cyclePageIds[0])) -static const char* tickerCharacters = "|/-\\"; +static const char* tickerCharacters = "|/-\\"; // use 2/4/8 characters so that the divide is optimal. #define TICKER_CHARACTER_COUNT (sizeof(tickerCharacters) / sizeof(char)) typedef enum { @@ -146,6 +149,17 @@ void padLineBuffer(void) while (length < sizeof(lineBuffer) - 1) { lineBuffer[length++] = ' '; } + lineBuffer[length] = 0; +} + +void padHalfLineBuffer(void) +{ + uint8_t halfLineIndex = sizeof(lineBuffer) / 2; + uint8_t length = strlen(lineBuffer); + while (length < halfLineIndex - 1) { + lineBuffer[length++] = ' '; + } + lineBuffer[length] = 0; } // LCDbar(n,v) : draw a bar graph - n number of chars for width, v value in % to display @@ -179,6 +193,7 @@ void fillScreenWithCharacters() } #endif + void updateTicker(void) { static uint8_t tickerIndex = 0; @@ -215,9 +230,6 @@ void drawRxChannel(uint8_t channelIndex, uint8_t width) drawHorizonalPercentageBar(width - 1, percentage); } -#define HALF_SCREEN_CHARACTER_COLUMN_COUNT (SCREEN_CHARACTER_COLUMN_COUNT / 2) -#define IS_SCREEN_CHARACTER_COLUMN_COUNT_ODD (SCREEN_CHARACTER_COLUMN_COUNT & 1) - #define RX_CHANNELS_PER_PAGE_COUNT 14 void showRxPage(void) { @@ -295,43 +307,70 @@ void showProfilePage(void) void showGpsPage() { uint8_t rowIndex = PAGE_TITLE_LINE_COUNT; + static uint8_t gpsTicker = 0; + static uint32_t lastGPSSvInfoReceivedCount = 0; + if (GPS_svInfoReceivedCount != lastGPSSvInfoReceivedCount) { + lastGPSSvInfoReceivedCount = GPS_svInfoReceivedCount; + gpsTicker++; + gpsTicker = gpsTicker % TICKER_CHARACTER_COUNT; + } + + i2c_OLED_set_xy(0, rowIndex); + i2c_OLED_send_char(tickerCharacters[gpsTicker]); + i2c_OLED_set_xy(MAX(0, SATELLITE_GRAPH_LEFT_OFFSET), rowIndex++); uint32_t index; for (index = 0; index < SATELLITE_COUNT && index < SCREEN_CHARACTER_COLUMN_COUNT; index++) { - uint8_t bargraphValue = ((uint16_t) GPS_svinfo_cno[index] * VERTICAL_BARGRAPH_CHARACTER_COUNT) / (GPS_DBHZ_MAX - 1); - bargraphValue = MIN(bargraphValue, VERTICAL_BARGRAPH_CHARACTER_COUNT - 1); - i2c_OLED_send_char(VERTICAL_BARGRAPH_ZERO_CHARACTER + bargraphValue); + uint8_t bargraphOffset = ((uint16_t) GPS_svinfo_cno[index] * VERTICAL_BARGRAPH_CHARACTER_COUNT) / (GPS_DBHZ_MAX - 1); + bargraphOffset = MIN(bargraphOffset, VERTICAL_BARGRAPH_CHARACTER_COUNT - 1); + i2c_OLED_send_char(VERTICAL_BARGRAPH_ZERO_CHARACTER + bargraphOffset); } + char fixChar = STATE(GPS_FIX) ? 'Y' : 'N'; - tfp_sprintf(lineBuffer, "Satellites: %d Fix: %c", GPS_numSat, fixChar); + tfp_sprintf(lineBuffer, "Sats: %d Fix: %c", GPS_numSat, fixChar); padLineBuffer(); i2c_OLED_set_line(rowIndex++); i2c_OLED_send_string(lineBuffer); - tfp_sprintf(lineBuffer, "Lat: %d Lon: %d", GPS_coord[LAT] / GPS_DEGREES_DIVIDER, GPS_coord[LON] / GPS_DEGREES_DIVIDER); + tfp_sprintf(lineBuffer, "La/Lo: %d/%d", GPS_coord[LAT] / GPS_DEGREES_DIVIDER, GPS_coord[LON] / GPS_DEGREES_DIVIDER); padLineBuffer(); i2c_OLED_set_line(rowIndex++); i2c_OLED_send_string(lineBuffer); - tfp_sprintf(lineBuffer, "Spd: %d cm/s GC: %d", GPS_speed, GPS_ground_course); - padLineBuffer(); - i2c_OLED_set_line(rowIndex++); + tfp_sprintf(lineBuffer, "Spd: %d", GPS_speed); + padHalfLineBuffer(); + i2c_OLED_set_line(rowIndex); i2c_OLED_send_string(lineBuffer); - tfp_sprintf(lineBuffer, "RX: %d Delta: %d", GPS_packetCount, gpsData.lastMessage - gpsData.lastLastMessage); - padLineBuffer(); - i2c_OLED_set_line(rowIndex++); + tfp_sprintf(lineBuffer, "GC: %d", GPS_ground_course); + padHalfLineBuffer(); + i2c_OLED_set_xy(HALF_SCREEN_CHARACTER_COLUMN_COUNT, rowIndex++); i2c_OLED_send_string(lineBuffer); - tfp_sprintf(lineBuffer, "ERRs: %d TOs: %d", gpsData.errors, gpsData.timeouts); - padLineBuffer(); - i2c_OLED_set_line(rowIndex++); + tfp_sprintf(lineBuffer, "RX: %d", GPS_packetCount); + padHalfLineBuffer(); + i2c_OLED_set_line(rowIndex); + i2c_OLED_send_string(lineBuffer); + + tfp_sprintf(lineBuffer, "ERRs: %d", gpsData.errors, gpsData.timeouts); + padHalfLineBuffer(); + i2c_OLED_set_xy(HALF_SCREEN_CHARACTER_COLUMN_COUNT, rowIndex++); + i2c_OLED_send_string(lineBuffer); + + tfp_sprintf(lineBuffer, "Delta: %d", gpsData.lastMessage - gpsData.lastLastMessage); + padHalfLineBuffer(); + i2c_OLED_set_line(rowIndex); + i2c_OLED_send_string(lineBuffer); + + tfp_sprintf(lineBuffer, "TOs: %d", gpsData.timeouts); + padHalfLineBuffer(); + i2c_OLED_set_xy(HALF_SCREEN_CHARACTER_COLUMN_COUNT, rowIndex++); i2c_OLED_send_string(lineBuffer); strncpy(lineBuffer, gpsPacketLog, GPS_PACKET_LOG_ENTRY_COUNT); - padLineBuffer(); + padHalfLineBuffer(); i2c_OLED_set_line(rowIndex++); i2c_OLED_send_string(lineBuffer); diff --git a/src/main/io/gps.c b/src/main/io/gps.c index 5609fd03f..5b919f185 100644 --- a/src/main/io/gps.c +++ b/src/main/io/gps.c @@ -77,6 +77,7 @@ int32_t GPS_coord[2]; // LAT/LON uint8_t GPS_numSat; uint16_t GPS_hdop = 9999; // Compute GPS quality signal uint32_t GPS_packetCount = 0; +uint32_t GPS_svInfoReceivedCount = 0; // SV = Space Vehicle, counter increments each time SV info is received. uint8_t GPS_update = 0; // it's a binary toggle to distinct a GPS position update uint16_t GPS_altitude; // altitude in 0.1m @@ -644,6 +645,9 @@ static bool gpsNewFrameNMEA(char c) GPS_svinfo_quality[svSatNum - 1] = 0; // only used by ublox break; } + + GPS_svInfoReceivedCount++; + break; } @@ -915,6 +919,7 @@ static bool UBLOX_parse_gps(void) GPS_svinfo_quality[i]=_buffer.svinfo.channel[i].quality; GPS_svinfo_cno[i]= _buffer.svinfo.channel[i].cno; } + GPS_svInfoReceivedCount++; break; default: return false; diff --git a/src/main/io/gps.h b/src/main/io/gps.h index 34ad83625..ee90f09b2 100644 --- a/src/main/io/gps.h +++ b/src/main/io/gps.h @@ -104,6 +104,7 @@ extern uint8_t GPS_numSat; extern uint16_t GPS_hdop; // GPS signal quality extern uint8_t GPS_update; // it's a binary toogle to distinct a GPS position update extern uint32_t GPS_packetCount; +extern uint32_t GPS_svInfoReceivedCount; extern uint16_t GPS_altitude; // altitude in 0.1m extern uint16_t GPS_speed; // speed in 0.1m/s extern uint16_t GPS_ground_course; // degrees * 10