-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinger.py
More file actions
46 lines (39 loc) · 1.35 KB
/
finger.py
File metadata and controls
46 lines (39 loc) · 1.35 KB
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
from enum import Enum
import time
class TouchState(Enum):
Touch = 1
NotTouch = 0
class Finger():
def __init__(self, threasholds={"up": 67, "down": 64}):
self.threasholds = threasholds
self.touchStates = TouchState.NotTouch
# For detecting tap
self.touchDownTimer = time.time()
def updateTouchState(self, touchSensorData):
if self.touchStates == TouchState.NotTouch:
if touchSensorData > self.threasholds["up"]:
return self.touchDownEvent()
# else:
# return self.touchUpEvent()
elif self.touchStates == TouchState.Touch:
if touchSensorData < self.threasholds["down"]:
return self.touchUpEvent()
# else:
# return self.touchDownState()
def touchDownState(self):
# print("touchDownState")
self.touchDownTimer = time.time()
self.touchStates = TouchState.Touch
return 2
def touchDownEvent(self):
# print("touchDown")
self.touchDownTimer = time.time()
self.touchStates = TouchState.Touch
return 1
def touchUpEvent(self):
# print("touchUp")
self.touchStates = TouchState.NotTouch
if time.time() - self.touchDownTimer < 150 * 0.001:
return -1 #Tap
else:
return 0