Skip to content
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

try time.ticks_ms #8

Merged
merged 1 commit into from
Oct 15, 2022
Merged

try time.ticks_ms #8

merged 1 commit into from
Oct 15, 2022

Conversation

jepler
Copy link
Member

@jepler jepler commented Oct 14, 2022

.. which allows adafruit_ticks to be imported in micropython or (more importantly) from the 'unix port' of CircuitPython, used for some automated testing.

This is a step towards allowing the build-time testsuite to run with Adafruit_CircuitPython_asyncio instead of micropython's uasyncio.

The patch reindents a block of code, so it's best understood through the output of git show -b which doesn't show whitespace changes:

@@ -52,6 +55,28 @@ _TICKS_HALFPERIOD = const(_TICKS_PERIOD // 2)
 try:
     from supervisor import ticks_ms  # pylint: disable=unused-import
 except (ImportError, NameError):
+    import time
+
+    if _ticks_ms := getattr(time, "ticks_ms", None):
+
+        def ticks_ms() -> int:
+            """Return the time in milliseconds since an unspecified moment,
+            wrapping after 2**29ms.
+
+            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."""
+            return _ticks_ms() & _TICKS_MAX  # pylint: disable=not-callable
+
+    else:
         try:
             from time import monotonic_ns as _monotonic_ns

.. which allows adafruit_ticks to be imported in micropython or
(more importantly) from the 'unix port' of CircuitPython, used for some
automated testing.

This is a step towards allowing the build-time testsuite to run with
Adafruit_CircuitPython_asyncio instead of micropython's uasyncio.
jepler added a commit to jepler/circuitpython that referenced this pull request Oct 14, 2022
This also depends on adafruit/Adafruit_CircuitPython_Ticks#8
otherwise adafruit_ticks is unimportable and the tests are just skipped.

Several of the tests fail, and one runs forever instead of terminating.

We should fix our asyncio until the tests patch, then incorporate this
change.
Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it, looks good.

@dhalbert dhalbert merged commit 7832bbb into main Oct 15, 2022
@dhalbert dhalbert deleted the try-time-ticksms branch October 15, 2022 03:13
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Oct 19, 2022
Updating https://github.com/adafruit/Adafruit_CircuitPython_ADXL34x to 1.12.7 from 1.12.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_ADXL34x#37 from tekktrik/dev/fix-value-error

Updating https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SSD1306 to 1.5.10 from 1.5.9:
  > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_SSD1306#29 from tekktrik/dev/fix-type-annotation

Updating https://github.com/adafruit/Adafruit_CircuitPython_GPS to 3.10.6 from 3.10.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_GPS#90 from tekktrik/dev/fix-example-import

Updating https://github.com/adafruit/Adafruit_CircuitPython_PM25 to 2.1.13 from 2.1.12:
  > Merge pull request adafruit/Adafruit_CircuitPython_PM25#25 from tekktrik/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_SD to 3.3.15 from 3.3.14:
  > Merge pull request adafruit/Adafruit_CircuitPython_SD#51 from calcut/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_SHTC3 to 1.1.10 from 1.1.9:
  > Merge pull request adafruit/Adafruit_CircuitPython_SHTC3#17 from tcfranks/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_asyncio to 0.5.17 from 0.5.16:
  > Merge pull request adafruit/Adafruit_CircuitPython_asyncio#30 from jepler/make-tests-pass

Updating https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer to 0.5.2 from 0.5.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_HTTPServer#15 from FoamyGuy/smaller_file_read_buffer

Updating https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad to 1.16.7 from 1.16.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#61 from deshipu/png

Updating https://github.com/adafruit/Adafruit_CircuitPython_Ticks to 1.0.8 from 1.0.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_Ticks#8 from adafruit/try-time-ticksms
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.

2 participants