|
51 | 51 | from digitalio import DigitalInOut
|
52 | 52 | import pulseio
|
53 | 53 | import neopixel
|
54 |
| -try: |
55 |
| - import adafruit_touchscreen |
56 |
| -except ImportError: |
57 |
| - pass |
58 |
| -try: |
59 |
| - from adafruit_cursorcontrol.cursorcontrol import Cursor |
60 |
| - from adafruit_cursorcontrol.cursorcontrol_cursormanager import CursorManager |
61 |
| -except ImportError: |
62 |
| - pass |
| 54 | + |
| 55 | +import adafruit_touchscreen |
| 56 | +from adafruit_cursorcontrol.cursorcontrol import Cursor |
| 57 | +from adafruit_cursorcontrol.cursorcontrol_cursormanager import CursorManager |
63 | 58 |
|
64 | 59 | from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
|
65 | 60 | import adafruit_esp32spi.adafruit_esp32spi_requests as requests
|
@@ -171,11 +166,11 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
|
171 | 166 |
|
172 | 167 | self._debug = debug
|
173 | 168 |
|
174 |
| - try: |
175 |
| - self._backlight = pulseio.PWMOut(board.TFT_LITE) # pylint: disable=no-member |
176 |
| - except AttributeError: |
| 169 | + if hasattr(board, 'TFT_BACKLIGHT'): |
177 | 170 | self._backlight = pulseio.PWMOut(board.TFT_BACKLIGHT) # pylint: disable=no-member
|
178 |
| - except ValueError: |
| 171 | + elif hasattr(board, 'TFT_LITE'): |
| 172 | + self._backlight = pulseio.PWMOut(board.TFT_LITE) # pylint: disable=no-member |
| 173 | + else: |
179 | 174 | self._backlight = None
|
180 | 175 | self.set_backlight(1.0) # turn on backlight
|
181 | 176 |
|
@@ -234,10 +229,12 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
|
234 | 229 |
|
235 | 230 | self._speaker_enable = DigitalInOut(board.SPEAKER_ENABLE)
|
236 | 231 | self._speaker_enable.switch_to_output(False)
|
237 |
| - try: # PyPortal |
| 232 | + if hasattr(board, 'AUDIO_OUT'): |
238 | 233 | self.audio = audioio.AudioOut(board.AUDIO_OUT)
|
239 |
| - except AttributeError: # PyGamer/PyBadge |
| 234 | + elif hasattr(board, 'SPEAKER'): |
240 | 235 | self.audio = audioio.AudioOut(board.SPEAKER)
|
| 236 | + else: |
| 237 | + raise AttributeError('Board does not have a builtin speaker!') |
241 | 238 | try:
|
242 | 239 | self.play_file("pyportal_startup.wav")
|
243 | 240 | except OSError:
|
|
0 commit comments