-
Notifications
You must be signed in to change notification settings - Fork 101
/
demo.py
122 lines (105 loc) · 2.77 KB
/
demo.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import time
from random import randint
import nxbt
from nxbt import Buttons
from nxbt import Sticks
MACRO = """
LOOP 12
B 0.1s
0.1s
1.5s
DPAD_RIGHT 0.075s
0.075s
A 0.1s
1.5s
DPAD_DOWN 1.00s
A 0.1s
0.25s
DPAD_DOWN 0.95s
A 0.1s
0.25s
L_STICK_PRESS 0.1s
1.0s
L_STICK@-100+000 0.5s
L_STICK@+000+100 0.5s
L_STICK@+100+000 0.5s
L_STICK@+000-100 0.5s
B 0.1s
0.25s
R_STICK_PRESS 0.1s
1.0s
R_STICK@-100+000 0.5s
R_STICK@+000+100 0.5s
R_STICK@+100+000 0.5s
R_STICK@+000-100 0.5s
LOOP 4
B 0.1s
0.1s
B 0.1s
0.4s
DPAD_LEFT 0.1s
0.1s
A 0.1s
1.5s
A 0.1s
5.0s
"""
def random_colour():
return [
randint(0, 255),
randint(0, 255),
randint(0, 255),
]
if __name__ == "__main__":
# Init NXBT
nx = nxbt.Nxbt()
# Get a list of all available Bluetooth adapters
adapters = nx.get_available_adapters()
# Prepare a list to store the indexes of the
# created controllers.
controller_idxs = []
# Loop over all Bluetooth adapters and create
# Switch Pro Controllers
for i in range(0, len(adapters)):
index = nx.create_controller(
nxbt.PRO_CONTROLLER,
adapter_path=adapters[i],
colour_body=random_colour(),
colour_buttons=random_colour())
controller_idxs.append(index)
# Select the last controller for input
controller_idx = controller_idxs[-1]
# Wait for the switch to connect to the controller
nx.wait_for_connection(controller_idx)
# Run a macro on the last controller
# and don't wait for the macro to complete
print("Macro Started")
macro_id = nx.macro(controller_idx, MACRO, block=False)
time.sleep(3)
# Stop the macro
print("Stopping Macro")
nx.stop_macro(controller_idx, macro_id)
print("Stopped Macro")
# Moving the selected home screen item two spaces to the right and back.
nx.tilt_stick(controller_idx, Sticks.RIGHT_STICK, 100, 0,
tilted=0.25, released=0.25)
nx.tilt_stick(controller_idx, Sticks.RIGHT_STICK, 100, 0,
tilted=0.25, released=0.25)
nx.tilt_stick(controller_idx, Sticks.RIGHT_STICK, -100, 0,
tilted=0.25, released=0.25)
nx.tilt_stick(controller_idx, Sticks.RIGHT_STICK, -100, 0,
tilted=0.25, released=0.25)
# Return to the "Change Grip/Order Screen"
nx.press_buttons(controller_idx, [Buttons.A])
time.sleep(2)
nx.press_buttons(controller_idx, [Buttons.A])
time.sleep(2)
# Enter the same macro, but block this time
print("Macro Started")
macro_id = nx.macro(controller_idx, MACRO)
print("Macro finished, going to the home screen...")
nx.press_buttons(controller_idx, [Buttons.B])
time.sleep(2)
nx.press_buttons(controller_idx, [Buttons.B])
time.sleep(2)
print("Exiting...")