Skip to content

Commit 0036d9c

Browse files
committed
Add option for IRQ pin to wait for _read
1 parent af6f9c1 commit 0036d9c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

adafruit_focaltouch.py

100644100755
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ class Adafruit_FocalTouch:
6767
_debug = False
6868
chip = None
6969

70-
def __init__(self, i2c, address=_FT6206_DEFAULT_I2C_ADDR, debug=False):
70+
def __init__(self, i2c, address=_FT6206_DEFAULT_I2C_ADDR, debug=False, irq_pin=None):
7171
self._i2c = I2CDevice(i2c, address)
7272
self._debug = debug
73+
self.irq_pin = irq_pin
7374

74-
chip_data = self._read(_FT6XXX_REG_LIBH, 8)
75+
chip_data = self._read(_FT6XXX_REG_LIBH, 8) # don't wait for IRQ
7576
lib_ver, chip_id, _, _, firm_id, _, vend_id = struct.unpack(
7677
">HBBBBBB", chip_data
7778
)
@@ -90,10 +91,11 @@ def __init__(self, i2c, address=_FT6206_DEFAULT_I2C_ADDR, debug=False):
9091
print("Point rate %d Hz" % self._read(_FT6XXX_REG_POINTRATE, 1)[0])
9192
print("Thresh %d" % self._read(_FT6XXX_REG_THRESHHOLD, 1)[0])
9293

94+
9395
@property
9496
def touched(self):
9597
""" Returns the number of touches currently detected """
96-
return self._read(_FT6XXX_REG_NUMTOUCHES, 1)[0]
98+
return self._read(_FT6XXX_REG_NUMTOUCHES, 1, irq_pin=self.irq_pin)[0]
9799

98100
# pylint: disable=unused-variable
99101
@property
@@ -103,7 +105,7 @@ def touches(self):
103105
touch coordinates, and 'id' as the touch # for multitouch tracking
104106
"""
105107
touchpoints = []
106-
data = self._read(_FT6XXX_REG_DATA, 32)
108+
data = self._read(_FT6XXX_REG_DATA, 32, irq_pin=self.irq_pin)
107109

108110
for i in range(2):
109111
point_data = data[i * 6 + 3 : i * 6 + 9]
@@ -121,11 +123,17 @@ def touches(self):
121123

122124
# pylint: enable=unused-variable
123125

124-
def _read(self, register, length):
126+
def _read(self, register, length, irq_pin=None):
125127
"""Returns an array of 'length' bytes from the 'register'"""
126128
with self._i2c as i2c:
129+
130+
if (irq_pin is not None):
131+
while (self.irq_pin.value):
132+
pass
133+
127134
i2c.write(bytes([register & 0xFF]))
128135
result = bytearray(length)
136+
129137
i2c.readinto(result)
130138
if self._debug:
131139
print("\t$%02X => %s" % (register, [hex(i) for i in result]))

0 commit comments

Comments
 (0)