SDL2 playstation joystick driver for python
Project description
clamps
Note: I only have playstations, so I don't know if this will work with other joysticks.
This is actually something I did long ago, but finally decided to make it a module available on PyPi.
Setup
This requires sdl2
inorder to work:
brew install sdl2 # macos
apt install libsdl2-dev # linux
This package will install the python bindings PySDL2
from pypi.
Tested:
- Works with joystick connected via USB cable
- Works with joystick connected via bluetooth
- Works with PS4 controller
- Works with PS5 controller
Example
So really, there is no difference between PS4Joystick
amd PS5Joystick
,
but both classes exist. Originally I hoped there would be a difference,
like access to the gyros and accelerometers, but there isn't.
#!/usr/bin/env python3
import time
from clamps import PS4Joystick
def main():
import time
js = PS4Joystick() # or PS5Joystick()
while js.valid:
try:
ps4 = js.get()
print(ps4,"\n----------------------\n")
time.sleep(0.1)
if ps4.buttons.pad is True:
break
except KeyboardInterrupt:
print('js exiting ...')
break
if __name__ == "__main__":
main()
Output of get()
is a namedtuple
with the following fields:
JS(info=JSInfo(num_buttons=16, num_axes=6, num_hats=0), leftstick=Axis(x=-0.003936767578125, y=0.011749267578125), rightstick=Axis(x=-0.01177978515625, y=-0.050994873046875), triggers=Axis(x=0.0, y=0.0), buttons=PS4Buttons(x=False, circle=False, square=False, triangle=False, share=False, ps=False, options=False, L3=False, R3=False, L1=False, R1=False, dp_up=False, dp_down=False, dp_left=False, dp_right=False, pad=True))
How to pair a DUALSHOCK 4 wireless controller with a supported device
To pair your wireless controller with a supported device using Bluetooth for the first time, turn on pairing mode.
- Make sure the player indicator on the controller is off. If the player indicator is on, press and hold the PS button until it turns off. If a USB is connected to the controller, disconnect it.
- While pressing and holding the SHARE button, press and hold the PS Button until the light bar flashes.
- Enable Bluetooth on your device, and then select the controller from the list of Bluetooth devices. When pairing is complete, the light bar blinks, and then the player indicator lights up.
MIT License
Copyright (c) 2014 Kevin Walchko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file clamps-0.1.3.tar.gz
.
File metadata
- Download URL: clamps-0.1.3.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.0 CPython/3.10.6 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b891322b520c217917b1524c6cc96bb61750e41c3b374b354849feb4040fd7b |
|
MD5 | 037de2f036bb87e06f9915dac8755cc6 |
|
BLAKE2b-256 | 389e43b9776bd29937ad3bfed4189dcace10ce4584e3783f7fd702918e87fe7a |
File details
Details for the file clamps-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: clamps-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.0 CPython/3.10.6 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f70bf5e86f37c2b260140c71b9b843ece8129ad26ee64d628336f5dd7fb28c4 |
|
MD5 | 576c428125d9153102588ce4a2d62c66 |
|
BLAKE2b-256 | 4a16c6b3e8803aedb2bdb248f7282927fe29eb9607b4dd7c6e9e082e79d529b4 |