Skip to content

Commit 6488161

Browse files
committed
Adding class parameters documentation
1 parent 136d15c commit 6488161

File tree

4 files changed

+77
-39
lines changed

4 files changed

+77
-39
lines changed

README.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,21 @@ To install in a virtual environment in your current project:
5353
Usage Example
5454
=============
5555

56-
.. code-block:: python
56+
.. code-block:: python3
5757
58-
import board
59-
import adafruit_touchscreen
58+
import board
59+
import adafruit_touchscreen
6060
61-
# These pins are used as both analog and digital!
62-
# XR, XL and YU must be analog and digital capable.
63-
# YD just needs to be digital.
64-
ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR,
65-
board.TOUCH_YD, board.TOUCH_YU)
61+
# These pins are used as both analog and digital!
62+
# XR, XL and YU must be analog and digital capable.
63+
# YD just needs to be digital.
64+
ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR,
65+
board.TOUCH_YD, board.TOUCH_YU)
6666
67-
while True:
68-
p = ts.touch_point
69-
if p:
70-
print(p)
67+
while True:
68+
p = ts.touch_point
69+
if p:
70+
print(p)
7171
7272
7373
Contributing

adafruit_touchscreen.py

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
Implementation Notes
1515
--------------------
1616
17-
**Hardware:**
18-
19-
2017
**Software and Dependencies:**
2118
2219
* Adafruit CircuitPython firmware for the supported boards:
23-
https://github.com/adafruit/circuitpython/releases
20+
https://circuitpython.org/downloads
21+
2422
"""
2523

2624
__version__ = "0.0.0-auto.0"
@@ -31,11 +29,18 @@
3129

3230

3331
def map_range(x, in_min, in_max, out_min, out_max):
32+
3433
"""
3534
Maps a number from one range to another.
36-
Note: This implementation handles values < in_min differently than arduino's map function does.
35+
36+
.. note:: This implementation handles values < in_min differently
37+
than arduino's map function does.
38+
39+
3740
:return: Returns value mapped to new range
3841
:rtype: float
42+
43+
3944
"""
4045
mapped = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
4146
if out_min <= out_max:
@@ -45,7 +50,42 @@ def map_range(x, in_min, in_max, out_min, out_max):
4550

4651
class Touchscreen:
4752
"""A driver for common and inexpensive resistive touchscreens. Analog input
48-
capable pins are required to read the intrinsic potentiometers"""
53+
capable pins are required to read the intrinsic potentiometers
54+
55+
Create the Touchscreen object. At a minimum you need the 4 pins
56+
that will connect to the 4 contacts on a screen. X and Y are just our
57+
names, you can rotate and flip the data if you like. All pins must be
58+
capable of becoming DigitalInOut pins. :attr:`y2_pin`, :attr:`x1_pin`
59+
and :attr:`x2_pin` must also be capable of becoming AnalogIn pins.
60+
If you know the resistance across the x1 and x2 pins when not touched,
61+
pass that in as 'x_resistance'.
62+
:attr:`calibration` is a tuple of two tuples, the default is
63+
((0, 65535), (0, 65535)). The numbers are the min/max readings for the
64+
X and Y coordinate planes, respectively. To figure these out, pass in
65+
no calibration value and read the raw values out while touching the
66+
panel.
67+
:attr:`size` is a tuple that gives the X and Y pixel size of the underlying
68+
screen. If passed in, we will automatically scale/rotate so touches
69+
correspond to the graphical coordinate system.
70+
71+
:param ~microcontroller.Pin x1_pin: Data pin for Left side of the screen.
72+
Must also be capable of becoming AnalogIn pins.
73+
:param ~microcontroller.Pin x2_pin: Data pin for Right side of the screen.
74+
Must also be capable of becoming AnalogIn pins.
75+
:param ~microcontroller.Pin y1_pin: Data pin for Bottom side of the screen.
76+
:param ~microcontroller.Pin y2_pin: Data pin for Top side of the screen.
77+
Must also be capable of becoming AnalogIn pins.
78+
:param int x_resistance: If you know the resistance across the x1 and x2
79+
pins when not touched, pass that in as :attr:`x_resistance`
80+
:param int samples: change by adjusting :attr:`samples` arg. Defaults to :const:`4`
81+
:param int z_threshold: We can also detect the 'z' threshold, how much
82+
its pressed. We don't register a touch unless its higher than :attr:`z_threshold`
83+
:param (int,int),(int,int) calibration: A tuple of two tuples The numbers are the min/max
84+
readings for the X and Y coordinate planes, respectively.
85+
Defaults to :const:`((0, 65535), (0, 65535))`
86+
:param int,int size: The dimensions of the screen as (x, y).
87+
88+
"""
4989

5090
def __init__(
5191
self,
@@ -56,29 +96,11 @@ def __init__(
5696
*,
5797
x_resistance=None,
5898
samples=4,
59-
z_threshhold=10000,
99+
z_threshold=10000,
60100
calibration=None,
61101
size=None
62102
):
63-
"""Create the Touchscreen object. At a minimum you need the 4 pins
64-
that will connect to the 4 contacts on a screen. X and Y are just our
65-
names, you can rotate and flip the data if you like. All pins must be
66-
capable of becoming DigitalInOut pins. 'y2_pin', 'x1_pin' and 'x2_pin'
67-
must also be capable of becoming AnalogIn pins.
68-
If you know the resistance across the x1 and x2 pins when not touched,
69-
pass that in as 'x_resistance'.
70-
By default we oversample 4 times, change by adjusting 'samples' arg.
71-
We can also detect the 'z' threshold, how much its prssed. We don't
72-
register a touch unless its higher than 'z_threshold'
73-
'calibration' is a tuple of two tuples, the default is
74-
((0, 65535), (0, 65535)). The numbers are the min/max readings for the
75-
X and Y coordinate planes, respectively. To figure these out, pass in
76-
no calibration value and read the raw values out while touching the
77-
panel.
78-
'size' is a tuple that gives the X and Y pixel size of the underlying
79-
screen. If passed in, we will automatically scale/rotate so touches
80-
correspond to the graphical coordinate system.
81-
"""
103+
82104
self._xm_pin = x1_pin
83105
self._xp_pin = x2_pin
84106
self._ym_pin = y1_pin
@@ -90,7 +112,7 @@ def __init__(
90112
calibration = ((0, 65535), (0, 65535))
91113
self._calib = calibration
92114
self._size = size
93-
self._zthresh = z_threshhold
115+
self._zthresh = z_threshold
94116

95117
@property
96118
def touch_point(self): # pylint: disable=too-many-locals

docs/examples.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,13 @@ Ensure your device works with this simple test.
66
.. literalinclude:: ../examples/touchscreen_simpletest.py
77
:caption: examples/touchscreen_simpletest.py
88
:linenos:
9+
10+
11+
Orientation Example
12+
--------------------
13+
14+
Example showing how to setup the different display orientations
15+
16+
.. literalinclude:: ../examples/touchscreen_orientation.py
17+
:caption: examples/touchscreen_orientation.py
18+
:linenos:

docs/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ Table of Contents
2727
.. toctree::
2828
:caption: Related Products
2929

30+
Adafruit PyPortal - CircuitPython Powered Internet Display <https://www.adafruit.com/product/4116>
31+
32+
Adafruit PyPortal Titano <https://www.adafruit.com/product/4444>
33+
34+
Adafruit PyPortal Pynt - CircuitPython Powered Internet Display - 2.4" TFT <https://www.adafruit.com/product/4465>
35+
3036

3137
.. toctree::
3238
:caption: Other Links

0 commit comments

Comments
 (0)