Skip to content
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

Update library for PyGamer/PyBadge #45

Merged
merged 4 commits into from
Jul 24, 2019
Merged
Changes from 1 commit
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
49 changes: 35 additions & 14 deletions adafruit_pyportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@
import busio
from digitalio import DigitalInOut
import pulseio
import adafruit_touchscreen
import neopixel
try:
brentru marked this conversation as resolved.
Show resolved Hide resolved
import adafruit_touchscreen
except ImportError:
pass
try:
from adafruit_cursorcontrol.cursorcontrol import Cursor
from adafruit_cursorcontrol.cursorcontrol_cursormanager import CursorManager
except ImportError:
pass

from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
import adafruit_esp32spi.adafruit_esp32spi_requests as requests
Expand Down Expand Up @@ -164,6 +172,8 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
self._debug = debug

try:
self._backlight = pulseio.PWMOut(board.TFT_LITE) # pylint: disable=no-member
brentru marked this conversation as resolved.
Show resolved Hide resolved
except AttributeError:
self._backlight = pulseio.PWMOut(board.TFT_BACKLIGHT) # pylint: disable=no-member
except ValueError:
self._backlight = None
Expand Down Expand Up @@ -224,7 +234,10 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,

self._speaker_enable = DigitalInOut(board.SPEAKER_ENABLE)
self._speaker_enable.switch_to_output(False)
self.audio = audioio.AudioOut(board.AUDIO_OUT)
try: # PyPortal
brentru marked this conversation as resolved.
Show resolved Hide resolved
self.audio = audioio.AudioOut(board.AUDIO_OUT)
except AttributeError: # PyGamer/PyBadge
self.audio = audioio.AudioOut(board.SPEAKER)
try:
self.play_file("pyportal_startup.wav")
except OSError:
Expand Down Expand Up @@ -347,18 +360,26 @@ def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None,
self._image_position = (0, 0) # default to top corner
if not self._image_resize:
self._image_resize = (320, 240) # default to full screen

if self._debug:
print("Init touchscreen")
# pylint: disable=no-member
self.touchscreen = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR,
board.TOUCH_YD, board.TOUCH_YU,
calibration=((5200, 59000),
(5800, 57000)),
size=(320, 240))
# pylint: enable=no-member

self.set_backlight(1.0) # turn on backlight
if hasattr(board, 'TOUCH_XL'):
if self._debug:
print("Init touchscreen")
# pylint: disable=no-member
self.touchscreen = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR,
board.TOUCH_YD, board.TOUCH_YU,
calibration=((5200, 59000),
(5800, 57000)),
size=(320, 240))
# pylint: enable=no-member

self.set_backlight(1.0) # turn on backlight
elif hasattr(board, 'BUTTON_CLOCK'):
if self._debug:
print("Init cursor")
self.mouse_cursor = Cursor(board.DISPLAY, display_group=self.splash, cursor_speed=8)
self.mouse_cursor.hide()
self.cursor = CursorManager(self.mouse_cursor)
else:
raise AttributeError('PyPortal module requires either a touchscreen or gamepad.')

gc.collect()

Expand Down