Added stick tilt functionality
This commit is contained in:
parent
7e99a36675
commit
1619c96cd7
3 changed files with 57 additions and 2 deletions
13
demo.py
13
demo.py
|
|
@ -3,6 +3,7 @@ from random import randint
|
||||||
|
|
||||||
import nxbt
|
import nxbt
|
||||||
from nxbt import Buttons
|
from nxbt import Buttons
|
||||||
|
from nxbt import Sticks
|
||||||
|
|
||||||
MACRO = """
|
MACRO = """
|
||||||
LOOP 12
|
LOOP 12
|
||||||
|
|
@ -78,7 +79,6 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
# Select the last controller for input
|
# Select the last controller for input
|
||||||
controller_idx = controller_idxs[-1]
|
controller_idx = controller_idxs[-1]
|
||||||
time.sleep(4)
|
|
||||||
|
|
||||||
# Wait for the switch to connect to the controller
|
# Wait for the switch to connect to the controller
|
||||||
nx.wait_for_connection(controller_idx)
|
nx.wait_for_connection(controller_idx)
|
||||||
|
|
@ -93,8 +93,17 @@ if __name__ == "__main__":
|
||||||
nx.stop_macro(controller_idx, macro_id)
|
nx.stop_macro(controller_idx, macro_id)
|
||||||
print("Stopped Macro")
|
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"
|
# Return to the "Change Grip/Order Screen"
|
||||||
time.sleep(2)
|
|
||||||
nx.press_buttons(controller_idx, [Buttons.A])
|
nx.press_buttons(controller_idx, [Buttons.A])
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
nx.press_buttons(controller_idx, [Buttons.A])
|
nx.press_buttons(controller_idx, [Buttons.A])
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ from .controller import Controller
|
||||||
from .bluez import *
|
from .bluez import *
|
||||||
from .nxbt import Nxbt
|
from .nxbt import Nxbt
|
||||||
from .nxbt import Buttons
|
from .nxbt import Buttons
|
||||||
|
from .nxbt import Sticks
|
||||||
from .nxbt import JOYCON_L
|
from .nxbt import JOYCON_L
|
||||||
from .nxbt import JOYCON_R
|
from .nxbt import JOYCON_R
|
||||||
from .nxbt import PRO_CONTROLLER
|
from .nxbt import PRO_CONTROLLER
|
||||||
|
|
|
||||||
45
nxbt/nxbt.py
45
nxbt/nxbt.py
|
|
@ -45,6 +45,12 @@ class Buttons():
|
||||||
ZL = 'ZL'
|
ZL = 'ZL'
|
||||||
|
|
||||||
|
|
||||||
|
class Sticks():
|
||||||
|
|
||||||
|
RIGHT_STICK = "R_STICK"
|
||||||
|
LEFT_STICK = "L_STICK"
|
||||||
|
|
||||||
|
|
||||||
class NxbtCommands(Enum):
|
class NxbtCommands(Enum):
|
||||||
|
|
||||||
CREATE_CONTROLLER = 0
|
CREATE_CONTROLLER = 0
|
||||||
|
|
@ -209,6 +215,45 @@ class Nxbt():
|
||||||
|
|
||||||
return macro_id
|
return macro_id
|
||||||
|
|
||||||
|
def tilt_stick(self, controller_index, stick, x, y,
|
||||||
|
tilted=0.1, released=0.1, block=True):
|
||||||
|
|
||||||
|
if controller_index not in self.manager_state.keys():
|
||||||
|
raise ValueError("Specified controller does not exist")
|
||||||
|
|
||||||
|
if x >= 0:
|
||||||
|
x_parsed = f'+{x:03}'
|
||||||
|
else:
|
||||||
|
x_parsed = f'{x:04}'
|
||||||
|
|
||||||
|
if y >= 0:
|
||||||
|
y_parsed = f'+{y:03}'
|
||||||
|
else:
|
||||||
|
y_parsed = f'{y:04}'
|
||||||
|
|
||||||
|
macro = f'{stick}@{x_parsed}{y_parsed} {tilted}s\n{released}s'
|
||||||
|
|
||||||
|
# Get a unique ID to identify the button press
|
||||||
|
# so we can check when the controller is done inputting it
|
||||||
|
macro_id = os.urandom(24).hex()
|
||||||
|
self.task_queue.put({
|
||||||
|
"command": NxbtCommands.INPUT_MACRO,
|
||||||
|
"arguments": {
|
||||||
|
"controller_index": controller_index,
|
||||||
|
"macro": macro,
|
||||||
|
"macro_id": macro_id,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if block:
|
||||||
|
while True:
|
||||||
|
finished = (self.manager_state
|
||||||
|
[controller_index]["finished_macros"])
|
||||||
|
if macro_id in finished:
|
||||||
|
break
|
||||||
|
|
||||||
|
return macro_id
|
||||||
|
|
||||||
def stop_macro(self, controller_index, macro_id, block=True):
|
def stop_macro(self, controller_index, macro_id, block=True):
|
||||||
|
|
||||||
if controller_index not in self.manager_state.keys():
|
if controller_index not in self.manager_state.keys():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue