nxbt
nxbt copied to clipboard
nx.tilt_stick() crashes the program
Hi! I'm trying to create a python program to convert my usb gamepad to be detected as a Pro Controller using bluetooth, all the buttons are done, now I'm trying to convert the axis, and it looks like when I use nx.tilt_stick() it disconnects after 5 seconds.
import nxbt
# Load the gamepad and time libraries
import Gamepad
import time
nx = nxbt.Nxbt()
controller_index = nx.create_controller(nxbt.PRO_CONTROLLER)
nx.wait_for_connection(controller_index)
print('Connected')
# Gamepad settings
gamepadType = Gamepad.PS3
buttonA = 'CIRCLE'
buttonB = 'TRIANGLE'
buttonX = 'CROSS'
buttonY = 'SQUARE'
buttonExit = 'PS'
joystickSpeed = 'RIGHT-Y'
joystickSteering = 'R2'
# Wait for a connection
if not Gamepad.available():
print('Please connect your gamepad...')
while not Gamepad.available():
time.sleep(1.0)
gamepad = gamepadType()
print('Gamepad connected')
# Set some initial state
speed = 0.0
steering = 0.0
# Handle joystick updates one at a time
while gamepad.isConnected():
# Wait for the next event
eventType, control, value = gamepad.getNextEvent()
# Determine the type
if eventType == 'BUTTON':
# Button changed
if control == buttonA:
# Happy button (event on press and release)
if value:
print('A')
nx.press_buttons(controller_index, [nxbt.Buttons.A])
elif control == buttonB:
# Beep button (event on press)
if value:
print('B')
nx.press_buttons(controller_index, [nxbt.Buttons.B])
elif control == buttonX:
# Exit button (event on press)
if value:
print('X')
nx.press_buttons(controller_index, [nxbt.Buttons.X])
elif control == buttonY:
# Exit button (event on press)
if value:
print('Y')
nx.press_buttons(controller_index, [nxbt.Buttons.Y])
break
elif eventType == 'AXIS':
# Joystick changed
if control == joystickSpeed:
# Speed control (inverted)
speed = value
elif control == joystickSteering:
# Steering control (not inverted)
steering = value
nx.tilt_stick(controller_index, nxbt.Sticks.RIGHT_STICK, joystickSpeed, 0)
nx.tilt_stick(controller_index, nxbt.Sticks.LEFT_STICK, joystickSteering, 0)
nx.press_buttons(controller_index, [nxbt.Buttons.B])
but if i remove
nx.tilt_stick(controller_index, nxbt.Sticks.RIGHT_STICK, joystickSpeed, 0)
nx.tilt_stick(controller_index, nxbt.Sticks.LEFT_STICK, joystickSteering, 0)
it works.