-
Notifications
You must be signed in to change notification settings - Fork 1.3k
supervisor: Add a function to get "wrapping" milliseconds #4936
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
Conversation
As discussed in adafruit#3410, this is a micropython-compatible (though differently named) function that allows creation of useful time and deadline functions in pure python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! But given the simplicity of the Python code you suggest in the documentation, should we:
- Make a simple library?
- Implement those routines in a native module? Perhaps a new
ticks
module, or added to supervisor?
Once #4903 is merged, we will have the room.
I think that I'd rather leave monotonic as is, and add this new functionality only. I studied the LED animation library and I think it's pretty easy to adapt it to wrapping ticks (made harder by the need for compatibility with 6.x). If that's typical of libraries that like to count intervals, then this is the way to go and the other complication is not needed. We still need to address the problem with this not fitting on a couple of boards, though, and decide whether to offer this as 1 function in supervisor or 3 or 4 functions in a new module. |
I am OK with adding this to |
Single function here + small python library sounds good. The reason to make a new module would be that we could make it available on some boards but not others then. That's also ok with me. |
How will it work with Blinka if libraries are updated with it ? |
Blinka has microcontroller but not supervisor. So we could either add supervisor to blinka, or move this to a location where blinka already provides a module, such as microcontroller.
|
@makermelissa do you have an opinion about the placement of this proposed |
As discussed in #3410, this is a micropython-compatible (though differently named) function that allows creation of useful time and deadline functions in pure python.
Closes: #3410
An alternative to #4935 which only adds the wrapped ticks and doesn't change the monotonic reference time.
supervisor.ticks_ms() → int
Return the time in milliseconds since an unspecified reference point, wrapping after 2**29ms.
The value is initialized so that the first overflow occurs about 65 seconds after power-on, making it feasible to check that your program works properly around an overflow.
The wrap value was chosen so that it is always possible to add or subtract two
ticks_ms
values without overflow on a board without long ints (or without allocating any long integer objects, on boards with long ints).This ticks value comes from a low-accuracy clock internal to the microcontroller, just like
time.monotonic
. Due to its low accuracy and the fact that it “wraps around” every few days, it is intended for working with short term events like advancing an LED animation, not for long term events like counting down the time until a holiday.Addition, subtraction, and comparison of ticks values can be done with routines like the following: