GHIElectronics.Endpoint.Drivers.FocalTech.FT5xx6 0.5.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- GHIElectronics/Endpoint/Drivers/FocalTech/FT5xx6/__init__.py +157 -0
- ghielectronics_endpoint_drivers_focaltech_ft5xx6-0.5.3.dist-info/METADATA +22 -0
- ghielectronics_endpoint_drivers_focaltech_ft5xx6-0.5.3.dist-info/RECORD +5 -0
- ghielectronics_endpoint_drivers_focaltech_ft5xx6-0.5.3.dist-info/WHEEL +5 -0
- ghielectronics_endpoint_drivers_focaltech_ft5xx6-0.5.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""FocalTech FT5xx6 capacitive-touch driver for GHI Endpoint (Python).
|
|
2
|
+
|
|
3
|
+
Companion to GHIElectronics.Endpoint.Drivers.FocalTech.FT5xx6 (.NET).
|
|
4
|
+
Reusable across any Endpoint board: the caller opens a GpioController
|
|
5
|
+
and passes it in; this file does no chip-specific pin math.
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
|
|
9
|
+
from GHIElectronics.Endpoint.Core import EPDomino24, I2cController
|
|
10
|
+
from GHIElectronics.Endpoint.Devices.Gpio import GpioController
|
|
11
|
+
from GHIElectronics.Endpoint.Drivers.FocalTech.FT5xx6 import Ft5xx6Controller
|
|
12
|
+
|
|
13
|
+
I2cController.Initialize(EPDomino24.I2c.I2c5)
|
|
14
|
+
gpio = GpioController()
|
|
15
|
+
touch = Ft5xx6Controller(
|
|
16
|
+
i2c_bus=EPDomino24.I2c.I2c5,
|
|
17
|
+
interrupt_pin=EPDomino24.Gpio.Pin.PB11,
|
|
18
|
+
gpio=gpio)
|
|
19
|
+
touch.TouchDown += lambda s, e: print(f"down ({e.X}, {e.Y})")
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from enum import IntEnum
|
|
23
|
+
|
|
24
|
+
from GHIElectronics.Endpoint.Core._event import Event
|
|
25
|
+
from GHIElectronics.Endpoint.Devices.Gpio import PinMode, PinEventTypes
|
|
26
|
+
from GHIElectronics.Endpoint.Devices.I2c import I2cDevice, I2cConnectionSettings
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
DEVICE_ADDRESS = 0x38
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class TouchEventArgs:
|
|
33
|
+
__slots__ = ("X", "Y")
|
|
34
|
+
|
|
35
|
+
def __init__(self, x, y):
|
|
36
|
+
self.X = x
|
|
37
|
+
self.Y = y
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Gesture(IntEnum):
|
|
41
|
+
MoveUp = 0x10
|
|
42
|
+
MoveLeft = 0x14
|
|
43
|
+
MoveDown = 0x18
|
|
44
|
+
MoveRight = 0x1C
|
|
45
|
+
ZoomIn = 0x48
|
|
46
|
+
ZoomOut = 0x49
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class GestureEventArgs:
|
|
50
|
+
__slots__ = ("Gesture",)
|
|
51
|
+
|
|
52
|
+
def __init__(self, gesture):
|
|
53
|
+
self.Gesture = gesture
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class TouchOrientation(IntEnum):
|
|
57
|
+
Degrees0 = 0
|
|
58
|
+
Degrees90 = 1
|
|
59
|
+
Degrees180 = 2
|
|
60
|
+
Degrees270 = 3
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class Ft5xx6Controller:
|
|
64
|
+
"""FocalTech FT5xx6 capacitive touch controller. TouchDown / TouchUp /
|
|
65
|
+
TouchMove and GestureReceived are `+=` / `-=` events (same shape as
|
|
66
|
+
GpioController.ValueChanged)."""
|
|
67
|
+
|
|
68
|
+
DeviceAddress = DEVICE_ADDRESS
|
|
69
|
+
|
|
70
|
+
def __init__(self, i2c_bus, interrupt_pin, gpio):
|
|
71
|
+
if gpio is None:
|
|
72
|
+
raise ValueError("gpio must not be None")
|
|
73
|
+
|
|
74
|
+
self._i2c = I2cDevice.Create(I2cConnectionSettings(i2c_bus, DEVICE_ADDRESS))
|
|
75
|
+
self._gpio = gpio
|
|
76
|
+
self._interrupt_pin = interrupt_pin
|
|
77
|
+
self._address_buffer = bytes([0])
|
|
78
|
+
self._read32 = bytearray(32)
|
|
79
|
+
|
|
80
|
+
self.TouchDown = Event()
|
|
81
|
+
self.TouchUp = Event()
|
|
82
|
+
self.TouchMove = Event()
|
|
83
|
+
self.GestureReceived = Event()
|
|
84
|
+
|
|
85
|
+
self.Width = 0
|
|
86
|
+
self.Height = 0
|
|
87
|
+
self.Orientation = TouchOrientation.Degrees0
|
|
88
|
+
self.SampleCount = 5
|
|
89
|
+
|
|
90
|
+
self._gpio.OpenPin(self._interrupt_pin, PinMode.Input)
|
|
91
|
+
self._gpio.RegisterCallbackForPinValueChangedEvent(
|
|
92
|
+
self._interrupt_pin, PinEventTypes.Falling, self._on_interrupt)
|
|
93
|
+
|
|
94
|
+
def _on_interrupt(self, _sender, _args):
|
|
95
|
+
try:
|
|
96
|
+
self._i2c.WriteRead(self._address_buffer, self._read32)
|
|
97
|
+
buf = self._read32
|
|
98
|
+
|
|
99
|
+
if buf[1] != 0 and len(self.GestureReceived):
|
|
100
|
+
self.GestureReceived(self, GestureEventArgs(Gesture(buf[1])))
|
|
101
|
+
|
|
102
|
+
# We do not read TD_STATUS: it excludes touch-up events even
|
|
103
|
+
# though the per-sample registers contain the correct data.
|
|
104
|
+
for i in range(self.SampleCount):
|
|
105
|
+
idx = i * 6 + 3
|
|
106
|
+
flag = (buf[idx] & 0xC0) >> 6
|
|
107
|
+
x = ((buf[idx] & 0x0F) << 8) | buf[idx + 1]
|
|
108
|
+
y = ((buf[idx + 2] & 0x0F) << 8) | buf[idx + 3]
|
|
109
|
+
|
|
110
|
+
if self.Orientation != TouchOrientation.Degrees0:
|
|
111
|
+
if self.Width == 0 or self.Height == 0:
|
|
112
|
+
raise ValueError("Width and Height must be set before rotating")
|
|
113
|
+
if self.Orientation == TouchOrientation.Degrees180:
|
|
114
|
+
x = self.Width - x
|
|
115
|
+
y = self.Height - y
|
|
116
|
+
elif self.Orientation == TouchOrientation.Degrees270:
|
|
117
|
+
temp = x
|
|
118
|
+
x = self.Width - y
|
|
119
|
+
y = temp
|
|
120
|
+
elif self.Orientation == TouchOrientation.Degrees90:
|
|
121
|
+
tmp = x
|
|
122
|
+
x = y
|
|
123
|
+
y = self.Width - tmp
|
|
124
|
+
|
|
125
|
+
args = TouchEventArgs(x, y)
|
|
126
|
+
if flag == 0:
|
|
127
|
+
self.TouchDown(self, args)
|
|
128
|
+
elif flag == 1:
|
|
129
|
+
self.TouchUp(self, args)
|
|
130
|
+
elif flag == 2:
|
|
131
|
+
self.TouchMove(self, args)
|
|
132
|
+
elif flag == 3:
|
|
133
|
+
break
|
|
134
|
+
except Exception:
|
|
135
|
+
# Don't tear down the IRQ handler on a single bad read.
|
|
136
|
+
pass
|
|
137
|
+
|
|
138
|
+
def Dispose(self):
|
|
139
|
+
try:
|
|
140
|
+
self._gpio.UnregisterCallbackForPinValueChangedEvent(
|
|
141
|
+
self._interrupt_pin, self._on_interrupt)
|
|
142
|
+
except Exception:
|
|
143
|
+
pass
|
|
144
|
+
try: self._gpio.ClosePin(self._interrupt_pin)
|
|
145
|
+
except Exception: pass
|
|
146
|
+
try: self._i2c.Dispose()
|
|
147
|
+
except Exception: pass
|
|
148
|
+
|
|
149
|
+
def __enter__(self):
|
|
150
|
+
return self
|
|
151
|
+
|
|
152
|
+
def __exit__(self, *_):
|
|
153
|
+
self.Dispose()
|
|
154
|
+
|
|
155
|
+
def __del__(self):
|
|
156
|
+
try: self.Dispose()
|
|
157
|
+
except Exception: pass
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: GHIElectronics.Endpoint.Drivers.FocalTech.FT5xx6
|
|
3
|
+
Version: 0.5.3
|
|
4
|
+
Summary: FocalTech FT5xx6 capacitive-touch driver for Endpoint. Mirrors the .NET driver API.
|
|
5
|
+
Author-email: "GHI Electronics, LLC" <support@ghielectronics.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://www.ghielectronics.com/
|
|
8
|
+
Project-URL: Repository, https://github.com/ghi-electronics/endpoint-drivers
|
|
9
|
+
Project-URL: Issues, https://github.com/ghi-electronics/endpoint-drivers/issues
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: GHIElectronics.Endpoint.Core<0.6,>=0.5.3
|
|
15
|
+
Requires-Dist: GHIElectronics.Endpoint.Devices.Gpio<0.6,>=0.5.3
|
|
16
|
+
Requires-Dist: GHIElectronics.Endpoint.Devices.I2c<0.6,>=0.5.3
|
|
17
|
+
|
|
18
|
+
# GHIElectronics.Endpoint.Drivers.FocalTech.FT5xx6
|
|
19
|
+
|
|
20
|
+
FocalTech FT5xx6 capacitive-touch driver for Endpoint (Python). Mirrors the .NET driver API.
|
|
21
|
+
|
|
22
|
+
Part of the [GHI Electronics Endpoint drivers](https://github.com/ghi-electronics/endpoint-drivers). See the repository README for the full driver list.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
GHIElectronics/Endpoint/Drivers/FocalTech/FT5xx6/__init__.py,sha256=S3c8sgCzblahBc73PJx0t7DdQKM4F7Q1eMNcQ26NQ4A,5025
|
|
2
|
+
ghielectronics_endpoint_drivers_focaltech_ft5xx6-0.5.3.dist-info/METADATA,sha256=0DPFFyow9UZ_QKB8RStvfxiCSSQl7bEq0HhY97QIoyI,1150
|
|
3
|
+
ghielectronics_endpoint_drivers_focaltech_ft5xx6-0.5.3.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
4
|
+
ghielectronics_endpoint_drivers_focaltech_ft5xx6-0.5.3.dist-info/top_level.txt,sha256=NpOZNgd0iquwrRPrTOhUDxc2V9TtNFLv5Z_Dx3YZtIU,15
|
|
5
|
+
ghielectronics_endpoint_drivers_focaltech_ft5xx6-0.5.3.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
GHIElectronics
|