-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbasic.py
More file actions
90 lines (62 loc) · 2.75 KB
/
Copy pathbasic.py
File metadata and controls
90 lines (62 loc) · 2.75 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import asyncio
import logging
import time
from tapsdk import AirGestures, InputType, TapSDK
from tapsdk import inputmodes as im
from tapsdk.enumerations import FingerAcclSensitivity, ImuGyroSensitivity, ImuAcclSensitivity
logging.basicConfig(level=logging.INFO)
logging.getLogger("tapsdk").setLevel(logging.DEBUG)
logger = logging.getLogger(__name__)
def OnDisconnection(identifier):
logger.info("Disconnected. %s", identifier)
def OnConnection(identifier):
logger.info("Connected. %s", identifier)
def OnMouseModeChange(identifier, mouse_mode):
logger.info("%s changed to mode %s", identifier, mouse_mode)
def OnTapped(identifier, tapcode):
logger.info("%s tapped %s", identifier, tapcode)
def OnGesture(identifier, gesture):
logger.info("%s gesture %s", identifier, AirGestures(gesture))
def OnMoused(identifier, vx, vy, isMouse):
logger.info("%s mouse movement: %d, %d, %d", identifier, vx, vy, isMouse)
def OnRawData(identifier, packets):
for m in packets:
logger.info("%s, %s, %s", m['type'], time.time(), m['payload'])
async def run():
client = TapSDK()
client.register_disconnection_events(OnDisconnection)
client.register_connection_events(OnConnection)
client.register_air_gesture_events(OnGesture)
client.register_tap_events(OnTapped)
client.register_raw_data_events(OnRawData)
client.register_mouse_events(OnMoused)
client.register_air_gesture_state_events(OnMouseModeChange)
await client.run()
logger.info("Connected: %s", client.client.is_connected)
logger.info("Set Controller Mode for 5 seconds")
await client.set_input_mode(im.InputModeController())
await asyncio.sleep(5)
logger.info("Force Mouse Mode for 5 seconds")
await client.set_input_type(InputType.MOUSE)
await asyncio.sleep(5)
logger.info("Force keyboard Mode for 5 seconds")
await client.set_input_type(InputType.KEYBOARD)
await asyncio.sleep(5)
logger.info("Set auto Mode for 10 seconds")
await client.set_input_type(InputType.AUTO)
await asyncio.sleep(10)
logger.info("Set Text Mode for 10 seconds")
await client.set_input_mode(im.InputModeText())
await asyncio.sleep(10)
logger.info("Send Haptics")
await client.send_vibration_sequence([100, 200, 100, 200, 500])
await asyncio.sleep(5)
logger.info("Set Raw Mode for 5 seconds")
await asyncio.sleep(2)
await client.set_input_mode(im.InputModeRaw(finger_accl_sens=FingerAcclSensitivity.G16,
imu_gyro_sens=ImuGyroSensitivity.DPS500,
imu_accl_sens=ImuAcclSensitivity.G4,
scaled=True))
await asyncio.sleep(5)
if __name__ == "__main__":
asyncio.run(run())