yannbouteiller / vgamepad

Virtual XBox360 and DualShock4 gamepads in python
MIT License
162 stars 21 forks source link

xboxs not work left and right joystick #17

Closed natrix5369 closed 1 year ago

natrix5369 commented 1 year ago

Hi. left_joystick_float and right_joystick_float not work for xbox series s/x :(

yannbouteiller commented 1 year ago

Hi, can you be more precise to describe the issue that you face please?

vgamepad does not emulate xbox series s/x gamepads at the moment, only vanilla xbox 360 gamepads.

natrix5369 commented 1 year ago

Hi, can you be more precise to describe the issue that you face please?

vgamepad does not emulate xbox series s/x gamepads at the moment, only vanilla xbox 360 gamepads.

I get it :(

The thing is that xboxs works fine with all vgamepad buttons, except the sticks :(

Are there any predictions on the implementation?

yannbouteiller commented 1 year ago

Maybe in the C++ code of vigem, but I doubt there are. The stick "float" API just converts the -1.0/1.0 range to integers and calls the "raw" API, what happens when you call the "raw" joystick API directly?

nahlahman commented 1 year ago

In case anyone managed to map physical Joycon joysticks with Vgamepad's virtual 360 joysticks, I would love to hear it. I've succeeded with all the buttons and triggers, but the joysticks have been kicking my ass.

I don't think it's a problem with vgamepad. I'm just a terrible programmer : )

yannbouteiller commented 1 year ago

I am still not sure what goes wrong exactly, can you share your code maybe ?

Closing as this doesn't seem to be an issue with vgamepad, but feel free to continue the discussion here. Please use stackoverflow for questions.

nahlahman commented 1 year ago

Yeah, in my case (I am not the OP of this topic) I was just trying to see if there's someone who already worked with joycons and Vgamepad to save me the trouble. I am simply a complete noob (this is my first project ever). For people who haven't worked with joycons, I don't expect help because it's quite a specific issue.

If you'd like to see how bad my understanding is of the joysticks, here is the relevant code I have tried. Although I've tried many other variations.

import vgamepad as vg
from pyjoycon import JoyCon, get_R_id, get_L_id
import hid

JOYCON_VENDOR_ID = 0x057e
JOYCON_PRODUCT_ID = 0x2006
JOYCON_REPORT_SIZE = 49
gamepad = vg.VX360Gamepad()

gamepad.left_joystick_float(x_value_float=-0.5, y_value_float=0.0)  # values between -1.0 and 1.0
gamepad.right_joystick_float(x_value_float=-1.0, y_value_float=0.8)  # values between -1.0 and 1.0

def get_joycon_device(joycon_id):
    joycon_devices = hid.enumerate(JOYCON_VENDOR_ID, JOYCON_PRODUCT_ID)
    for device_info in joycon_devices:
        if device_info['serial_number'] == joycon_id:
            joycon_device = hid.device()
            joycon_device.open_path(device_info['path'])
            return joycon_device

right_joycon_id = get_R_id()
left_joycon_id = get_L_id()

right_joycon = JoyCon(*right_joycon_id)
left_joycon = JoyCon(*left_joycon_id)

while True:
    right_report = right_joycon.get_status()
    left_report = left_joycon.get_status()

    right_stick_horizontal = right_report['analog-sticks']['right']['horizontal']
    right_stick_vertical = right_report['analog-sticks']['right']['vertical']
    left_stick_horizontal = left_report['analog-sticks']['left']['horizontal']
    left_stick_vertical = left_report['analog-sticks']['left']['vertical']

    gamepad.left_joystick_float(x_value_float=left_stick_horizontal, y_value_float=left_stick_vertical)
    gamepad.right_joystick_float(x_value_float=right_stick_horizontal, y_value_float=right_stick_vertical)

My project is about mapping motions to buttons. So I can swing the joycons to activate buttons, like swinging the right joycon to press X and the left joycon to press B. I already succeeded in that part, for which vgamepad has been very useful. Now I just have to map all normal controller functions. Once I've implemented the joysticks and rumble, all the crucial functions are done.

yannbouteiller commented 1 year ago

One issue that you might have here is a busy loop issue. You want to ensure that your while loop doesn't go faster than the real X360 refresh rate (something like 120Hz or 250Hz, I don't remember).

The issue that you obviously have is that you don't call gamepad.update() in this loop.

nahlahman commented 1 year ago

Oh I left out the "time.sleep(0.005)" line at the end, which hopefully takes care of the loop not being too fast.

gamepad.update() is used for all the buttons and triggers, but indeed I think the joysticks are left out. I'll see if that helps!

Thank you for your help and for having created this tool. I'll figure it out eventually, probably with help from stackoverflow as you suggested.