Skip to content

Add Missing Type Annotations #21

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

Merged
merged 3 commits into from
Sep 2, 2022
Merged
Changes from all commits
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
32 changes: 20 additions & 12 deletions adafruit_touchscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@
from digitalio import DigitalInOut
from analogio import AnalogIn

try:
from typing import Optional, Tuple
from microcontroller import Pin
except ImportError:
pass

def map_range(x, in_min, in_max, out_min, out_max):

def map_range(x: float, in_min: int, in_max: int, out_min: int, out_max: int) -> float:

"""
Maps a number from one range to another.
Expand Down Expand Up @@ -89,17 +95,17 @@ class Touchscreen:

def __init__(
self,
x1_pin,
x2_pin,
y1_pin,
y2_pin,
x1_pin: Pin,
x2_pin: Pin,
y1_pin: Pin,
y2_pin: Pin,
*,
x_resistance=None,
samples=4,
z_threshold=10000,
calibration=None,
size=None
):
x_resistance: Optional[int] = None,
samples: int = 4,
z_threshold: int = 10000,
calibration: Optional[Tuple[Tuple[int, int], Tuple[int, int]]] = None,
size: Optional[Tuple[int, int]] = None
) -> None:

self._xm_pin = x1_pin
self._xp_pin = x2_pin
Expand All @@ -115,7 +121,9 @@ def __init__(
self._zthresh = z_threshold

@property
def touch_point(self): # pylint: disable=too-many-locals
def touch_point(
self,
) -> Optional[Tuple[int, int, int]]: # pylint: disable=too-many-locals
"""A tuple that represents the x, y and z (touch pressure) coordinates
of a touch. Or, None if no touch is detected"""
z_1 = z_2 = z = None
Expand Down