45
45
46
46
_FT6206_DEFAULT_I2C_ADDR = 0x38
47
47
48
- _FT6XXX_REG_DATA = 0x00
49
- _FT6XXX_REG_NUMTOUCHES = 0x02
50
- _FT6XXX_REG_THRESHHOLD = 0x80
51
- _FT6XXX_REG_POINTRATE = 0x88
52
- _FT6XXX_REG_LIBH = 0xA1
53
- _FT6XXX_REG_LIBL = 0xA2
54
- _FT6XXX_REG_CHIPID = 0xA3
55
- _FT6XXX_REG_FIRMVERS = 0xA6
56
- _FT6XXX_REG_VENDID = 0xA8
57
- _FT6XXX_REG_RELEASE = 0xAF
48
+ _FT6XXX_REG_DATA = const ( 0x00 )
49
+ _FT6XXX_REG_NUMTOUCHES = const ( 0x02 )
50
+ _FT6XXX_REG_THRESHHOLD = const ( 0x80 )
51
+ _FT6XXX_REG_POINTRATE = const ( 0x88 )
52
+ _FT6XXX_REG_LIBH = const ( 0xA1 )
53
+ _FT6XXX_REG_LIBL = const ( 0xA2 )
54
+ _FT6XXX_REG_CHIPID = const ( 0xA3 )
55
+ _FT6XXX_REG_FIRMVERS = const ( 0xA6 )
56
+ _FT6XXX_REG_VENDID = const ( 0xA8 )
57
+ _FT6XXX_REG_RELEASE = const ( 0xAF )
58
58
59
59
class Adafruit_FocalTouch :
60
60
"""
@@ -63,41 +63,46 @@ class Adafruit_FocalTouch:
63
63
64
64
_debug = False
65
65
chip = None
66
-
66
+
67
67
def __init__ (self , i2c , address = _FT6206_DEFAULT_I2C_ADDR , debug = False ):
68
68
self ._i2c = I2CDevice (i2c , address )
69
69
self ._debug = debug
70
70
71
71
chip_data = self ._read (_FT6XXX_REG_LIBH , 9 )
72
- lib_ver , chip_id , g_mode , pwr_mode , firm_id , skip , vend_id = struct .unpack ('>HBBBBBB' , chip_data )
72
+ lib_ver , chip_id , _ , _ , firm_id , _ , vend_id = struct .unpack ('>HBBBBBB' , chip_data )
73
73
74
74
if vend_id != 0x11 :
75
75
raise RuntimeError ("Did not find FT chip" )
76
76
77
77
if chip_id == 0x06 :
78
- chip = "FT6206"
78
+ self . chip = "FT6206"
79
79
elif chip_id == 0x64 :
80
- chip = "FT6236"
80
+ self . chip = "FT6236"
81
81
82
82
if debug :
83
83
print ("Library vers %04X" % lib_ver )
84
84
print ("Firmware ID %02X" % firm_id )
85
85
print ("Point rate %d Hz" % self ._read (_FT6XXX_REG_POINTRATE , 1 )[0 ])
86
86
print ("Thresh %d" % self ._read (_FT6XXX_REG_THRESHHOLD , 1 )[0 ])
87
-
88
-
89
87
90
88
@property
91
89
def touched (self ):
92
- return self ._read (_FT6XXX_REG_NUMTOUCHES , 1 )[0 ]
90
+ """ Returns the number of touches currently detected """
91
+ return self ._read (_FT6XXX_REG_NUMTOUCHES , 1 )[0 ]
93
92
93
+
94
+ # pylint: disable=unused-variable
94
95
@property
95
96
def touches (self ):
97
+ """
98
+ Returns a list of touchpoint dicts, with 'x' and 'y' containing the
99
+ touch coordinates, and 'id' as the touch # for multitouch tracking
100
+ """
96
101
touchpoints = []
97
102
data = self ._read (_FT6XXX_REG_DATA , 32 )
98
103
99
- for t in range (2 ):
100
- point_data = data [t * 6 + 3 : t * 6 + 9 ]
104
+ for i in range (2 ):
105
+ point_data = data [i * 6 + 3 : i * 6 + 9 ]
101
106
if all ([i == 0xFF for i in point_data ]):
102
107
continue
103
108
#print([hex(i) for i in point_data])
@@ -106,9 +111,10 @@ def touches(self):
106
111
touch_id = y >> 12
107
112
x &= 0xFFF
108
113
y &= 0xFFF
109
- point = {'x' :x , 'y' : y , 'id' : touch_id }
114
+ point = {'x' :x , 'y' :y , 'id' :touch_id }
110
115
touchpoints .append (point )
111
116
return touchpoints
117
+ # pylint: enable=unused-variable
112
118
113
119
def _read (self , register , length ):
114
120
"""Returns an array of 'length' bytes from the 'register'"""
@@ -127,4 +133,3 @@ def _write(self, register, values):
127
133
i2c .write (bytes (values ))
128
134
if self ._debug :
129
135
print ("\t $%02X <= %s" % (values [0 ], [hex (i ) for i in values [1 :]]))
130
-
0 commit comments