37
37
38
38
__version__ = "0.0.0+auto.0"
39
39
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FT5336.git"
40
-
40
+ # pylint: disable=too-many-instance-attributes
41
41
_DEFAULT_ADDR = const (0x38 )
42
42
_REG_VENDID = const (0xA3 )
43
43
_REG_CHIPID = const (0xA8 )
49
49
_TOUCH1_XL = const (0x04 )
50
50
_TOUCH1_YH = const (0x05 )
51
51
_TOUCH1_YL = const (0x06 )
52
+ _SCREEN_WIDTH = 320
53
+ _SCREEN_HEIGHT = 480
52
54
53
55
54
56
class Adafruit_FT5336 :
@@ -61,13 +63,23 @@ class Adafruit_FT5336:
61
63
8 , _REG_NUMTOUCHES , 0
62
64
) # 8-bit read-only register for number of touches
63
65
66
+ # pylint: disable=too-many-arguments
64
67
def __init__ (
65
- self , i2c , i2c_addr : int = _DEFAULT_ADDR , max_touches : int = 5
68
+ self ,
69
+ i2c ,
70
+ i2c_addr : int = _DEFAULT_ADDR ,
71
+ max_touches : int = 5 ,
72
+ invert_x : bool = False ,
73
+ invert_y : bool = False ,
74
+ swap_xy : bool = False ,
66
75
) -> None :
67
76
"""Initialization over I2C
68
77
69
78
:param int i2c_addr: I2C address (default 0x38)
70
79
:param int max_touches: Maximum number of touch points to track. Defaults to 5.
80
+ :param bool invert_x: Invert X axis. Defaults to False.
81
+ :param bool invert_y: Invert Y axis. Defaults to False.
82
+ :param bool swap_xy: Swap X and Y axes. Defaults to False.
71
83
"""
72
84
self .i2c_device = I2CDevice (i2c , i2c_addr ) # I2C device instance
73
85
self .i2c_addr = i2c_addr # Store the I2C address
@@ -79,6 +91,15 @@ def __init__(
79
91
self ._touch_y : List [int ] = [0 ] * self .max_touches
80
92
self ._touch_id : List [int ] = [0 ] * self .max_touches
81
93
94
+ # Inversion and swap properties
95
+ self ._invert_x = invert_x
96
+ self ._invert_y = invert_y
97
+ self ._swap_xy = swap_xy
98
+
99
+ # Set screen dimensions
100
+ self ._screen_width = _SCREEN_WIDTH
101
+ self ._screen_height = _SCREEN_HEIGHT
102
+
82
103
# Verify device identity by checking the vendor and chip IDs
83
104
if self ._vend_id != _VENDID :
84
105
raise ValueError ("Incorrect vendor ID" )
@@ -95,12 +116,20 @@ def _read_data(self):
95
116
self ._touches = 0
96
117
97
118
for i in range (self ._touches ):
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
- ]
119
+ x = (buffer [_TOUCH1_XH + i * 6 ] & 0x0F ) << 8 | buffer [_TOUCH1_XL + i * 6 ]
120
+ y = (buffer [_TOUCH1_YH + i * 6 ] & 0x0F ) << 8 | buffer [_TOUCH1_YL + i * 6 ]
121
+
122
+ if self ._invert_x :
123
+ x = self ._screen_width - 1 - x
124
+
125
+ if self ._invert_y :
126
+ y = self ._screen_height - 1 - y
127
+
128
+ if self ._swap_xy :
129
+ x , y = y , x
130
+
131
+ self ._touch_x [i ] = x
132
+ self ._touch_y [i ] = y
104
133
self ._touch_id [i ] = buffer [_TOUCH1_YH + i * 6 ] >> 4
105
134
106
135
@property
@@ -141,3 +170,30 @@ def point(self, point_index: int) -> Tuple:
141
170
else :
142
171
value = (self ._touch_x [point_index ], self ._touch_y [point_index ], 1 )
143
172
return value
173
+
174
+ @property
175
+ def invert_x (self ) -> bool :
176
+ """Whether the X axis is inverted"""
177
+ return self ._invert_x
178
+
179
+ @invert_x .setter
180
+ def invert_x (self , value : bool ):
181
+ self ._invert_x = value
182
+
183
+ @property
184
+ def invert_y (self ) -> bool :
185
+ """Whether the Y axis is inverted"""
186
+ return self ._invert_y
187
+
188
+ @invert_y .setter
189
+ def invert_y (self , value : bool ):
190
+ self ._invert_y = value
191
+
192
+ @property
193
+ def swap_xy (self ) -> bool :
194
+ """Whether the X and Y axes are swapped"""
195
+ return self ._swap_xy
196
+
197
+ @swap_xy .setter
198
+ def swap_xy (self , value : bool ):
199
+ self ._swap_xy = value
0 commit comments