From 248cff59477863812029a0010b4b5763b162e415 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 20 Nov 2020 15:19:22 -0800 Subject: [PATCH 1/2] Add error handling and retries to play_tone --- adafruit_magtag/peripherals.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/adafruit_magtag/peripherals.py b/adafruit_magtag/peripherals.py index ce05700..58a33a6 100755 --- a/adafruit_magtag/peripherals.py +++ b/adafruit_magtag/peripherals.py @@ -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 @@ -121,3 +130,4 @@ def any_button_pressed(self): Return whether any button is pressed """ return False in [self.buttons[i].value for i in range(0, 4)] + From 9dd7e1749ec34ef4a08c885ee995296c8a68d6b0 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 20 Nov 2020 15:20:30 -0800 Subject: [PATCH 2/2] Ran black --- adafruit_magtag/peripherals.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_magtag/peripherals.py b/adafruit_magtag/peripherals.py index 58a33a6..3abd531 100755 --- a/adafruit_magtag/peripherals.py +++ b/adafruit_magtag/peripherals.py @@ -130,4 +130,3 @@ def any_button_pressed(self): Return whether any button is pressed """ return False in [self.buttons[i].value for i in range(0, 4)] -