1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
3 # SPDX-License-Identifier: MIT
4 """Platform agnostic time implementation"""
6 from adafruit_blinka import agnostic
8 # We intentionally are patching into this namespace so skip the wildcard check.
9 # pylint: disable=unused-wildcard-import,wildcard-import
11 if agnostic.implementation == "circuitpython":
13 elif agnostic.implementation == "micropython":
15 from utime import sleep
17 from ucollections import namedtuple
19 _struct_time = namedtuple(
34 # pylint: disable=too-many-arguments
46 """Construct struct_time with default values."""
59 def struct_time(time_tuple):
60 """Create a struct_time"""
61 return _marshal_time(*time_tuple)
63 # pylint: disable=invalid-name
65 _prev_ticks_ms = utime.ticks_ms()
68 """A monotonically increasing time in seconds. No defined start time."""
69 # Assumes that monotonic is called more frequently than the wraparound of micropython's
71 global _prev_ticks_ms, _total_ms # pylint: disable=global-statement
72 ticks_ms = utime.ticks_ms()
73 _total_ms += utime.ticks_diff(ticks_ms, _prev_ticks_ms)
74 _prev_ticks_ms = ticks_ms
75 return _total_ms * 0.001