Browse Source

Merge pull request #1350 from weebl2000/sync-gps-time-30min

Sync gps time every 30min
pull/1957/head
Liam Cottle 3 months ago
committed by GitHub
parent
commit
5dddb8a3a1
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      src/helpers/sensors/MicroNMEALocationProvider.h

7
src/helpers/sensors/MicroNMEALocationProvider.h

@ -43,6 +43,8 @@ class MicroNMEALocationProvider : public LocationProvider {
int _pin_en; int _pin_en;
long next_check = 0; long next_check = 0;
long time_valid = 0; long time_valid = 0;
unsigned long _last_time_sync = 0;
static const unsigned long TIME_SYNC_INTERVAL = 1800000; // Re-sync every 30 minutes
public : public :
MicroNMEALocationProvider(Stream& ser, mesh::RTCClock* clock = NULL, int pin_reset = GPS_RESET, int pin_en = GPS_EN,RefCountedDigitalPin* peripher_power=NULL) : MicroNMEALocationProvider(Stream& ser, mesh::RTCClock* clock = NULL, int pin_reset = GPS_RESET, int pin_en = GPS_EN,RefCountedDigitalPin* peripher_power=NULL) :
@ -129,10 +131,15 @@ public :
if (millis() > next_check) { if (millis() > next_check) {
next_check = millis() + 1000; next_check = millis() + 1000;
// Re-enable time sync periodically when GPS has valid fix
if (!_time_sync_needed && _clock != NULL && (millis() - _last_time_sync) > TIME_SYNC_INTERVAL) {
_time_sync_needed = true;
}
if (_time_sync_needed && time_valid > 2) { if (_time_sync_needed && time_valid > 2) {
if (_clock != NULL) { if (_clock != NULL) {
_clock->setCurrentTime(getTimestamp()); _clock->setCurrentTime(getTimestamp());
_time_sync_needed = false; _time_sync_needed = false;
_last_time_sync = millis();
} }
} }
if (isValid()) { if (isValid()) {

Loading…
Cancel
Save