Skip to content

Commit

Permalink
Don't rely on modular arithmetic for the screensaver; just check the …
Browse files Browse the repository at this point in the history
…elapsed time from the last reposition (#359)
  • Loading branch information
chrisib committed Mar 21, 2024
1 parent ac05257 commit cc9d08f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions software/firmware/experimental/screensaver.py
Expand Up @@ -34,6 +34,9 @@ class Screensaver:
## Standard duration before we blank the screen
BLANK_TIMEOUT_MS = 1000 * 60 * 20

def __init__(self):
self.last_logo_reposition_at = 0

def draw(self, force=False):
"""Draw the logo to a random position on the screen
Expand All @@ -45,8 +48,9 @@ def draw(self, force=False):
"""
LOGO_UPDATE_INTERVAL = 2000

ms = utime.ticks_ms()
if force or ms % LOGO_UPDATE_INTERVAL == 0:
now = utime.ticks_ms()
if force or time.ticks_diff(now, self.last_logo_reposition_at) > LOGO_UPDATE_INTERVAL:
self.last_logo_reposition_at = now
x = random.randint(0, OLED_WIDTH - self.LOGO_WIDTH)
y = random.randint(0, OLED_HEIGHT - self.LOGO_HEIGHT)

Expand Down

0 comments on commit cc9d08f

Please sign in to comment.