Merge pull request #116 from edgar-bonet/millis-rollover

Correct handling of millis() rollover
This commit is contained in:
Matt Goodrich 2020-02-25 11:55:56 -05:00 committed by GitHub
commit 8738b307ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 19 additions and 25 deletions

View File

@ -58,7 +58,7 @@ void setup()
Serial.println(" no response :(");
}
uint32_t updateTime = 1000;
uint32_t timer = 0;
void loop() // run over and over again
{
@ -67,9 +67,9 @@ void loop() // run over and over again
if ((c) && (GPSECHO))
Serial.write(c);
if (millis() > updateTime)
if (millis() - timer > 1000)
{
updateTime = millis() + 1000;
timer = millis();
if (GPS.LOCUS_ReadStatus()) {
Serial.print("\n\nLog #");
Serial.print(GPS.LOCUS_serial, DEC);
@ -98,5 +98,5 @@ void loop() // run over and over again
Serial.print((int)GPS.LOCUS_percent); Serial.print("% Used ");
}//if (GPS.LOCUS_ReadStatus())
}//if (millis() > updateTime)
}//if (millis() - timer > 1000)
}//loop

View File

@ -76,8 +76,6 @@ void loop() // run over and over again
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
// if millis() or timer wraps around, we'll just reset it
if (timer > millis()) timer = millis();
// approximately every 2 seconds or so, print out the current stats
if (millis() - timer > 2000) {

View File

@ -101,9 +101,6 @@ void loop() // run over and over again
return; // we can fail to parse a sentence in which case we should just
// wait for another
}
// if millis() or timer wraps around, we'll just reset it
if (timer > millis())
timer = millis();
// approximately every 2 seconds or so, random intervals, print out the
// current stats

View File

@ -64,8 +64,6 @@ void loop() // run over and over again
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
// if millis() or timer wraps around, we'll just reset it
if (timer > millis()) timer = millis();
// approximately every 2 seconds or so, print out the current stats
if (millis() - timer > 2000) {

View File

@ -68,7 +68,7 @@ void setup()
}
}
uint32_t updateTime = 1000;
uint32_t timer = 0;
void loop() // run over and over again
{
@ -77,9 +77,9 @@ void loop() // run over and over again
if ((c) && (GPSECHO))
Serial.write(c);
if (millis() > updateTime)
if (millis() - timer > 1000)
{
updateTime = millis() + 1000;
timer = millis();
if (GPS.LOCUS_ReadStatus()) {
Serial.print("\n\nLog #");
Serial.print(GPS.LOCUS_serial, DEC);
@ -108,7 +108,7 @@ void loop() // run over and over again
Serial.print((int)GPS.LOCUS_percent); Serial.print("% Used ");
}//if (GPS.LOCUS_ReadStatus())
}//if (millis() > updateTime)
}//if (millis() - timer > 1000)
}//loop

View File

@ -78,9 +78,6 @@ void loop() // run over and over again
return; // we can fail to parse a sentence in which case we should just wait for another
}
// if millis() or timer wraps around, we'll just reset it
if (timer > millis()) timer = millis();
// approximately every 2 seconds or so, print out the current stats
if (millis() - timer > 2000) {
timer = millis(); // reset the timer

View File

@ -637,8 +637,10 @@ bool Adafruit_GPS::wakeup(void) {
/**************************************************************************/
/*!
@brief Time in seconds since the last position fix was obtained. Will
fail by rolling over to zero after one millis() cycle, about 6-1/2 weeks.
@brief Time in seconds since the last position fix was obtained. The
time returned is limited to 2^32 milliseconds, which is about 49.7 days.
It will wrap around to zero if no position fix is received
for this long.
@return nmea_float_t value in seconds since last fix.
*/
/**************************************************************************/
@ -648,8 +650,9 @@ nmea_float_t Adafruit_GPS::secondsSinceFix() {
/**************************************************************************/
/*!
@brief Time in seconds since the last GPS time was obtained. Will fail
by rolling over to zero after one millis() cycle, about 6-1/2 weeks.
@brief Time in seconds since the last GPS time was obtained. The time
returned is limited to 2^32 milliseconds, which is about 49.7 days. It
will wrap around to zero if no GPS time is received for this long.
@return nmea_float_t value in seconds since last GPS time.
*/
/**************************************************************************/
@ -659,8 +662,9 @@ nmea_float_t Adafruit_GPS::secondsSinceTime() {
/**************************************************************************/
/*!
@brief Time in seconds since the last GPS date was obtained. Will fail
by rolling over to zero after one millis() cycle, about 6-1/2 weeks.
@brief Time in seconds since the last GPS date was obtained. The time
returned is limited to 2^32 milliseconds, which is about 49.7 days. It
will wrap around to zero if no GPS date is received for this long.
@return nmea_float_t value in seconds since last GPS date.
*/
/**************************************************************************/

View File

@ -60,7 +60,7 @@ void Adafruit_GPS::newDataValue(nmea_index_t idx, nmea_float_t v) {
// weighting factor for smoothing depends on delta t / tau
nmea_float_t w =
min((nmea_float_t)1.0,
((nmea_float_t)millis() - val[idx].lastUpdate) / val[idx].response);
(nmea_float_t)(millis() - val[idx].lastUpdate) / val[idx].response);
// default smoothing
val[idx].smoothed = (1.0 - w) * val[idx].smoothed + w * v;
// special smoothing for some angle types