Zuzu-Typ / XInput-Python

Simple access to the DirectX input API for Python
zlib License
28 stars 5 forks source link

Battery information error #4

Closed huntfx closed 3 years ago

huntfx commented 3 years ago

I was trying out the different functions available and came across this error:

>>> XInput.get_battery_information(XInput.get_state(0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "XInput.py", line 268, in get_battery_information
    XInputGetBatteryInformation(user_index, BATTERY_DEVTYPE_GAMEPAD, battery_information)
  File "XInput.py", line 144, in XInputGetBatteryInformation
    return libXInput.XInputGetBatteryInformation(dwUserIndex, devType, ctypes.byref(batteryInformation))
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

Also can I ask what you mean by "You shouldn't check this too frequently" in get_connected? Is it just due to it being slow?

Zuzu-Typ commented 3 years ago

Hi there Peter,

I'm afraid you passed the wrong argument. get_battery_information takes a user_index (i.e. the index of the controller), so the correct way to call it would be: XInput.get_battery_information(0)

About your question, I put that note there, because Microsoft recommends it.

For performance reasons, don't call XInputGetState for an 'empty' user slot every frame. We recommend that you space out checks for new controllers every few seconds instead. (Source)

Happy New Year! (:

huntfx commented 3 years ago

Ah sorry my bad haha, I didn't notice it had a different input since nearly all the functions require the state.

Thanks for clarifying the connected function too, perhaps it'd be worth adding "for performance reasons" to the docstring, with a suggestion to not call it more than every few seconds.

Happy new year too :)