Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuzu-Typ committed Jun 14, 2019
1 parent fc4c82c commit 46892c6
Show file tree
Hide file tree
Showing 6 changed files with 377 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

runreadmelang.bat
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
# XInput
# XInput
## A simple to use interface to the XInput API for Python\.
**XInput** provides a few simple methods that can be used to query controller information\.

## Tiny Documentation
### Using XInput
XInput provides a few functions:
`get_connected() -> (bool, bool, bool, bool)` Query which controllers are connected \(note: don't query each frame\)

`get_state(user_index) -> State` Get the State of the controller `user_index`

`get_button_values(state) -> dict` Returns a dictionary, showing which buttons are currently being pressed\.

`get_trigger_values(state) -> (LT, RT)` Returns a tuple with the values of the left and right triggers in range `0.0` to `1.0`

`get_thumb_values(state) -> ((LX, LY), (RX, RY))` Returns the values of the thumb sticks, expressed in X and Y ranging from `0.0` to `1.0`

`set_vibration(user_index, left_speed, right_speed) -> bool (Success)` Sets the vibration of the left and right motors of `user_index` to values between `0` and `65535` or in range `0.0` to `1.0` respectively\.

`get_battery_information(user_index) -> (<type>, <level>)` Returns the battery information for `user_index`
20 changes: 20 additions & 0 deletions README.rml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[title]XInput[/title]
[subtitle]A simple to use interface to the XInput API for Python.[/subtitle]
[b]XInput[/] provides a few simple methods that can be used to query controller information.

[s1]Tiny Documentation[/]
[s2]Using XInput[/]
XInput provides a few functions:
[code]get_connected() -> (bool, bool, bool, bool)[/code] Query which controllers are connected (note: don't query each frame)

[code]get_state(user_index) -> State[/code] Get the State of the controller [code]user_index[/code]

[code]get_button_values(state) -> dict[/code] Returns a dictionary, showing which buttons are currently being pressed.

[code]get_trigger_values(state) -> (LT, RT)[/code] Returns a tuple with the values of the left and right triggers in range [code]0.0[/] to [code]1.0[/]

[code]get_thumb_values(state) -> ((LX, LY), (RX, RY))[/code] Returns the values of the thumb sticks, expressed in X and Y ranging from [code]0.0[/] to [code]1.0[/]

[code]set_vibration(user_index, left_speed, right_speed) -> bool (Success)[/code] Sets the vibration of the left and right motors of [code]user_index[/] to values between [code]0[/] and [code]65535[/] or in range [code]0.0[/] to [code]1.0[/] respectively.

[code]get_battery_information(user_index) -> (<type>, <level>)[/] Returns the battery information for [code]user_index[/]
30 changes: 30 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

######
XInput
######

********************************************************
A simple to use interface to the XInput API for Python\.
********************************************************
| **XInput** provides a few simple methods that can be used to query controller information\.
|
Tiny Documentation
==================

Using XInput
------------
| XInput provides a few functions\:
| :code:`get_connected() -> (bool, bool, bool, bool)` Query which controllers are connected \(note\: don\'t query each frame\)
|
| :code:`get_state(user_index) -> State` Get the State of the controller :code:`user_index`
|
| :code:`get_button_values(state) -> dict` Returns a dictionary\, showing which buttons are currently being pressed\.
|
| :code:`get_trigger_values(state) -> (LT, RT)` Returns a tuple with the values of the left and right triggers in range :code:`0.0` to :code:`1.0`
|
| :code:`get_thumb_values(state) -> ((LX, LY), (RX, RY))` Returns the values of the thumb sticks\, expressed in X and Y ranging from :code:`0.0` to :code:`1.0`
|
| :code:`set_vibration(user_index, left_speed, right_speed) -> bool (Success)` Sets the vibration of the left and right motors of :code:`user_index` to values between :code:`0` and :code:`65535` or in range :code:`0.0` to :code:`1.0` respectively\.
|
| :code:`get_battery_information(user_index) -> (<type>, <level>)` Returns the battery information for :code:`user_index`
16 changes: 11 additions & 5 deletions XInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from math import sqrt

import glm

XINPUT_DLL_NAMES = (
"XInput1_4.dll",
"XInput9_1_0.dll",
Expand All @@ -19,7 +17,7 @@
for name in XINPUT_DLL_NAMES:
found = ctypes.util.find_library(name)
if found:
libXInput = ctypes.CDLL(found)
libXInput = ctypes.WinDLL(found)
break

if not libXInput:
Expand Down Expand Up @@ -108,6 +106,14 @@ def XInputGetBatteryInformation(dwUserIndex, devType, batteryInformation):
class XInputNotConnectedError(Exception):
pass

def get_connected():
state = XINPUT_STATE()
out = [False] * 4
for i in range(4):
out[i] = (XInputGetState(i, state) == 0)

return tuple(out)

def get_state(user_index):
state = XINPUT_STATE()
res = XInputGetState(user_index, state)
Expand Down Expand Up @@ -135,7 +141,7 @@ def set_vibration(user_index, left_speed, right_speed):
vibration.wLeftMotorSpeed = int(left_speed)
vibration.wRightMotorSpeed = int(right_speed)

return XInputSetState(user_index, vibration)
return XInputSetState(user_index, vibration) == 0

def get_button_values(state):
wButtons = state.Gamepad.wButtons
Expand Down Expand Up @@ -211,5 +217,5 @@ def get_thumb_values(state):
else:
magR = 0

return (glm.vec2(normLX, normLY) * normMagL, glm.vec2(normRX, normRY) * normMagR)
return ((normLX * normMagL, normLY * normMagL), (normRX * normMagR, normRY * normMagR))

Loading

0 comments on commit 46892c6

Please sign in to comment.