|
50 | 50 | import busio
|
51 | 51 | from digitalio import DigitalInOut
|
52 | 52 | import pulseio
|
53 |
| -import adafruit_touchscreen |
54 | 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 |
55 | 63 |
|
56 | 64 | from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
|
57 | 65 | import adafruit_esp32spi.adafruit_esp32spi_requests as requests
|
@@ -164,6 +172,8 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
|
164 | 172 | self._debug = debug
|
165 | 173 |
|
166 | 174 | try:
|
| 175 | + self._backlight = pulseio.PWMOut(board.TFT_LITE) # pylint: disable=no-member |
| 176 | + except AttributeError: |
167 | 177 | self._backlight = pulseio.PWMOut(board.TFT_BACKLIGHT) # pylint: disable=no-member
|
168 | 178 | except ValueError:
|
169 | 179 | self._backlight = None
|
@@ -224,7 +234,10 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
|
224 | 234 |
|
225 | 235 | self._speaker_enable = DigitalInOut(board.SPEAKER_ENABLE)
|
226 | 236 | self._speaker_enable.switch_to_output(False)
|
227 |
| - self.audio = audioio.AudioOut(board.AUDIO_OUT) |
| 237 | + try: # PyPortal |
| 238 | + self.audio = audioio.AudioOut(board.AUDIO_OUT) |
| 239 | + except AttributeError: # PyGamer/PyBadge |
| 240 | + self.audio = audioio.AudioOut(board.SPEAKER) |
228 | 241 | try:
|
229 | 242 | self.play_file("pyportal_startup.wav")
|
230 | 243 | except OSError:
|
@@ -347,18 +360,26 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
|
347 | 360 | self._image_position = (0, 0) # default to top corner
|
348 | 361 | if not self._image_resize:
|
349 | 362 | self._image_resize = (320, 240) # default to full screen
|
350 |
| - |
351 |
| - if self._debug: |
352 |
| - print("Init touchscreen") |
353 |
| - # pylint: disable=no-member |
354 |
| - self.touchscreen = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, |
355 |
| - board.TOUCH_YD, board.TOUCH_YU, |
356 |
| - calibration=((5200, 59000), |
357 |
| - (5800, 57000)), |
358 |
| - size=(320, 240)) |
359 |
| - # pylint: enable=no-member |
360 |
| - |
361 |
| - self.set_backlight(1.0) # turn on backlight |
| 363 | + if hasattr(board, 'TOUCH_XL'): |
| 364 | + if self._debug: |
| 365 | + print("Init touchscreen") |
| 366 | + # pylint: disable=no-member |
| 367 | + self.touchscreen = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, |
| 368 | + board.TOUCH_YD, board.TOUCH_YU, |
| 369 | + calibration=((5200, 59000), |
| 370 | + (5800, 57000)), |
| 371 | + size=(320, 240)) |
| 372 | + # pylint: enable=no-member |
| 373 | + |
| 374 | + self.set_backlight(1.0) # turn on backlight |
| 375 | + elif hasattr(board, 'BUTTON_CLOCK'): |
| 376 | + if self._debug: |
| 377 | + print("Init cursor") |
| 378 | + self.mouse_cursor = Cursor(board.DISPLAY, display_group=self.splash, cursor_speed=8) |
| 379 | + self.mouse_cursor.hide() |
| 380 | + self.cursor = CursorManager(self.mouse_cursor) |
| 381 | + else: |
| 382 | + raise AttributeError('PyPortal module requires either a touchscreen or gamepad.') |
362 | 383 |
|
363 | 384 | gc.collect()
|
364 | 385 |
|
|
0 commit comments