Constantin
Well-known member
Hi Everyone,
I have a question re: setTime(t), the part of the Time.h library that tells the Teensy how many seconds have elapsed since 1/1/1970. When that command is invoked, does the underlying interval get reset too? For example,
1) Teensy running along fine and time_t =1000. It has been 500 millis since time_t advanced to current state.
2) I invoke setTime(600).
3) time_t should now be 600, but when will it advance to 601? In ~500 millis or 1000millis?
The reason I ask, is that I want synchronize multiple Teensy's and if the underlying interval to advance each time_t is reset whenever setTime(t) is called, then that task would be a lot easier. Here is the relevant code from the Time.cpp file in Paul's Github Repo.
and
To me, the above suggests that when setTime is invoked, that the interval is restarted as well. Did I get that right?
I have a question re: setTime(t), the part of the Time.h library that tells the Teensy how many seconds have elapsed since 1/1/1970. When that command is invoked, does the underlying interval get reset too? For example,
1) Teensy running along fine and time_t =1000. It has been 500 millis since time_t advanced to current state.
2) I invoke setTime(600).
3) time_t should now be 600, but when will it advance to 601? In ~500 millis or 1000millis?
The reason I ask, is that I want synchronize multiple Teensy's and if the underlying interval to advance each time_t is reset whenever setTime(t) is called, then that task would be a lot easier. Here is the relevant code from the Time.cpp file in Paul's Github Repo.
Code:
time_t now() {
// calculate number of seconds passed since last call to now()
while (millis() - prevMillis >= 1000) {
// millis() and prevMillis are both unsigned ints thus the subtraction will always be the absolute value of the difference
sysTime++;
prevMillis += 1000;
#ifdef TIME_DRIFT_INFO
sysUnsyncedTime++; // this can be compared to the synced time to measure long term drift
#endif
}
if (nextSyncTime <= sysTime) {
if (getTimePtr != 0) {
time_t t = getTimePtr();
if (t != 0) {
setTime(t);
} else {
nextSyncTime = sysTime + syncInterval;
Status = (Status == timeNotSet) ? timeNotSet : timeNeedsSync;
}
}
}
return (time_t)sysTime;
}
and
Code:
void setTime(time_t t) {
#ifdef TIME_DRIFT_INFO
if(sysUnsyncedTime == 0)
sysUnsyncedTime = t; // store the time of the first call to set a valid Time
#endif
sysTime = (uint32_t)t;
nextSyncTime = (uint32_t)t + syncInterval;
Status = timeSet;
prevMillis = millis(); // restart counting from now (thanks to Korman for this fix)
}
To me, the above suggests that when setTime is invoked, that the interval is restarted as well. Did I get that right?
Last edited: