diff --git a/openrtx/src/core/gps.c b/openrtx/src/core/gps.c index 963732eb..e9bb25b6 100644 --- a/openrtx/src/core/gps.c +++ b/openrtx/src/core/gps.c @@ -27,7 +27,7 @@ #define KNOTS2KMH 1.852f -static char sentence[MINMEA_MAX_LENGTH + 1]; +static char sentence[2*MINMEA_MAX_LENGTH]; static bool isRtcSyncronised = false; static bool gpsEnabled = false; static bool readNewSentence = true; @@ -52,14 +52,22 @@ void gps_taskFunc() // Acquire a new NMEA sentence from GPS if(readNewSentence) { - int status = gps_getNmeaSentence(sentence, MINMEA_MAX_LENGTH + 1); + int status = gps_getNmeaSentence(sentence, 2*MINMEA_MAX_LENGTH); if(status != 0) return; readNewSentence = false; } + // Waiting for a sentence... if(gps_nmeaSentenceReady() == false) return; + // Discard all non-GPS sentences + if((sentence[0] != '$') || (sentence[1] != 'G')) + { + readNewSentence = true; + return; + } + // Parse the sentence. Work on a local state copy to minimize the time // spent with the state mutex locked gps_t gps_data; diff --git a/openrtx/src/core/threads.c b/openrtx/src/core/threads.c index 612b2f22..1bf1d3ac 100644 --- a/openrtx/src/core/threads.c +++ b/openrtx/src/core/threads.c @@ -139,26 +139,30 @@ void *dev_task(void *arg) if(state.gpsDetected) gps_init(9600); #endif + uint8_t tick_5ms = 0; + while(state.shutdown == false) { - // Update radio state - state_update(); + tick_5ms++; #if defined(GPS_PRESENT) && !defined(MD3x0_ENABLE_DBG) if(state.gpsDetected) - { gps_taskFunc(); - } #endif - // Signal state update to UI thread - event_t dev_msg; - dev_msg.type = EVENT_STATUS; - dev_msg.payload = 0; - ui_pushEvent(dev_msg); + // Update radio state and push an event to the UI every 100ms + if((tick_5ms % 20) == 0) + { + state_update(); - // 10Hz update rate - sleepFor(0u, 100u); + event_t dev_msg; + dev_msg.type = EVENT_STATUS; + dev_msg.payload = 0; + ui_pushEvent(dev_msg); + } + + // Run this loop once every 5ms + sleepFor(0u, 5u); } #if defined(GPS_PRESENT)