@@ -67,11 +67,12 @@ class Adafruit_FocalTouch:
67
67
_debug = False
68
68
chip = None
69
69
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 ):
71
71
self ._i2c = I2CDevice (i2c , address )
72
72
self ._debug = debug
73
+ self .irq_pin = irq_pin
73
74
74
- chip_data = self ._read (_FT6XXX_REG_LIBH , 8 )
75
+ chip_data = self ._read (_FT6XXX_REG_LIBH , 8 ) # don't wait for IRQ
75
76
lib_ver , chip_id , _ , _ , firm_id , _ , vend_id = struct .unpack (
76
77
">HBBBBBB" , chip_data
77
78
)
@@ -90,10 +91,11 @@ def __init__(self, i2c, address=_FT6206_DEFAULT_I2C_ADDR, debug=False):
90
91
print ("Point rate %d Hz" % self ._read (_FT6XXX_REG_POINTRATE , 1 )[0 ])
91
92
print ("Thresh %d" % self ._read (_FT6XXX_REG_THRESHHOLD , 1 )[0 ])
92
93
94
+
93
95
@property
94
96
def touched (self ):
95
97
""" 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 ]
97
99
98
100
# pylint: disable=unused-variable
99
101
@property
@@ -103,7 +105,7 @@ def touches(self):
103
105
touch coordinates, and 'id' as the touch # for multitouch tracking
104
106
"""
105
107
touchpoints = []
106
- data = self ._read (_FT6XXX_REG_DATA , 32 )
108
+ data = self ._read (_FT6XXX_REG_DATA , 32 , irq_pin = self . irq_pin )
107
109
108
110
for i in range (2 ):
109
111
point_data = data [i * 6 + 3 : i * 6 + 9 ]
@@ -121,11 +123,17 @@ def touches(self):
121
123
122
124
# pylint: enable=unused-variable
123
125
124
- def _read (self , register , length ):
126
+ def _read (self , register , length , irq_pin = None ):
125
127
"""Returns an array of 'length' bytes from the 'register'"""
126
128
with self ._i2c as i2c :
129
+
130
+ if (irq_pin is not None ):
131
+ while (self .irq_pin .value ):
132
+ pass
133
+
127
134
i2c .write (bytes ([register & 0xFF ]))
128
135
result = bytearray (length )
136
+
129
137
i2c .readinto (result )
130
138
if self ._debug :
131
139
print ("\t $%02X => %s" % (register , [hex (i ) for i in result ]))
0 commit comments