-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgt1151-gesture-test.py
63 lines (49 loc) · 1.61 KB
/
gt1151-gesture-test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/opt/homebrew/bin/python3
from gt1151ef import TouchData, GT1151
import logging
import threading
logging.basicConfig(
level=logging.DEBUG, format="%(asctime)s %(funcName)s %(lineno)d %(message)s", datefmt="%Y-%m-%dT%H:%M:%S%z"
)
logger = logging.getLogger(__name__)
flag_t = 1
gt = GT1151()
gest_current = TouchData()
gest_old = TouchData()
def pthread_irq():
logger.debug("pthread running")
while flag_t == 1:
if gt.digital_read(gt.INT) == 0:
gest_current.Touch = 1
else:
gest_current.Touch = 0
print("thread:exit")
def main():
logger.info("testing gt1151 gesture functionality")
try:
gt.GT_Init() # initialize GT1151 touch controller
gt.Gesture() # enable gesture mode
t = threading.Thread(target=pthread_irq)
t.setDaemon(True)
t.start()
while 1:
gt.GT_Gesture_Scan(gest_current, gest_old)
logging.debug(f"Touch: {gest_current.Touch}")
logging.debug(f"TouchpointFlag: {gest_current.TouchpointFlag}")
logging.debug(f"TouchCount: {gest_current.TouchCount}")
logging.debug(f"Touchkeytrackid: {gest_current.Touchkeytrackid}")
logging.debug(f"X: {gest_current.X}")
logging.debug(f"Y: {gest_current.Y}")
logging.debug(f"S: {gest_current.S}")
gest_old = gest_current
except IOError as e:
logging.exception(e)
raise
except KeyboardInterrupt:
logging.info("ctrl + c:")
flag_t = 0
t.join()
exit()
if __name__ == '__main__':
main()
logger.info("main:exit")