def __init__(self): self.splash = displayio.Group(max_size=5) self.bg_group = displayio.Group(max_size=1) board.DISPLAY.auto_brightness = True self.bg_file = None self.texts = [] # touchscreen 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)) # connecting wifi self.wifi = connect_wifi() # connecting io self.connect_io() # setting local time set_local_time() # getting last feed time from adafruit io self.prev_feed_end_time, self.prev_feed_start_time, self.prev_feed_count = self.get_last_feed_time() board.DISPLAY.show(self.splash)
def __init__(self) -> None: self.root_group = displayio.Group() self._display = board.DISPLAY self._background_group = displayio.Group() self.root_group.append(self._background_group) self._text_group = displayio.Group() self.root_group.append(self._text_group) self._button_group = displayio.Group() self.root_group.append(self._button_group) if self._display.height > 250: self._text_group.scale = 2 self._button_group.scale = 2 self._speaker_enable = DigitalInOut(board.SPEAKER_ENABLE) self._speaker_enable.switch_to_output(False) if hasattr(board, "AUDIO_OUT"): self.audio = audioio.AudioOut(board.AUDIO_OUT) elif hasattr(board, "SPEAKER"): self.audio = audioio.AudioOut(board.SPEAKER) else: raise AttributeError("Board does not have an audio output!") self._background_file = None self._wavfile = None try: self._display.auto_brightness = False except AttributeError: pass self.backlight_fade(0) self._display.show(self.root_group) self.touchscreen = None self.mouse_cursor = None if hasattr(board, "TOUCH_XL"): self.touchscreen = adafruit_touchscreen.Touchscreen( board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU, calibration=((5200, 59000), (5800, 57000)), size=(self._display.width, self._display.height), ) elif hasattr(board, "BUTTON_CLOCK"): self.mouse_cursor = Cursor(self._display, display_group=self.root_group, cursor_speed=8) self.cursor = CursorManager(self.mouse_cursor) else: raise AttributeError("PYOA requires a touchscreen or cursor.") self._gamedirectory = None self._gamefilename = None self._game = None self._text = None self._background_sprite = None self._text_font = None self._left_button = None self._right_button = None self._middle_button = None
def __init__(self): self.root_group = displayio.Group(max_size=15) self._background_group = displayio.Group(max_size=1) self.root_group.append(self._background_group) self._text_group = displayio.Group(max_size=1) self.root_group.append(self._text_group) self._button_group = displayio.Group(max_size=2) self.root_group.append(self._button_group) self._speaker_enable = DigitalInOut(board.SPEAKER_ENABLE) self._speaker_enable.switch_to_output(False) if hasattr(board, 'AUDIO_OUT'): self.audio = audioio.AudioOut(board.AUDIO_OUT) elif hasattr(board, 'SPEAKER'): self.audio = audioio.AudioOut(board.SPEAKER) else: raise AttributeError('Board does not have an audio output!') self._background_file = None self._wavfile = None board.DISPLAY.auto_brightness = False self.backlight_fade(0) board.DISPLAY.show(self.root_group) self.touchscreen = None if hasattr(board, 'TOUCH_XL'): 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)) elif hasattr(board, 'BUTTON_CLOCK'): self.mouse_cursor = Cursor(board.DISPLAY, display_group=self.root_group, cursor_speed=8) self.cursor = CursorManager(self.mouse_cursor) else: raise AttributeError('PYOA requires a touchscreen or cursor.') self._gamedirectory = None self._gamefilename = None self._game = None self._text = None self._background_sprite = None self._text_font = None self._left_button = None self._right_button = None self._middle_button = None
def __init__(self, splash, cursor_bmp): logging.getLogger('Paint').debug('Creating a TouchscreenPoller') self._display_grp = splash self._touchscreen = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU, calibration=((9000, 59000), (8000, 57000)), size=(320, 240)) self._cursor_grp = displayio.Group(max_size=1) self._cur_palette = displayio.Palette(3) self._cur_palette.make_transparent(0) self._cur_palette[1] = 0xFFFFFF self._cur_palette[2] = 0x0000 self._cur_sprite = displayio.TileGrid(cursor_bmp, pixel_shader=self._cur_palette) self._cursor_grp.append(self._cur_sprite) self._display_grp.append(self._cursor_grp) self._x_offset = cursor_bmp.width // 2 self._y_offset = cursor_bmp.height // 2
def __init__(self): self.root_group = displayio.Group(max_size=15) self._background_group = displayio.Group(max_size=1) self.root_group.append(self._background_group) self._text_group = displayio.Group(max_size=1) self.root_group.append(self._text_group) self._button_group = displayio.Group(max_size=2) self.root_group.append(self._button_group) self._speaker_enable = DigitalInOut(board.SPEAKER_ENABLE) self._speaker_enable.switch_to_output(False) self.audio = audioio.AudioOut(board.AUDIO_OUT) self._background_file = None self._wavfile = None board.DISPLAY.auto_brightness = False self.backlight_fade(0) board.DISPLAY.show(self.root_group) 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)) self._gamedirectory = None self._gamefilename = None self._game = None self._text = None self._background_sprite = None self._text_font = None self._left_button = None self._right_button = None self._middle_button = None
SCREEN_HEIGHT = board.DISPLAY.height BUTTON_WIDTH = int(SCREEN_WIDTH / 5) # was 60 BUTTON_HEIGHT = int(SCREEN_WIDTH / 10) # was 30 BUTTON_MARGIN = 8 MAX_DIGITS = 29 BLACK = 0x0 ORANGE = 0xFF8800 BLUE = 0x0088FF WHITE = 0xFFFFFF GRAY = 0x666666 LABEL_OFFSET = int(SCREEN_WIDTH - (SCREEN_WIDTH / 7)) ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU, calibration=((5200, 59000), (5800, 57000)), size=(SCREEN_WIDTH, SCREEN_HEIGHT)) # Make the display context calc_group = displayio.Group(max_size=25) board.DISPLAY.show(calc_group) # Make a background color fill color_bitmap = displayio.Bitmap(SCREEN_WIDTH, SCREEN_HEIGHT, 1) color_palette = displayio.Palette(1) color_palette[0] = GRAY bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0,
def __init__(self): self.root_group = displayio.Group(max_size=15) self._background_group = displayio.Group(max_size=1) self.root_group.append(self._background_group) self._text_group = displayio.Group(max_size=1) self.root_group.append(self._text_group) self._button_group = displayio.Group(max_size=2) self.root_group.append(self._button_group) self._text_font = bitmap_font.load_font("Arial-Bold-12.bdf") #self._text_font = fontio.BuiltinFont try: glyphs = b'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-!,. "\'?!' print("Preloading font glyphs:", glyphs) self._text_font.load_glyphs(glyphs) except AttributeError: pass # normal for built in font self._left_button = Button(x=10, y=195, width=120, height=40, label="Left", label_font=self._text_font, style=Button.SHADOWROUNDRECT) self._right_button = Button(x=190, y=195, width=120, height=40, label="Right", label_font=self._text_font, style=Button.SHADOWROUNDRECT) self._middle_button = Button(x=100, y=195, width=120, height=40, label="Middle", label_font=self._text_font, style=Button.SHADOWROUNDRECT) self._speaker_enable = DigitalInOut(board.SPEAKER_ENABLE) self._speaker_enable.switch_to_output(False) self.audio = audioio.AudioOut(board.AUDIO_OUT) self._background_file = None self._wavfile = None board.DISPLAY.auto_brightness = False self.backlight_fade(0) board.DISPLAY.show(self.root_group) 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)) self._gamedirectory = None self._gamefilename = None self._game = None self._text = None self._background_sprite = None
values.append(float(input_file.readline())) except Exception as e: print(e) # assume because file doesn't exist values = [0, 0, 0, 0, 0, 0, 0, 0] save_settings(values) print('values', values) # These pins are used as both analog and digital! XL, XR and YU must be analog # and digital capable. YD just need to be digital ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU, calibration=((5200, 59000), (5800, 57000)), z_threshhold=25000, samples=1, size=(480, 320)) # the current working directory (where this file is) cwd = ("/" + __file__).rsplit('/', 1)[0] fonts = [ file for file in os.listdir(cwd + "/fonts/") if (file.endswith(".bdf") and not file.startswith("._")) ] for i, filename in enumerate(fonts): fonts[i] = cwd + "/fonts/" + filename print(fonts) # THE_FONT = "/fonts/Arial-12.bdf"
def __init__(self, *, url=None, headers=None, json_path=None, regexp_path=None, default_bg=0x000000, status_neopixel=None, text_font=None, text_position=None, text_color=0x808080, text_wrap=False, text_maxlen=0, text_transform=None, json_transform=None, image_json_path=None, image_resize=None, image_position=None, caption_text=None, caption_font=None, caption_position=None, caption_color=0x808080, image_url_path=None, success_callback=None, esp=None, external_spi=None, debug=False): self._debug = debug try: if hasattr(board, 'TFT_BACKLIGHT'): self._backlight = pulseio.PWMOut(board.TFT_BACKLIGHT) # pylint: disable=no-member elif hasattr(board, 'TFT_LITE'): self._backlight = pulseio.PWMOut(board.TFT_LITE) # pylint: disable=no-member except ValueError: self._backlight = None self.set_backlight(1.0) # turn on backlight self._url = url self._headers = headers if json_path: if isinstance(json_path[0], (list, tuple)): self._json_path = json_path else: self._json_path = (json_path, ) else: self._json_path = None self._regexp_path = regexp_path self._success_callback = success_callback if status_neopixel: self.neopix = neopixel.NeoPixel(status_neopixel, 1, brightness=0.2) else: self.neopix = None self.neo_status(0) try: os.stat(LOCALFILE) self._uselocal = True except OSError: self._uselocal = False if self._debug: print("Init display") self.splash = displayio.Group(max_size=15) if self._debug: print("Init background") self._bg_group = displayio.Group(max_size=1) self._bg_file = None self._default_bg = default_bg self.splash.append(self._bg_group) # show thank you and bootup file if available for bootscreen in ("/thankyou.bmp", "/pyportal_startup.bmp"): try: os.stat(bootscreen) board.DISPLAY.show(self.splash) for i in range(100, -1, -1): # dim down self.set_backlight(i / 100) time.sleep(0.005) self.set_background(bootscreen) board.DISPLAY.wait_for_frame() for i in range(100): # dim up self.set_backlight(i / 100) time.sleep(0.005) time.sleep(2) except OSError: pass # they removed it, skip! self._speaker_enable = DigitalInOut(board.SPEAKER_ENABLE) self._speaker_enable.switch_to_output(False) if hasattr(board, 'AUDIO_OUT'): self.audio = audioio.AudioOut(board.AUDIO_OUT) elif hasattr(board, 'SPEAKER'): self.audio = audioio.AudioOut(board.SPEAKER) else: raise AttributeError('Board does not have a builtin speaker!') try: self.play_file("pyportal_startup.wav") except OSError: pass # they deleted the file, no biggie! if esp: # If there was a passed ESP Object if self._debug: print("Passed ESP32 to PyPortal") self._esp = esp if external_spi: #If SPI Object Passed spi = external_spi else: # Else: Make ESP32 connection spi = busio.SPI(board.SCK, board.MOSI, board.MISO) else: if self._debug: print("Init ESP32") esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_gpio0 = DigitalInOut(board.ESP_GPIO0) esp32_reset = DigitalInOut(board.ESP_RESET) esp32_cs = DigitalInOut(board.ESP_CS) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) self._esp = adafruit_esp32spi.ESP_SPIcontrol( spi, esp32_cs, esp32_ready, esp32_reset, esp32_gpio0) #self._esp._debug = 1 for _ in range(3): # retries try: print("ESP firmware:", self._esp.firmware_version) break except RuntimeError: print("Retrying ESP32 connection") time.sleep(1) self._esp.reset() else: raise RuntimeError("Was not able to find ESP32") requests.set_socket(socket, self._esp) if url and not self._uselocal: self._connect_esp() if self._debug: print("My IP address is", self._esp.pretty_ip(self._esp.ip_address)) # set the default background self.set_background(self._default_bg) board.DISPLAY.show(self.splash) if self._debug: print("Init SD Card") sd_cs = DigitalInOut(board.SD_CS) self._sdcard = None try: self._sdcard = adafruit_sdcard.SDCard(spi, sd_cs) vfs = storage.VfsFat(self._sdcard) storage.mount(vfs, "/sd") except OSError as error: print("No SD card found:", error) self._qr_group = None # Tracks whether we've hidden the background when we showed the QR code. self._qr_only = False if self._debug: print("Init caption") self._caption = None if caption_font: self._caption_font = bitmap_font.load_font(caption_font) self.set_caption(caption_text, caption_position, caption_color) if text_font: if isinstance(text_position[0], (list, tuple)): num = len(text_position) if not text_wrap: text_wrap = [0] * num if not text_maxlen: text_maxlen = [0] * num if not text_transform: text_transform = [None] * num else: num = 1 text_position = (text_position, ) text_color = (text_color, ) text_wrap = (text_wrap, ) text_maxlen = (text_maxlen, ) text_transform = (text_transform, ) self._text = [None] * num self._text_color = [None] * num self._text_position = [None] * num self._text_wrap = [None] * num self._text_maxlen = [None] * num self._text_transform = [None] * num self._text_font = bitmap_font.load_font(text_font) if self._debug: print("Loading font glyphs") # self._text_font.load_glyphs(b'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' # b'0123456789:/-_,. ') gc.collect() for i in range(num): if self._debug: print("Init text area", i) self._text[i] = None self._text_color[i] = text_color[i] self._text_position[i] = text_position[i] self._text_wrap[i] = text_wrap[i] self._text_maxlen[i] = text_maxlen[i] self._text_transform[i] = text_transform[i] else: self._text_font = None self._text = None # Add any JSON translators self._json_transform = [] if json_transform: if callable(json_transform): self._json_transform.append(json_transform) else: self._json_transform.extend(filter(callable, json_transform)) self._image_json_path = image_json_path self._image_url_path = image_url_path self._image_resize = image_resize self._image_position = image_position if image_json_path or image_url_path: if self._debug: print("Init image path") if not self._image_position: self._image_position = (0, 0) # default to top corner if not self._image_resize: self._image_resize = (320, 240) # default to full screen 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()
def __init__(self, spi, display, splash_group, debug=False): # Speaker Enable self._speaker_enable = DigitalInOut(board.SPEAKER_ENABLE) self._speaker_enable.switch_to_output(False) self._display = display if hasattr(board, "AUDIO_OUT"): self.audio = audioio.AudioOut(board.AUDIO_OUT) elif hasattr(board, "SPEAKER"): self.audio = audioio.AudioOut(board.SPEAKER) else: raise AttributeError("Board does not have a builtin speaker!") if debug: print("Init SD Card") sd_cs = board.SD_CS if not NATIVE_SD: sd_cs = DigitalInOut(sd_cs) self._sdcard = None try: self._sdcard = sdcardio.SDCard(spi, sd_cs) vfs = storage.VfsFat(self._sdcard) storage.mount(vfs, "/sd") except OSError as error: print("No SD card found:", error) try: if hasattr(board, "TFT_BACKLIGHT"): self._backlight = pulseio.PWMOut(board.TFT_BACKLIGHT) # pylint: disable=no-member elif hasattr(board, "TFT_LITE"): self._backlight = pulseio.PWMOut(board.TFT_LITE) # pylint: disable=no-member except ValueError: self._backlight = None self.set_backlight(1.0) # turn on backlight # pylint: disable=import-outside-toplevel if hasattr(board, "TOUCH_XL"): import adafruit_touchscreen if 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=(board.DISPLAY.width, board.DISPLAY.height), ) # pylint: enable=no-member self.set_backlight(1.0) # turn on backlight elif hasattr(board, "BUTTON_CLOCK"): from adafruit_cursorcontrol.cursorcontrol import Cursor from adafruit_cursorcontrol.cursorcontrol_cursormanager import CursorManager if debug: print("Init cursor") self.mouse_cursor = Cursor(board.DISPLAY, display_group=splash_group, cursor_speed=8) self.mouse_cursor.hide() self.cursor = CursorManager(self.mouse_cursor) else: raise AttributeError( "PyPortal module requires either a touchscreen or gamepad.") # pylint: enable=import-outside-toplevel gc.collect()
# ------------- Sound Effects -------------- # soundBeep = '/sounds/beep.wav' soundRoll = '/sounds/roll_dice.wav' # ------------- Display setup -------------- # pyportal = PyPortal() display = board.DISPLAY display.rotation = 0 # or - display.rotation = 270 # Touchscreen setup, rotated 0 (landscape) screen_width = 320 screen_height = 240 ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU, #samples = 10, x_resistance=300, # Reading from my Pyportal, your mileage may vary calibration=((5200, 59000), (5800, 57000)), size=(screen_width, screen_height)) # ------------- Display Groups ------------- # main = displayio.Group(max_size=15) # Main display group att_view = displayio.Group(max_size=5) # Group for attack select objects def_view = displayio.Group(max_size=5) # Group for defend select objects roll_view = displayio.Group(max_size=10) # Group for roll view objects # Load the red dice sheet (bitmap) red_dice_sheet, palette = adafruit_imageload.load("/images/dice_red.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) # Load the white dice sheet (bitmap)
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) # display groups splash = displayio.Group(max_size=15) bg_group = displayio.Group(max_size=1) splash.append(bg_group) # let there be light board.DISPLAY.show(splash) # touchscreen touchscreen = adafruit_touchscreen.Touchscreen( board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU, size=(board.DISPLAY.width, board.DISPLAY.height), ) # some globals and defaults global enabled global EVENT_DURATION EVENT_DURATION = 5 # font loading cwd = ("/"+__file__).rsplit('/', 1)[0] big_font = bitmap_font.load_font(cwd+"/fonts/Nunito-Light-75.bdf") big_font.load_glyphs(b'0123456789:') # label positions and colors
width=34, height=34, style=Button.RECT, fill_color=BUTTON1, selected_fill=BUTTON2, outline_color=WHITE, selected_outline=WHITE, icon=icon_sprite("heart-grey")) doubler.append(fav_button.group) buttons = [fav_button] touch = adafruit_touchscreen.Touchscreen( board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU, calibration=((8000, 60000), (9000, 55000)), size=(480, 320), ) channel = Channel(usb_cdc.serials[1]) core_name = "MENU" rom_name = None rom_fav = False def switch_core(new_name): global core_name, header, core_label, core_sprite, icon_lookup core_name = new_name
print("connecting to AP ...") connection = get_wifi(secrets) # set local time print("get local time from worldtimeapi.org") set_time(connection,secrets['timezone']) now = get_time() print("local time is: %s" % now) # add header header = update_header(None,adt) group.append(header) # setup touchscreen touchscreen = adafruit_touchscreen.Touchscreen( board.TOUCH_XL, board.TOUCH_XR,board.TOUCH_YD, board.TOUCH_YU, calibration=((5200, 59000),(5800, 57000)), size=(board.DISPLAY.width, board.DISPLAY.height)) # setup timers w_tmr = Timer(WTTRIN_INT) c_tmr = Timer(CLOCK_INT) b_tmr = Timer(BACKLIGHT_INT) w_tmr.start(True) c_tmr.start(True) b_tmr.start(False) while True: update = False # turn off backlight when timer expires if not b_tmr.rest(): board.DISPLAY.auto_brightness = False
def __init__(self, *, url, json_path=None, xml_path=None, default_bg=None, status_neopixel=None, text_font=None, text_position=None, text_color=0x808080, text_wrap=0, text_maxlen=0, image_json_path=None, image_resize=None, image_position=None, time_between_requests=60, success_callback=None, caption_text=None, caption_font=None, caption_position=None, caption_color=0x808080, debug=True): self._debug = debug try: self._backlight = pulseio.PWMOut(board.TFT_BACKLIGHT) except: self._backlight = None self.set_backlight(1.0) # turn on backlight self._url = url if json_path: if isinstance(json_path[0], tuple) or isinstance( json_path[0], list): self._json_path = json_path else: self._json_path = (json_path, ) else: self._json_path = None self._xml_path = xml_path self._time_between_requests = time_between_requests self._success_callback = success_callback if status_neopixel: self.neopix = neopixel.NeoPixel(status_neopixel, 1, brightness=0.2) else: self.neopix = None self.neo_status(0) try: os.stat(LOCALFILE) self._uselocal = True except OSError: self._uselocal = False # Make ESP32 connection if self._debug: print("Init ESP32") esp32_cs = DigitalInOut(microcontroller.pin.PB14) # PB14 esp32_ready = DigitalInOut(microcontroller.pin.PB16) esp32_gpio0 = DigitalInOut(microcontroller.pin.PB15) esp32_reset = DigitalInOut(microcontroller.pin.PB17) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) if not self._uselocal: self._esp = adafruit_esp32spi.ESP_SPIcontrol( spi, esp32_cs, esp32_ready, esp32_reset, esp32_gpio0) #self._esp._debug = 1 for _ in range(3): # retries try: print("ESP firmware:", self._esp.firmware_version) break except RuntimeError: print("Retrying ESP32 connection") time.sleep(1) self._esp.reset() else: raise RuntimeError("Was not able to find ESP32") requests.set_interface(self._esp) if self._debug: print("Init display") self.splash = displayio.Group(max_size=5) board.DISPLAY.show(self.splash) if self._debug: print("Init background") self._bg_group = displayio.Group(max_size=1) self._bg_file = None self.set_background(default_bg) self.splash.append(self._bg_group) self._qr_group = None if self._debug: print("Init caption") self._caption = None if caption_font: self._caption_font = bitmap_font.load_font(caption_font) self.set_caption(caption_text, caption_position, caption_color) if text_font: if isinstance(text_position[0], tuple) or isinstance( text_position[0], list): num = len(text_position) if not text_wrap: text_wrap = [0] * num if not text_maxlen: text_maxlen = [0] * num else: num = 1 text_position = (text_position, ) text_color = (text_color, ) text_wrap = (text_wrap, ) text_maxlen = (text_maxlen, ) self._text = [None] * num self._text_color = [None] * num self._text_position = [None] * num self._text_wrap = [None] * num self._text_maxlen = [None] * num self._text_font = bitmap_font.load_font(text_font) if self._debug: print("Loading font glyphs") #self._text_font.load_glyphs(b'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789:/-_,. ') gc.collect() for i in range(num): if self._debug: print("Init text area", i) self._text[i] = None self._text_color[i] = text_color[i] self._text_position[i] = text_position[i] self._text_wrap[i] = text_wrap[i] self._text_maxlen[i] = text_maxlen[i] else: self._text_font = None self._text = None self._image_json_path = image_json_path self._image_resize = image_resize self._image_position = image_position if image_json_path: if self._debug: print("Init image path") if not self._image_position: 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") self.ts = adafruit_touchscreen.Touchscreen(microcontroller.pin.PB01, microcontroller.pin.PB08, microcontroller.pin.PA06, microcontroller.pin.PB00, calibration=((5200, 59000), (5800, 57000)), size=(320, 240)) self.set_backlight(1.0) # turn on backlight gc.collect()
debug=DEBUG_MODE, ) pyportal.set_background("/images/fractal_loading.bmp") log("Pyportal initialized") # Display setup display = board.DISPLAY display.rotation = 0 display.auto_brightness = True log("Display initialized") # Touchscreen setup touch_screen = adafruit_touchscreen.Touchscreen( board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU, calibration=((6272, 60207), (7692, 56691)), size=(SCREEN_WIDTH, SCREEN_HEIGHT), ) log("Touchscreen initialized") # Keyboard setup try: # Initialize with the available USB devices. The constructur picks the # correct one from the list keyboard = Keyboard(usb_hid.devices) keyboard_active = True log("Keyboard activated") except OSError: keyboard_active = False log("No keyboard found")
display.auto_brightness = False display.brightness = val # print(dir(board)) display.rotation = 0 set_backlight(1.0) # Touchscreen setup # ------Rotate 270: screen_width = 240 screen_height = 320 ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU, calibration=((5200, 59000), (5800, 57000)), size=(screen_width, screen_height)) try: temperature_feed = io.get_feed('villaastrid.tupa-bme680-temp') except AdafruitIO_RequestError: print("temperature_feed, failed") try: ldr_feed = io.get_feed('home-tampere.esp32test-ldr') except AdafruitIO_RequestError: print("ldr_feed, failed") try:
"name": "iPod", "status": "unknown" }, "28:c2:dd:a2:5a:d1": { "name": "Chromebook", "status": "unknown" }, "44:65:0d:b8:8f:95": { "name": "Kindle", "status": "unknown" } }, } # initialize the Touchscreen ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU) # initailize the pytportal object pyportal = PyPortal(default_bg="./kids.bmp") pyportal.set_backlight(.5) # location of the ON / OFF "buttons" zOn = (44, 212) zOff = (34, 212) aOn = (190, 212) aOff = (180, 212) onColor = 0x5ff442 offColor = 0xd60000 big_font = bitmap_font.load_font("./fonts/Helvetica-Bold-36.bdf")
def __init__(self, *, url=None, json_path=None, regexp_path=None, default_bg=0x000000, status_neopixel=None, text_font=None, text_position=None, text_color=0x808080, text_wrap=False, text_maxlen=0, text_transform=None, image_json_path=None, image_resize=None, image_position=None, caption_text=None, caption_font=None, caption_position=None, caption_color=0x808080, success_callback=None, debug=False): self._debug = debug try: self._backlight = pulseio.PWMOut(board.TFT_BACKLIGHT) # pylint: disable=no-member except ValueError: self._backlight = None self.set_backlight(1.0) # turn on backlight self._url = url if json_path: if isinstance(json_path[0], (list, tuple)): self._json_path = json_path else: self._json_path = (json_path, ) else: self._json_path = None self._regexp_path = regexp_path self._success_callback = success_callback if status_neopixel: self.neopix = neopixel.NeoPixel(status_neopixel, 1, brightness=0.2) else: self.neopix = None self.neo_status(0) try: os.stat(LOCALFILE) self._uselocal = True except OSError: self._uselocal = False if self._debug: print("Init display") self.splash = displayio.Group(max_size=15) if self._debug: print("Init background") self._bg_group = displayio.Group(max_size=1) self._bg_file = None self._default_bg = default_bg self.splash.append(self._bg_group) # show thank you and bootup file if available for bootscreen in ("/thankyou.bmp", "/pyportal_startup.bmp"): try: os.stat(bootscreen) board.DISPLAY.show(self.splash) for i in range(100, -1, -1): # dim down self.set_backlight(i / 100) time.sleep(0.005) self.set_background(bootscreen) board.DISPLAY.wait_for_frame() for i in range(100): # dim up self.set_backlight(i / 100) time.sleep(0.005) time.sleep(2) except OSError: pass # they removed it, skip! self._speaker_enable = DigitalInOut(board.SPEAKER_ENABLE) self._speaker_enable.switch_to_output(False) self.audio = audioio.AudioOut(board.AUDIO_OUT) try: self.play_file("pyportal_startup.wav") except OSError: pass # they deleted the file, no biggie! # Make ESP32 connection if self._debug: print("Init ESP32") esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_gpio0 = DigitalInOut(board.ESP_GPIO0) esp32_reset = DigitalInOut(board.ESP_RESET) esp32_cs = DigitalInOut(board.ESP_CS) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) self._esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset, esp32_gpio0) #self._esp._debug = 1 for _ in range(3): # retries try: print("ESP firmware:", self._esp.firmware_version) break except RuntimeError: print("Retrying ESP32 connection") time.sleep(1) self._esp.reset() else: raise RuntimeError("Was not able to find ESP32") requests.set_interface(self._esp) if url and not self._uselocal: self._connect_esp() # set the default background self.set_background(self._default_bg) board.DISPLAY.show(self.splash) if self._debug: print("Init SD Card") sd_cs = DigitalInOut(board.SD_CS) self._sdcard = None try: self._sdcard = adafruit_sdcard.SDCard(spi, sd_cs) vfs = storage.VfsFat(self._sdcard) storage.mount(vfs, "/sd") except OSError as error: print("No SD card found:", error) self._qr_group = None if self._debug: print("Init caption") self._caption = None if caption_font: self._caption_font = bitmap_font.load_font(caption_font) self.set_caption(caption_text, caption_position, caption_color) if text_font: if isinstance(text_position[0], (list, tuple)): num = len(text_position) if not text_wrap: text_wrap = [0] * num if not text_maxlen: text_maxlen = [0] * num if not text_transform: text_transform = [None] * num else: num = 1 text_position = (text_position, ) text_color = (text_color, ) text_wrap = (text_wrap, ) text_maxlen = (text_maxlen, ) text_transform = (text_transform, ) self._text = [None] * num self._text_color = [None] * num self._text_position = [None] * num self._text_wrap = [None] * num self._text_maxlen = [None] * num self._text_transform = [None] * num self._text_font = bitmap_font.load_font(text_font) if self._debug: print("Loading font glyphs") # self._text_font.load_glyphs(b'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' # b'0123456789:/-_,. ') gc.collect() for i in range(num): if self._debug: print("Init text area", i) self._text[i] = None self._text_color[i] = text_color[i] self._text_position[i] = text_position[i] self._text_wrap[i] = text_wrap[i] self._text_maxlen[i] = text_maxlen[i] self._text_transform[i] = text_transform[i] else: self._text_font = None self._text = None self._image_json_path = image_json_path self._image_resize = image_resize self._image_position = image_position if image_json_path: if self._debug: print("Init image path") if not self._image_position: 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 gc.collect()
import displayio import pulseio import audioio import time import adafruit_touchscreen cwd = __file__.rsplit('/', 1)[0] IMAGE_FILE = cwd + "/lcars_background.bmp" # These pins are used as both analog and digital! XR and YU must be analog # and digital capable. XL and YD just need to be digital ts = adafruit_touchscreen.Touchscreen(microcontroller.pin.PB01, microcontroller.pin.PB08, microcontroller.pin.PA06, microcontroller.pin.PB00, calibration=((5200, 59000), (5800, 57000)), size=(320, 240)) try: backlight = pulseio.PWMOut(board.TFT_BACKLIGHT) backlight.duty_cycle = 65535 except: board.DISPLAY.auto_brightness = False board.DISPLAY.brightness = 1.0 # define the bounding boxes for each button red_button = ((25, 30), (65, 80)) yellow_button = ((25, 100), (65, 150)) blue_button = ((25, 170), (65, 230))
# Backlight function def set_backlight(val): """Adjust the TFT backlight. :param val: The backlight brightness. Use a value between ``0`` and ``1``, where ``0`` is off, and ``1`` is 100% brightness. """ val = max(0, min(1.0, val)) board.DISPLAY.auto_brightness = False board.DISPLAY.brightness = val # Touchscreen setup ts = adafruit_touchscreen.Touchscreen( board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU, calibration=((5200, 59000), (5800, 57000)), size=(320, 240), ) # ---------- Set the font and preload letters ---------- # Be sure to put your font into a folder named "fonts". font = bitmap_font.load_font("/fonts/Helvetica-Bold-16.bdf") # This will preload the text images. font.load_glyphs( b"abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890- ()") # ------------- User Inretface Eliments ------------- # # Make the display context splash = displayio.Group()
# The buttons on the TFT display will send keycodes just like a standard keyboard keyboard = Keyboard() keyboard_layout = KeyboardLayoutUS(keyboard) # Some GarageBand/Song specific definitions max_tracks = 12 # Setup touchscreen # ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, # board.TOUCH_YD, board.TOUCH_YU, # calibration=((5200, 59000), (5800, 57000)), # size=(320, 240), z_threshhold=5000) ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU, size=(320, 240)) # Load the font to be used on the buttons font = bitmap_font.load_font("/fonts/Dina.bdf") # As it turns out, the code above can all be replaced with the following: pyportal = PyPortal(default_bg=0x000000) button_margin = (1,1) button_height = 80 button_width = 80 btn_0_0 = PaddedButton(x=0, y=0, width=button_width, height=button_height, label="T-1-1", label_font=font, label_color=0xffffFF, fill_color=0x094A85, outline_color=0x094A85,
import time import board import displayio import adafruit_touchscreen from adafruit_bitmap_font import bitmap_font from adafruit_displayio_layout.widgets.flip_input import FlipInput display = board.DISPLAY # create the display on the PyPortal, # otherwise change this to setup the display # for display chip driver and pinout you have (e.g. ILI9341) # setup the touchscreen ts = adafruit_touchscreen.Touchscreen( board.TOUCH_XL, board.TOUCH_XR, board.TOUCH_YD, board.TOUCH_YU, calibration=((5200, 59000), (5800, 57000)), size=(display.width, display.height), ) # Select the font file for use font_file = "fonts/DSEG14Classic-Regular-64-ModS.pcf" my_font = bitmap_font.load_font(font_file) my_flip1 = FlipInput( display, anchor_point=[0.0, 0.0], anchored_position=[50, 40], color=0xFF2222, # reddish orange color value_list=[ # list of month strings, using three characters "JAN",
top_L.direction = digitalio.Direction.OUTPUT top_R.direction = digitalio.Direction.OUTPUT bottom_L.direction = digitalio.Direction.OUTPUT bottom_R.direction = digitalio.Direction.OUTPUT yelloww.direction = digitalio.Direction.OUTPUT switch.direction = digitalio.Direction.INPUT mode_sw.direction = digitalio.Direction.INPUT left_click.direction = digitalio.Direction.INPUT mode_sw.switch_to_input(pull=digitalio.Pull.DOWN) left_click.switch_to_input(pull=digitalio.Pull.DOWN) switch.switch_to_input(pull=digitalio.Pull.DOWN) ts = adafruit_touchscreen.Touchscreen(board.A3, board.A1, board.A2, board.A0) def startup(): # Initial Start up sequence so that you know all is going well # Turn on all LEDS top_L.value = True top_R.value = True bottom_L.value = True bottom_R.value = True yelloww.value = True # Wait a second time.sleep(1)