switch to monotonic_ns to handle long uptimes

This commit is contained in:
Roy Hooper 2019-11-29 20:59:49 -05:00
parent 245089b1f3
commit 487bf35adc

View file

@ -69,14 +69,12 @@ class Animation:
configured by the speed property (set from init).
:return: True if the animation draw cycle was triggered, otherwise False.
"""
now = time.monotonic()
now = time.monotonic_ns()
if now < self._next_update:
return False
self.draw()
now = time.monotonic()
self._next_update = now + self.speed
self._next_update = now + self._speed_ns
return True
def draw(self):
@ -98,6 +96,18 @@ class Animation:
self._color = color
self._recompute_color(color)
@property
def speed(self):
"""
Get or set the animation speed in fractional seconds.
:return: speed
"""
return self._speed_ns / 1000000000
@speed.setter
def speed(self, seconds):
self._speed_ns = int(seconds * 1000000000)
def _recompute_color(self, color):
pass