diff --git a/platformio.ini b/platformio.ini index 74ed94ab..035a8e29 100644 --- a/platformio.ini +++ b/platformio.ini @@ -62,7 +62,7 @@ lib_deps = 1260 ; OneButton library for non-blocking button debounce 1202 ; CRC32, explicitly needed because dependency is missing in the ble ota update lib https://github.com/meshtastic/arduino-fsm.git - https://github.com/meshtastic/SparkFun_Ublox_Arduino_Library.git + https://github.com/meshtastic/SparkFun_Ublox_Arduino_Library.git#cb8353dfddd1b0e205098f5e70d5f2a5f74b4838 https://github.com/meshtastic/RadioLib.git#ac7feac00f5e0bd95a3ac5d5852b4cc7344cf95c https://github.com/meshtastic/TinyGPSPlus.git https://github.com/meshtastic/AXP202X_Library.git#8404abb6d4b486748636bc6ad72d2a47baaf5460 diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 2f8e636e..f8d83743 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -209,7 +209,10 @@ void GPS::loop() // While we are awake if (isAwake) { // DEBUG_MSG("looking for location\n"); - whileActive(); + if ((now - lastWhileActiveMsec) > 1000) { + lastWhileActiveMsec = now; + whileActive(); + } // If we've already set time from the GPS, no need to ask the GPS bool gotTime = timeSetFromGPS || lookForTime(); diff --git a/src/gps/GPS.h b/src/gps/GPS.h index 3a7279c2..1f8429a4 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -28,7 +28,7 @@ void readFromRTC(); class GPS { private: - uint32_t lastWakeStartMsec = 0, lastSleepStartMsec = 0; + uint32_t lastWakeStartMsec = 0, lastSleepStartMsec = 0, lastWhileActiveMsec = 0; bool hasValidLocation = false; // default to false, until we complete our first read @@ -94,7 +94,7 @@ class GPS */ virtual bool whileIdle() = 0; - /** Idle processing while GPS is looking for lock */ + /** Idle processing while GPS is looking for lock, called once per secondish */ virtual void whileActive() {} /** @@ -134,7 +134,7 @@ class GPS uint32_t getSleepTime() const; GpsOperation getGpsOp() const; - + /** * Tell users we have new GPS readings */ diff --git a/src/gps/UBloxGPS.cpp b/src/gps/UBloxGPS.cpp index e34513d2..887fd62b 100644 --- a/src/gps/UBloxGPS.cpp +++ b/src/gps/UBloxGPS.cpp @@ -34,7 +34,8 @@ bool UBloxGPS::setupGPS() // _serial_gps.setRxBufferSize(1024); // the default is 256 } - ublox.enableDebugging(Serial); + // uncomment to see debug info + // ublox.enableDebugging(Serial); // try a second time, the ublox lib serial parsing is buggy? // see https://github.com/meshtastic/Meshtastic-device/issues/376 @@ -112,9 +113,19 @@ bool UBloxGPS::factoryReset() /** Idle processing while GPS is looking for lock */ void UBloxGPS::whileActive() { - // If we don't have a fix (a quick check), don't try waiting for a solution) - fixType = ublox.getFixType(maxWait()); - DEBUG_MSG("GPS fix type %d\n", fixType); + ublox.getT(maxWait()); // ask for new time data - hopefully ready when we come back + + // Ask for a new position fix - hopefully it will have results ready by next time + // the order here is important, because we only check for has latitude when reading + ublox.getSIV(maxWait()); + ublox.getPDOP(maxWait()); + ublox.getP(maxWait()); + + // Update fixtype + if (ublox.moduleQueried.fixType) { + fixType = ublox.getFixType(0); + DEBUG_MSG("GPS fix type %d\n", fixType); + } } /** @@ -141,8 +152,6 @@ bool UBloxGPS::lookForTime() t.tm_isdst = false; perhapsSetRTC(t); return true; - } else { - ublox.getT(maxWait()); // ask for new time data - hopefully ready when we come back } } @@ -177,11 +186,6 @@ bool UBloxGPS::lookForLocation() // Also: apparently when the GPS is initially reporting lock it can output a bogus latitude > 90 deg! foundLocation = (latitude != 0) && (longitude != 0) && (latitude <= 900000000 && latitude >= -900000000) && (numSatellites > 0); - } else { - // Ask for a new position fix - hopefully it will have results ready by next time - ublox.getSIV(maxWait()); - ublox.getPDOP(maxWait()); - ublox.getP(maxWait()); } } @@ -205,6 +209,7 @@ void UBloxGPS::sleep() void UBloxGPS::wake() { + fixType = 0; // assume we hace no fix yet setGPSPower(true); // Give time for the GPS to boot delay(200); diff --git a/src/main.cpp b/src/main.cpp index 424d9f4a..f4e811f5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -429,7 +429,7 @@ void loop() // FIXME - until button press handling is done by interrupt (see polling above) we can't sleep very long at all or buttons // feel slow - msecstosleep = 200; // FIXME, stop early if something happens + msecstosleep = 10; // FIXME, stop early if something happens and sleep much longer // TODO: This should go into a thread handled by FreeRTOS. handleWebResponse();