Skip to content

Commit 1f87c8f

Browse files
committed
lint
1 parent 8168409 commit 1f87c8f

File tree

3 files changed

+47
-20
lines changed

3 files changed

+47
-20
lines changed

adafruit_ft5336.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from adafruit_register.i2c_bits import ROBits
3030
from adafruit_bus_device.i2c_device import I2CDevice
3131
from micropython import const
32+
3233
try:
3334
from typing import List, Tuple
3435
except ImportError:
@@ -49,14 +50,20 @@
4950
_TOUCH1_YH = const(0x05)
5051
_TOUCH1_YL = const(0x06)
5152

53+
5254
class Adafruit_FT5336:
5355
"""Adafruit FT5336 touch screen driver"""
56+
5457
# Define read-only register bits for vendor ID, chip ID, and number of touches.
5558
_vend_id = ROBits(8, _REG_VENDID, 0) # 8-bit read-only register for vendor ID
5659
_chip_id = ROBits(8, _REG_CHIPID, 0) # 8-bit read-only register for chip ID
57-
_num_touches = ROBits(8, _REG_NUMTOUCHES, 0) # 8-bit read-only register for number of touches
60+
_num_touches = ROBits(
61+
8, _REG_NUMTOUCHES, 0
62+
) # 8-bit read-only register for number of touches
5863

59-
def __init__(self, i2c, i2c_addr: int = _DEFAULT_ADDR, max_touches: int = 5) -> None:
64+
def __init__(
65+
self, i2c, i2c_addr: int = _DEFAULT_ADDR, max_touches: int = 5
66+
) -> None:
6067
"""Initialization over I2C
6168
6269
:param int i2c_addr: I2C address (default 0x38)
@@ -68,9 +75,9 @@ def __init__(self, i2c, i2c_addr: int = _DEFAULT_ADDR, max_touches: int = 5) ->
6875
self.max_touches = max_touches # Maximum number of touches to track
6976

7077
# Initialize touch point arrays
71-
self._touchX: List[int] = [0] * self.max_touches
72-
self._touchY: List[int] = [0] * self.max_touches
73-
self._touchID: List[int] = [0] * self.max_touches
78+
self._touch_x: List[int] = [0] * self.max_touches
79+
self._touch_y: List[int] = [0] * self.max_touches
80+
self._touch_id: List[int] = [0] * self.max_touches
7481

7582
# Verify device identity by checking the vendor and chip IDs
7683
if self._vend_id != _VENDID:
@@ -88,44 +95,49 @@ def _read_data(self):
8895
self._touches = 0
8996

9097
for i in range(self._touches):
91-
self._touchX[i] = (buffer[_TOUCH1_XH + i * 6] & 0x0F) << 8 | buffer[_TOUCH1_XL + i * 6]
92-
self._touchY[i] = (buffer[_TOUCH1_YH + i * 6] & 0x0F) << 8 | buffer[_TOUCH1_YL + i * 6]
93-
self._touchID[i] = buffer[_TOUCH1_YH + i * 6] >> 4
98+
self._touch_x[i] = (buffer[_TOUCH1_XH + i * 6] & 0x0F) << 8 | buffer[
99+
_TOUCH1_XL + i * 6
100+
]
101+
self._touch_y[i] = (buffer[_TOUCH1_YH + i * 6] & 0x0F) << 8 | buffer[
102+
_TOUCH1_YL + i * 6
103+
]
104+
self._touch_id[i] = buffer[_TOUCH1_YH + i * 6] >> 4
94105

95106
@property
96107
def touched(self) -> int:
97108
"""Count of touch inputs detected
98-
109+
99110
:return: Count of touch inputs detected (0-max_touches)
100111
:rtype: int
101112
"""
102113
n = self._num_touches
103114
return 0 if n > self.max_touches else n
104-
115+
105116
@property
106117
def points(self) -> List:
107118
"""X, Y and Z values from each available touch input
108-
119+
109120
:return: X, Y and Z values in a list
110121
:rtype: List
111122
"""
112123
self._read_data()
113124
points = []
114125
for i in range(min(self._touches, self.max_touches)):
115-
point = (self._touchX[i], self._touchY[i], 1)
126+
point = (self._touch_x[i], self._touch_y[i], 1)
116127
points.append(point)
117128

118129
return points
119130

120131
def point(self, point_index: int) -> Tuple:
121132
"""X, Y and Z value from a specified touch input
122-
133+
123134
:param int point_index: Touch input to read (0 - max_touches)
124135
:return: X, Y and Z values
125136
:rtype: Tuple
126137
"""
127138
self._read_data()
128139
if self._touches == 0 or point_index >= self._touches:
129-
return (0, 0, 0)
140+
value = (0, 0, 0)
130141
else:
131-
return (self._touchX[point_index], self._touchY[point_index], 1)
142+
value = (self._touch_x[point_index], self._touch_y[point_index], 1)
143+
return value

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434

3535

3636
intersphinx_mapping = {
37-
"python": ("https://docs.python.org/3", None),"BusDevice": ("https://docs.circuitpython.org/projects/busdevice/en/latest/", None),
37+
"python": ("https://docs.python.org/3", None),
38+
"BusDevice": ("https://docs.circuitpython.org/projects/busdevice/en/latest/", None),
3839
"Register": ("https://docs.circuitpython.org/projects/register/en/latest/", None),
3940
"CircuitPython": ("https://docs.circuitpython.org/en/latest/", None),
4041
}

examples/ft5336_simpletest.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2-
# SPDX-FileCopyrightText: Copyright (c) 2023 Liz Clark for Adafruit Industries
3-
#
4-
# SPDX-License-Identifier: Unlicense
1+
# SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
Demo for the FT5336. Reads all available touch input coordinates.
6+
"""
7+
8+
import time
9+
import board
10+
import adafruit_ft5336
11+
12+
i2c = board.I2C()
13+
touch = adafruit_ft5336.Adafruit_FT5336(i2c)
14+
15+
while True:
16+
t = touch.points
17+
print(t)
18+
time.sleep(0.1)

0 commit comments

Comments
 (0)