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

Fix screensaver timer to be less reliant on exact timing #359

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions software/firmware/experimental/screensaver.py
Original file line number Diff line number Diff line change
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
Loading