Skip to content

Timer: Cleanup and fix millis() rollover bug #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Timer: Cleanup and fix millis() rollover bug #6

wants to merge 5 commits into from

Conversation

edgar-bonet
Copy link

This pull request does some cleanup on the Timer module, removing code that has no effect other than making the source longer and harder to read. It also removes the lines intended to detect a millis() rollover event:

if(LastTime > millis()*2)//millis restarted
        LastTime = 0;

These lines are responsible from the issue #4. Besides, they serve no useful purpose, as the test that follows is rollover safe.

The three constructors have been replaced by a single one with default
arguments. Timer::Create(), now redundant, has been removed.
Since the argument has an unsigned type, it cannot be negative.
Since unsigned numbers obey the rules of modular arithmetics, the usual
rules of commutativity and associativity of addition apply.
There is no point in trying to detect a millis() rollover event as, per
the rules of modular arithmetics, the subtraction

    millis() - LastTime

is rollover safe.

Fixes #4.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant