def __init__(self,
                 spi,
                 display,
                 touchscreen=None,
                 audio_device=1,
                 debug=False):
        self._display = display

        self._audio_device = audio_device
        self.touchscreen = touchscreen
        self._debug = debug
        if spi is not None:
            # Attempt to Init STMPE610
            if self.touchscreen is None:
                if debug:
                    print("Attempting to initialize STMPE610...")
                try:
                    chip_select = DigitalInOut(board.CE1)
                    self.touchscreen = Adafruit_STMPE610_SPI(spi, chip_select)
                except (RuntimeError, AttributeError, NameError):
                    if debug:
                        print("None Found")
            # Attempt to Init FocalTouch
            if self.touchscreen is None:
                if debug:
                    print("Attempting to initialize Focal Touch...")
                try:
                    i2c = board.I2C()
                    self.touchscreen = adafruit_focaltouch.Adafruit_FocalTouch(
                        i2c)
                except Exception:  # pylint: disable=broad-except
                    if debug:
                        print("None Found")

        self.set_backlight(1.0)  # turn on backlight

        gc.collect()
"""
Example for getting touch data from an FT6206 or FT6236 capacitive
touch driver, over I2C
"""

import time
import busio
import board
import adafruit_focaltouch

# Create library object (named "ft") using a Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)

ft = adafruit_focaltouch.Adafruit_FocalTouch(i2c, debug=False)

while True:
    # if the screen is being touched print the touches
    if ft.touched:
        print(ft.touches)
    else:
        print('no touch')

    time.sleep(.15)
Ejemplo n.º 3
0
"""
Example for getting touch data from an FT6206 or FT6236 capacitive
touch driver, over I2C
"""

import busio
import board
import adafruit_focaltouch

# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)

ft = adafruit_focaltouch.Adafruit_FocalTouch(i2c, debug=True)

while True:
    n = ft.touched
    if n:
        print(ft.touches)
    board, "SCL"
):  # if SCL and SDA pins are defined by the board definition, use them.
    SCL_pin = board.SCL
    SDA_pin = board.SDA
else:
    SCL_pin = board.IO42  # set to a pin that you want to use for SCL
    SDA_pin = board.IO41  # set to a pin that you want to use for SDA

IRQ_pin = board.IO39  # select a pin to connect to the display's interrupt pin ("IRQ")

i2c = busio.I2C(SCL_pin, SDA_pin)

# Setup the interrupt (IRQ) pin for input
irq = DigitalInOut(board.IO39)
irq.direction = Direction.INPUT

# Create library object (named "ft") using a Bus I2C port and using an interrupt pin (IRQ)
ft = adafruit_focaltouch.Adafruit_FocalTouch(i2c, debug=False, irq_pin=irq)


print("\n\nReady for touches...")

while True:
    # if the screen is being touched print the touches
    if ft.touched:
        print(ft.touches)
    else:
        print("no touch")

    time.sleep(0.05)
import busio
import board
import digitalio
import adafruit_focaltouch
from adafruit_rgb_display import ili9341, color565

# Create library object using our Bus I2C & SPI port
i2c = busio.I2C(board.SCL, board.SDA)
spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Adafruit Metro M0 + 2.8" Capacitive touch shield
cs_pin = digitalio.DigitalInOut(board.D10)
dc_pin = digitalio.DigitalInOut(board.D9)

# Initialize display
display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin)
# Fill with black!
display.fill(color565(0, 0, 0))

ft = adafruit_focaltouch.Adafruit_FocalTouch(i2c)

while True:
    if ft.touched:
        ts = ft.touches
        point = ts[0]  # the shield only supports one point!
        # perform transformation to get into display coordinate system!
        y = 320 - point["y"]
        x = 240 - point["x"]
        display.fill_rectangle(x - 2, y - 2, 4, 4, color565(255, 255, 255))
    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,
        image_dim_json_path=None,
        caption_text=None,
        caption_font=None,
        caption_position=None,
        caption_color=0x808080,
        image_url_path=None,
        success_callback=None,
        external_spi=None,
        debug=False,
        display=None,
        touchscreen=None
    ):

        self._debug = debug
        self._debug_start = time.monotonic()
        self.display = display

        spi = None

        if self.display is None:
            if external_spi:  # If SPI Object Passed
                spi = external_spi
            else:  # Else: Make ESP32 connection
                spi = board.SPI()

            display_bus = displayio.FourWire(
                spi, command=board.D25, chip_select=board.CE0
            )
            self.display = adafruit_ili9341.ILI9341(
                display_bus, width=320, height=240, backlight_pin=board.D18
            )

        if self.display is None:
            raise RuntimeError("Display not found or provided")
        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:
            import neopixel  # pylint: disable=import-outside-toplevel

            self.neopix = neopixel.NeoPixel(status_neopixel, 1, brightness=0.2)
        else:
            self.neopix = None
        self.neo_status(0)

        self.audio_device = 1

        try:
            os.stat(LOCALFILE)
            self._uselocal = True
        except OSError:
            self._uselocal = False

        self._debug_print("Init display")
        self.splash = displayio.Group(max_size=15)

        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)
                self.display.show(self.splash)
                self.set_backlight(0)
                self.set_background(bootscreen)
                self.set_backlight(1)
            except OSError:
                pass  # they removed it, skip!
        try:
            self.play_file("pyportal_startup.wav")
        except OSError:
            pass  # they deleted the file, no biggie!

        self._debug_print("My IP address is", self.get_ip_address())

        # set the default background
        self.set_background(self._default_bg)
        self.display.show(self.splash)

        self._qr_group = None
        # Tracks whether we've hidden the background when we showed the QR code.
        self._qr_only = False

        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)
            self._debug_print("Loading font glyphs")
            # self._text_font.load_glyphs(b'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
            #                             b'0123456789:/-_,. ')
            gc.collect()

            for i in range(num):
                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
        self._image_dim_json_path = image_dim_json_path
        if image_json_path or image_url_path:
            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 = (
                    self.display.width,
                    self.display.height,
                )  # default to full screen

        self._debug_print("Init touchscreen")
        self.touchscreen = touchscreen
        if spi is not None:
            # Attempt to Init STMPE610
            if self.touchscreen is None:
                self._debug_print("Attempting to initialize STMPE610...")
                try:
                    chip_select = digitalio.DigitalInOut(board.CE1)
                    self.touchscreen = Adafruit_STMPE610_SPI(spi, chip_select)
                except (RuntimeError, AttributeError):
                    self._debug_print("None Found")
            # Attempt to Init FocalTouch
            if self.touchscreen is None:
                self._debug_print("Attempting to initialize Focal Touch...")
                try:
                    i2c = board.I2C()
                    self.touchscreen = adafruit_focaltouch.Adafruit_FocalTouch(i2c)
                except Exception:  # pylint: disable=broad-except
                    self._debug_print("None Found")

        self.set_backlight(1.0)  # turn on backlight

        gc.collect()