Skip to content

Commit cac38e3

Browse files
committed
changes needed in base for mag tag
1 parent 4a885dc commit cac38e3

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

adafruit_pybadger/pybadger_base.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,26 @@
5050
import board
5151
from micropython import const
5252
import digitalio
53-
54-
try:
55-
import audiocore
56-
except ImportError:
57-
import audioio as audiocore
5853
from adafruit_bitmap_font import bitmap_font
5954
import displayio
6055
from adafruit_display_shapes.rect import Rect
6156
from adafruit_display_text import label
6257
import terminalio
6358
import adafruit_miniqr
6459

60+
AUDIO_ENABLED = False
61+
try:
62+
import audiocore
63+
64+
AUDIO_ENABLED = True
65+
except ImportError:
66+
try:
67+
import audioio as audiocore
68+
69+
AUDIO_ENABLED = True
70+
except ImportError:
71+
# Allow to work with no audio
72+
pass
6573
__version__ = "0.0.0-auto.0"
6674
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyBadger.git"
6775

@@ -685,11 +693,17 @@ def _sine_sample(length):
685693
yield int(tone_volume * math.sin(2 * math.pi * (i / length)) + shift)
686694

687695
def _generate_sample(self, length=100):
688-
if self._sample is not None:
689-
return
690-
self._sine_wave = array.array("H", PyBadgerBase._sine_sample(length))
691-
self._sample = self._audio_out(board.SPEAKER) # pylint: disable=not-callable
692-
self._sine_wave_sample = audiocore.RawSample(self._sine_wave)
696+
if AUDIO_ENABLED:
697+
if self._sample is not None:
698+
return
699+
self._sine_wave = array.array("H", PyBadgerBase._sine_sample(length))
700+
# pylint: disable=not-callable
701+
self._sample = self._audio_out(
702+
board.SPEAKER
703+
) # pylint: disable=not-callable
704+
self._sine_wave_sample = audiocore.RawSample(self._sine_wave)
705+
else:
706+
print("Required audio modules were missing")
693707

694708
def _enable_speaker(self, enable):
695709
if not hasattr(board, "SPEAKER_ENABLE"):

0 commit comments

Comments
 (0)