Skip to content

Add error handling and retries to play_tone #18

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

Merged
merged 2 commits into from
Nov 20, 2020
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
13 changes: 11 additions & 2 deletions adafruit_magtag/peripherals.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,19 @@ def __init__(self):
def play_tone(self, frequency, duration):
"""Automatically Enable/Disable the speaker and play
a tone at the specified frequency for the specified duration

It will attempt to play the sound up to 3 times in the case of
an error.
"""
self._speaker_enable.value = True
simpleio.tone(board.SPEAKER, frequency, duration)
attempt = 0
# Try up to 3 times to play the sound
while attempt < 3:
try:
simpleio.tone(board.SPEAKER, frequency, duration)
break
except NameError:
pass
attempt += 1
self._speaker_enable.value = False

@property
Expand Down