GHIElectronics.Endpoint.Devices.Touch 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/Devices/Touch/__init__.py +150 -0
- ghielectronics_endpoint_devices_touch-0.5.3.dist-info/METADATA +20 -0
- ghielectronics_endpoint_devices_touch-0.5.3.dist-info/RECORD +5 -0
- ghielectronics_endpoint_devices_touch-0.5.3.dist-info/WHEEL +5 -0
- ghielectronics_endpoint_devices_touch-0.5.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""Touchscreens on Endpoint.
|
|
2
|
+
|
|
3
|
+
Touch is abstract: subclass it for your panel's chip (I2C, SPI, custom).
|
|
4
|
+
Interrupt-driven drivers are first class - open a GPIO line via
|
|
5
|
+
GHIElectronics.Endpoint.Devices.Gpio and attach to its ValueChanged event.
|
|
6
|
+
|
|
7
|
+
The library ships one concrete subclass, InputTouch, that wraps a kernel
|
|
8
|
+
/dev/input/eventN. USB HID touchscreens show up this way automatically.
|
|
9
|
+
|
|
10
|
+
from GHIElectronics.Endpoint.Devices.Touch import Touch
|
|
11
|
+
|
|
12
|
+
class MyFt5x06(Touch):
|
|
13
|
+
# ... open I2C, pulse reset, attach to interrupt GPIO ...
|
|
14
|
+
@property
|
|
15
|
+
def Width(self): return 800
|
|
16
|
+
@property
|
|
17
|
+
def Height(self): return 480
|
|
18
|
+
@property
|
|
19
|
+
def Connected(self): return True
|
|
20
|
+
def Dispose(self): ...
|
|
21
|
+
|
|
22
|
+
t = MyFt5x06(i2c_bus=6, address=0x38, reset_pin=\"PF2\", int_pin=\"PF12\")
|
|
23
|
+
t.OnChangedEvent += lambda s, e: print(e.Points)
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
import abc
|
|
27
|
+
import ctypes
|
|
28
|
+
import sys
|
|
29
|
+
from enum import IntEnum
|
|
30
|
+
|
|
31
|
+
from GHIElectronics.Endpoint.Core._event import _EventProperty
|
|
32
|
+
from GHIElectronics.Endpoint.Core._native import TouchCallback, native
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class TouchEventType(IntEnum):
|
|
36
|
+
"""How the Points changed between frames."""
|
|
37
|
+
Pressed = 0
|
|
38
|
+
Released = 1
|
|
39
|
+
Moved = 2
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class TouchPoint:
|
|
43
|
+
"""One finger on the touchscreen."""
|
|
44
|
+
__slots__ = ("Id", "X", "Y")
|
|
45
|
+
|
|
46
|
+
def __init__(self, id_, x, y):
|
|
47
|
+
self.Id = id_
|
|
48
|
+
self.X = x
|
|
49
|
+
self.Y = y
|
|
50
|
+
|
|
51
|
+
def __repr__(self):
|
|
52
|
+
return f"TouchPoint(Id={self.Id}, X={self.X}, Y={self.Y})"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class TouchEventArgs:
|
|
56
|
+
def __init__(self, eventType, points):
|
|
57
|
+
self.EventType = eventType
|
|
58
|
+
self.Points = points
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class Touch(abc.ABC):
|
|
62
|
+
"""A touchscreen on the board. Abstract: subclass for custom chips, use
|
|
63
|
+
GetDefault() for a kernel /dev/input/eventN device (USB touchscreens)."""
|
|
64
|
+
|
|
65
|
+
OnChangedEvent = _EventProperty("OnChangedEvent")
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
@abc.abstractmethod
|
|
69
|
+
def Width(self):
|
|
70
|
+
"""Visible width of the touchscreen area, in pixels."""
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
@abc.abstractmethod
|
|
74
|
+
def Height(self):
|
|
75
|
+
"""Visible height of the touchscreen area, in pixels."""
|
|
76
|
+
|
|
77
|
+
@property
|
|
78
|
+
@abc.abstractmethod
|
|
79
|
+
def Connected(self):
|
|
80
|
+
"""True while the touchscreen is physically present and responding."""
|
|
81
|
+
|
|
82
|
+
@abc.abstractmethod
|
|
83
|
+
def Dispose(self):
|
|
84
|
+
"""Release the touchscreen's resources (I2C handle, GPIO, etc.)."""
|
|
85
|
+
|
|
86
|
+
def _RaiseChanged(self, args):
|
|
87
|
+
"""Subclasses call this to emit a touch event. Exceptions in handlers
|
|
88
|
+
are printed, never raised back out of the device thread."""
|
|
89
|
+
try:
|
|
90
|
+
handler = self.OnChangedEvent
|
|
91
|
+
if handler is not None:
|
|
92
|
+
handler(self, args)
|
|
93
|
+
except Exception as e:
|
|
94
|
+
print(f"Unhandled exception in a Touch event: {e}", file=sys.stderr)
|
|
95
|
+
|
|
96
|
+
@staticmethod
|
|
97
|
+
def GetDefault():
|
|
98
|
+
"""The first kernel-exposed touchscreen the library can find at
|
|
99
|
+
/dev/input/eventN, or None if none is present. For USB HID
|
|
100
|
+
touchscreens; the on-board panel's custom chip is the customer's
|
|
101
|
+
own subclass and does not come through here."""
|
|
102
|
+
return InputTouch._find_default()
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class InputTouch(Touch):
|
|
106
|
+
"""Touchscreen backed by a kernel input device at /dev/input/eventN."""
|
|
107
|
+
|
|
108
|
+
def __init__(self, deviceName):
|
|
109
|
+
self.DeviceName = deviceName
|
|
110
|
+
self._handle = native.out_handle()
|
|
111
|
+
self._callback = TouchCallback(self._OnChanged)
|
|
112
|
+
native.touch_open(deviceName.encode(), self._callback, None, native.ref(self._handle))
|
|
113
|
+
v, p, c, w, h = (native.out_int() for _ in range(5))
|
|
114
|
+
native.touch_info(self._handle, native.ref(v), native.ref(p), native.ref(c),
|
|
115
|
+
native.ref(w), native.ref(h))
|
|
116
|
+
self.VendorId = v.value
|
|
117
|
+
self.ProductId = p.value
|
|
118
|
+
self._connected = c.value != 0
|
|
119
|
+
self._width = w.value
|
|
120
|
+
self._height = h.value
|
|
121
|
+
native.keep_alive(self)
|
|
122
|
+
|
|
123
|
+
@property
|
|
124
|
+
def Width(self):
|
|
125
|
+
return self._width
|
|
126
|
+
|
|
127
|
+
@property
|
|
128
|
+
def Height(self):
|
|
129
|
+
return self._height
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
def Connected(self):
|
|
133
|
+
return self._connected
|
|
134
|
+
|
|
135
|
+
@classmethod
|
|
136
|
+
def _find_default(cls):
|
|
137
|
+
buffer = ctypes.create_string_buffer(64)
|
|
138
|
+
native.touch_find_default(buffer, len(buffer))
|
|
139
|
+
path = buffer.value.decode("ascii")
|
|
140
|
+
return cls(path) if path else None
|
|
141
|
+
|
|
142
|
+
def Dispose(self):
|
|
143
|
+
if self._handle:
|
|
144
|
+
native.touch_close(self._handle)
|
|
145
|
+
self._handle = None
|
|
146
|
+
native.let_go(self)
|
|
147
|
+
|
|
148
|
+
def _OnChanged(self, _context, eventType, pointCount, ids, xs, ys):
|
|
149
|
+
points = [TouchPoint(ids[i], xs[i], ys[i]) for i in range(pointCount)]
|
|
150
|
+
self._RaiseChanged(TouchEventArgs(TouchEventType(eventType), points))
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: GHIElectronics.Endpoint.Devices.Touch
|
|
3
|
+
Version: 0.5.3
|
|
4
|
+
Summary: Touchscreen support for Endpoint. The Touch class is abstract: subclass it for your panel's chip. Ships one concrete subclass, InputTouch, that wraps a kernel /dev/input/eventN (used for USB touchscreens).
|
|
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-Libraries
|
|
9
|
+
Project-URL: Issues, https://github.com/ghi-electronics/Endpoint-Libraries/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
|
+
|
|
16
|
+
# GHIElectronics.Endpoint.Devices.Touch
|
|
17
|
+
|
|
18
|
+
Touchscreen support for Endpoint. The Touch class is abstract: subclass it for your panel's chip. Ships one concrete subclass, InputTouch, that wraps a kernel /dev/input/eventN (used for USB touchscreens).
|
|
19
|
+
|
|
20
|
+
Part of the [GHI Electronics Endpoint](https://github.com/ghi-electronics/Endpoint-Libraries) libraries. See the repository README for the full package list and getting-started guide.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
GHIElectronics/Endpoint/Devices/Touch/__init__.py,sha256=PQJSIiPvVHXG-orl7mDcyN5zOujsANdDfIrVgjkaMpE,4734
|
|
2
|
+
ghielectronics_endpoint_devices_touch-0.5.3.dist-info/METADATA,sha256=IQSlLa5RhijehpfU4q08BQ_w_7AM87zwr9a35K933E4,1269
|
|
3
|
+
ghielectronics_endpoint_devices_touch-0.5.3.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
4
|
+
ghielectronics_endpoint_devices_touch-0.5.3.dist-info/top_level.txt,sha256=NpOZNgd0iquwrRPrTOhUDxc2V9TtNFLv5Z_Dx3YZtIU,15
|
|
5
|
+
ghielectronics_endpoint_devices_touch-0.5.3.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
GHIElectronics
|