arduino-managed-serial-device icon indicating copy to clipboard operation
arduino-managed-serial-device copied to clipboard

millis() timer overflow after 49 days of runtime

Open mrmichaelrb opened this issue 5 years ago • 1 comments

These kinds of comparisons don't allow for overflow:

commandQueue[position].delay = _delay + millis(); ... if(!processing && queueLength > 0 && commandQueue[0].delay <= millis()) {

timeout = millis() + commandQueue[0].timeout; ... if(_timeout && (millis() > started + _timeout)) {

Admittedly this is a problem that will only occur every 49 days, but still...

See this for examples of best practices: Worried about millis() timer overflow?

Basically, you should do this instead (add a new "start" property): command.start = millis(); command.delay = _delay;

And then this should be the check: if (millis() - command.start >= command.delay) {

mrmichaelrb avatar May 28 '19 00:05 mrmichaelrb

Feel free to post a pull request! In my case, im unlikely to run for longer than two hours at a time; so I'm not super worried about it.

coddingtonbear avatar May 28 '19 00:05 coddingtonbear