1 """Platform agnostic time implementation"""
 
   3 from adafruit_blinka import agnostic
 
   5 # We intentionally are patching into this namespace so skip the wildcard check.
 
   6 # pylint: disable=unused-wildcard-import,wildcard-import
 
   8 if agnostic.implementation == "circuitpython":
 
  10 elif agnostic.implementation == "micropython":
 
  12     from utime import sleep
 
  14     from ucollections import namedtuple
 
  16     _struct_time = namedtuple(
 
  31     # pylint: disable=too-many-arguments
 
  43         """Construct struct_time with default values."""
 
  56     def struct_time(time_tuple):
 
  57         """Create a struct_time"""
 
  58         return _marshal_time(*time_tuple)
 
  60     # pylint: disable=invalid-name
 
  62     _prev_ticks_ms = utime.ticks_ms()
 
  65         """A monotonically increasing time in seconds. No defined start time."""
 
  66         # Assumes that monotonic is called more frequently than the wraparound of micropython's
 
  68         global _prev_ticks_ms, _total_ms  # pylint: disable=global-statement
 
  69         ticks_ms = utime.ticks_ms()
 
  70         _total_ms += utime.ticks_diff(ticks_ms, _prev_ticks_ms)
 
  71         _prev_ticks_ms = ticks_ms
 
  72         return _total_ms * 0.001