Compare commits
86 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
b67bcb2b9d | ||
|
546a00c9b4 | ||
|
c0797ced0b | ||
|
bb3ab10b91 | ||
|
875b5f66f8 | ||
|
aebe1e581e | ||
|
de894fca7e | ||
|
1b06033d4c | ||
|
4105048784 | ||
|
e2c16cd29e | ||
|
3b3ec445ad | ||
|
dc14382b62 | ||
|
bda77189f7 | ||
|
d34302b494 | ||
|
a808741b7f | ||
|
6f7413ecad | ||
|
7c79dc5fbf | ||
|
98271e866f | ||
|
caa2062cea | ||
|
9359e6eac4 | ||
|
c54f58bcee | ||
|
d19bfc6507 | ||
|
2a448890ff | ||
|
5404852ec4 | ||
|
12b5743895 | ||
|
ab3f786013 | ||
|
e8cb5de594 | ||
|
79bf833c9a | ||
|
e1907e7a6f | ||
|
60aa11b496 | ||
|
330d117340 | ||
|
9d8ab950de | ||
|
40f74472d7 | ||
|
b091660130 | ||
|
82d407bfe2 | ||
|
0f279f1ee8 | ||
|
624d17c919 | ||
|
24c628a182 | ||
|
36e8886754 | ||
|
28605e0023 | ||
|
f5529f1463 | ||
|
b3ff9fd375 | ||
|
98b13798cd | ||
|
b51c8b49f6 | ||
|
cdbe03ad56 | ||
|
3a14ab3e7a | ||
|
32f9042abb | ||
|
4c86d71633 | ||
|
9c79d961f1 | ||
|
c1c10e4eac | ||
|
04ce807bc0 | ||
|
71a49da5d2 | ||
|
f4e1d73dd3 | ||
|
e766dca70f | ||
|
1e0b23da41 | ||
|
ff01788c89 | ||
|
c07b975bc5 | ||
|
7b0270fa7d | ||
|
d76717c163 | ||
|
786657cc90 | ||
|
11e78fbece | ||
|
a3f697866b | ||
|
1530c79dd7 | ||
|
83a37750d1 | ||
|
bc0eb35c3c | ||
|
93b5e38e6e | ||
|
94cb09dbdd | ||
|
8fb31f86ba | ||
|
e04766d48d | ||
|
c39f3f2ea5 | ||
|
ea319db5a3 | ||
|
d62e8d133e | ||
|
fe435f6e36 | ||
|
cc767d5fcd | ||
|
1ab69d6c96 | ||
|
b004d2bc7b | ||
|
3f16538555 | ||
|
f1be774e68 | ||
|
9560d8e637 | ||
|
ecb42d9c0a | ||
|
604c5f2800 | ||
|
a54fb55b91 | ||
|
0bf55f756b | ||
|
2a5afd7cb0 | ||
|
0a6fee2f85 | ||
|
2f5579cc49 |
22
.github/workflows/docs_publish.yml
vendored
Normal file
22
.github/workflows/docs_publish.yml
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
name: publish_docs
|
||||
on: [push, workflow_dispatch]
|
||||
jobs:
|
||||
docs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-python@v2
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
pip install sphinx furo
|
||||
- name: Sphinx build
|
||||
run: |
|
||||
sphinx-build docs/source docs/build
|
||||
- name: Deploy
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
|
||||
with:
|
||||
publish_branch: gh-pages
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: docs/build/
|
||||
force_orphan: true
|
3
.gitignore
vendored
3
.gitignore
vendored
@@ -149,6 +149,9 @@ dmypy.json
|
||||
!.vscode/extensions.json
|
||||
*.code-workspace
|
||||
|
||||
### pycharm ###
|
||||
.idea/*
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/python,vscode
|
||||
|
||||
pydualsense/interface.py
|
||||
|
11
70-ps5-controller.rules
Normal file
11
70-ps5-controller.rules
Normal file
@@ -0,0 +1,11 @@
|
||||
# ref.: https://boilingsteam.com/the-dualsense-is-making-even-more-sense/
|
||||
# copy this file to /etc/udev/rules.d
|
||||
# reload udev rules with:
|
||||
# udevadm control --reload-rules
|
||||
# udevadm trigger
|
||||
|
||||
# PS5 DualSense controller over USB hidraw
|
||||
KERNEL=="hidraw*", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="0ce6", MODE="0660", TAG+="uaccess"
|
||||
|
||||
# PS5 DualSense controller over bluetooth hidraw
|
||||
KERNEL=="hidraw*", KERNELS=="*054C:0CE6*", MODE="0660", TAG+="uaccess"
|
76
README.md
76
README.md
@@ -1,29 +1,83 @@
|
||||
# pydualsense
|
||||
control your dualsense through python. using the hid library this module implements the sending report for controlling you new PS5 controller. It creates a background thread to constantly update the controller.
|
||||
control your dualsense through python. using the hid library this package implements the report features for controlling your PS5 controller.
|
||||
|
||||
# install
|
||||
# Documentation
|
||||
|
||||
Just install the package from pypi
|
||||
You can find the documentation at [docs](https://flok.github.io/pydualsense/)
|
||||
|
||||
# Installation
|
||||
|
||||
|
||||
## Windows
|
||||
Download [hidapi](https://github.com/libusb/hidapi/releases) and place the x64 .dll file into your Workspace. After that install the package from [pypi](https://pypi.org/project/pydualsense/).
|
||||
|
||||
```bash
|
||||
pip install pydualsense
|
||||
pip install --upgrade pydualsense
|
||||
```
|
||||
|
||||
## Linux
|
||||
|
||||
On Linux based system you first need to add a udev rule to let the user access the PS5 controller without requiring root privileges.
|
||||
|
||||
```bash
|
||||
sudo cp 70-ps5-controller.rules /etc/udev/rules.d
|
||||
sudo udevadm control --reload-rules
|
||||
sudo udevadm trigger
|
||||
```
|
||||
|
||||
Then install the hidapi through your package manager of your system.
|
||||
|
||||
On an Ubuntu system the package ```libhidapi-dev``` is required.
|
||||
|
||||
```bash
|
||||
sudo apt install libhidapi-dev
|
||||
```
|
||||
|
||||
After that install the package from [pypi](https://pypi.org/project/pydualsense/).
|
||||
|
||||
```bash
|
||||
pip install --upgrade pydualsense
|
||||
```
|
||||
|
||||
# usage
|
||||
|
||||
```python
|
||||
|
||||
from pydualsense import pydualsense
|
||||
from pydualsense import pydualsense, TriggerModes
|
||||
|
||||
def cross_pressed(state):
|
||||
print(state)
|
||||
|
||||
ds = pydualsense() # open controller
|
||||
ds.setColor(255,0,0) # set touchpad color to red
|
||||
ds.setLeftTriggerMode(TriggerModes.Rigid)
|
||||
ds.setLeftTriggerForce(1, 255)
|
||||
ds.init() # initialize controller
|
||||
|
||||
ds.cross_pressed += cross_pressed
|
||||
ds.light.setColorI(255,0,0) # set touchpad color to red
|
||||
ds.triggerL.setMode(TriggerModes.Rigid)
|
||||
ds.triggerL.setForce(1, 255)
|
||||
ds.close() # closing the controller
|
||||
```
|
||||
|
||||
See [examples](https://github.com/flok/pydualsense/tree/master/examples) or [examples docs](https://flok.github.io/pydualsense/examples.html) folder for some more ideas
|
||||
|
||||
# Help wanted
|
||||
|
||||
Help wanted from people that want to use this and have feature requests. Just open a issue with the correct label.
|
||||
|
||||
# dependecies
|
||||
|
||||
- hid >= 1.0.4
|
||||
- hidapi-usb >= 0.3
|
||||
|
||||
# Credits
|
||||
|
||||
|
||||
Most stuff for this implementation were provided by and used from:
|
||||
|
||||
|
||||
- [https://www.reddit.com/r/gamedev/comments/jumvi5/dualsense_haptics_leds_and_more_hid_output_report/](https://www.reddit.com/r/gamedev/comments/jumvi5/dualsense_haptics_leds_and_more_hid_output_report/)
|
||||
- [https://github.com/Ryochan7/DS4Windows](https://github.com/Ryochan7/DS4Windows)
|
||||
|
||||
# Coming soon
|
||||
|
||||
- reading the states of the controller to enable a fully compatibility with python - partially done
|
||||
- add documentation using sphinx
|
||||
- add multiple controllers
|
||||
- add documentation using sphinx
|
||||
|
0
docs/.nojekyll
Normal file
0
docs/.nojekyll
Normal file
23
docs/Makefile
Normal file
23
docs/Makefile
Normal file
@@ -0,0 +1,23 @@
|
||||
# Minimal makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line, and also
|
||||
# from the environment for the first two.
|
||||
SPHINXOPTS ?=
|
||||
SPHINXBUILD ?= sphinx-build
|
||||
SOURCEDIR = source
|
||||
BUILDDIR = build
|
||||
|
||||
# Put it first so that "make" without argument is like "make help".
|
||||
help:
|
||||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
.PHONY: help Makefile
|
||||
|
||||
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||
%: Makefile
|
||||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
generate_doc:
|
||||
sphinx-apidoc ../pydualsense -f -o ./source --ext-autodoc --ext-coverage --ext-todo
|
10
docs/source/api.rst
Normal file
10
docs/source/api.rst
Normal file
@@ -0,0 +1,10 @@
|
||||
API
|
||||
===
|
||||
|
||||
This is the front page for the API documentation of the **pydualsense** library.
|
||||
|
||||
|
||||
.. toctree::
|
||||
ds_enum
|
||||
ds_main
|
||||
ds_eventsystem
|
43
docs/source/conf.py
Normal file
43
docs/source/conf.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import sys
|
||||
import os
|
||||
# Configuration file for the Sphinx documentation builder.
|
||||
#
|
||||
# For the full list of built-in configuration values, see the documentation:
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
||||
|
||||
project = 'pydualsense'
|
||||
copyright = '2022, Florian (flok) K'
|
||||
author = 'Florian (flok) K'
|
||||
release = '0.6.1'
|
||||
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
sys.path.insert(0, os.path.abspath('../../'))
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
||||
|
||||
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.napoleon', 'sphinx.ext.coverage', 'sphinx.ext.todo']
|
||||
|
||||
templates_path = ['templates']
|
||||
exclude_patterns = []
|
||||
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
||||
|
||||
html_theme = 'furo'
|
||||
html_static_path = ['static']
|
||||
|
||||
autodoc_default_options = {
|
||||
'members': True,
|
||||
'member-order': 'bysource',
|
||||
'special-members': '__init__',
|
||||
'undoc-members': True,
|
||||
'exclude-members': '__weakref__'
|
||||
}
|
||||
|
||||
autoclass_content = 'both'
|
||||
todo_include_todos = True
|
||||
|
11
docs/source/ds_enum.rst
Normal file
11
docs/source/ds_enum.rst
Normal file
@@ -0,0 +1,11 @@
|
||||
pydualsense enums classes
|
||||
=========================
|
||||
|
||||
The enum module provides the used `enums` by **pydualsense**. These `enums` are used to update the state of the controller as a parameter to call the used functions.
|
||||
|
||||
|
||||
.. automodule:: pydualsense.enums
|
||||
:noindex:
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
10
docs/source/ds_eventsystem.rst
Normal file
10
docs/source/ds_eventsystem.rst
Normal file
@@ -0,0 +1,10 @@
|
||||
pydualsense event system classes
|
||||
=========================
|
||||
|
||||
The `Event System` implements the event system used for the button callbacks
|
||||
|
||||
.. automodule:: pydualsense.event_system
|
||||
:noindex:
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
11
docs/source/ds_main.rst
Normal file
11
docs/source/ds_main.rst
Normal file
@@ -0,0 +1,11 @@
|
||||
pydualsense main class
|
||||
======================
|
||||
|
||||
`pydualsense` is the main class of the library with the same name. It provides access to the states of the controller through manual reading of the :class:`DSState <pydualsense.pydualsense.DSState>`
|
||||
|
||||
|
||||
.. automodule:: pydualsense.pydualsense
|
||||
:noindex:
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
82
docs/source/examples.rst
Normal file
82
docs/source/examples.rst
Normal file
@@ -0,0 +1,82 @@
|
||||
Examples
|
||||
========
|
||||
|
||||
This pages displays some examples that on how the library can be used. All the examples can also be found inside the `examples` folder on the github repository.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pydualsense import *
|
||||
|
||||
def cross_down(state):
|
||||
print(f'cross {state}')
|
||||
|
||||
|
||||
def circle_down(state):
|
||||
print(f'circle {state}')
|
||||
|
||||
|
||||
def dpad_down(state):
|
||||
print(f'dpad down {state}')
|
||||
|
||||
|
||||
def joystick(stateX, stateY):
|
||||
print(f'joystick {stateX} {stateY}')
|
||||
|
||||
|
||||
def gyro_changed(pitch, yaw, roll):
|
||||
print(f'{pitch}, {yaw}, {roll}')
|
||||
|
||||
# create dualsense
|
||||
dualsense = pydualsense()
|
||||
# find device and initialize
|
||||
dualsense.init()
|
||||
|
||||
# add events handler functions
|
||||
dualsense.cross_pressed += cross_down
|
||||
dualsense.circle_pressed += circle_down
|
||||
dualsense.dpad_down += dpad_down
|
||||
dualsense.left_joystick_changed += joystick
|
||||
dualsense.gyro_changed += gyro_changed
|
||||
|
||||
# read controller state until R1 is pressed
|
||||
while not dualsense.state.R1:
|
||||
...
|
||||
|
||||
# close device
|
||||
dualsense.close()
|
||||
|
||||
|
||||
The above example demonstrates the newly added c# like event system that makes it possible to trigger an event for the inputs of the controller.
|
||||
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pydualsense import *
|
||||
|
||||
# get dualsense instance
|
||||
dualsense = pydualsense()
|
||||
# initialize controller and connect
|
||||
dualsense.init()
|
||||
|
||||
print('Trigger Effect demo started')
|
||||
|
||||
# set left and right rumble motors
|
||||
dualsense.setLeftMotor(255)
|
||||
dualsense.setRightMotor(100)
|
||||
|
||||
# set left l2 trigger to Rigid and set index 1 to force 255
|
||||
dualsense.triggerL.setMode(TriggerModes.Rigid)
|
||||
dualsense.triggerL.setForce(1, 255)
|
||||
|
||||
# set left r2 trigger to Rigid
|
||||
dualsense.triggerR.setMode(TriggerModes.Pulse_A)
|
||||
dualsense.triggerR.setForce(0, 200)
|
||||
dualsense.triggerR.setForce(1, 255)
|
||||
dualsense.triggerR.setForce(2, 175)
|
||||
|
||||
# loop until r1 is pressed to feel effect
|
||||
while not dualsense.state.R1:
|
||||
...
|
||||
|
||||
# terminate the thread for message and close the device
|
||||
dualsense.close()
|
26
docs/source/index.rst
Normal file
26
docs/source/index.rst
Normal file
@@ -0,0 +1,26 @@
|
||||
Welcome to pydualsense's documentation!
|
||||
=======================================
|
||||
|
||||
|
||||
**pydualsense** is a Python library that helps you interact with your PlayStation 5 DualSense controller. It reads the current state of the controller and also allows to update the triggers and other options on the controller.
|
||||
|
||||
To get started check out the :doc:`usage` section for more information on how to install.
|
||||
|
||||
|
||||
.. note::
|
||||
This project is under active development.
|
||||
|
||||
Contents
|
||||
--------
|
||||
|
||||
.. toctree::
|
||||
usage
|
||||
api
|
||||
examples
|
||||
modules
|
||||
|
||||
|
||||
TODOs
|
||||
-----
|
||||
|
||||
.. todolist::
|
7
docs/source/modules.rst
Normal file
7
docs/source/modules.rst
Normal file
@@ -0,0 +1,7 @@
|
||||
pydualsense
|
||||
===========
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 4
|
||||
|
||||
pydualsense
|
45
docs/source/pydualsense.rst
Normal file
45
docs/source/pydualsense.rst
Normal file
@@ -0,0 +1,45 @@
|
||||
pydualsense package
|
||||
===================
|
||||
|
||||
Submodules
|
||||
----------
|
||||
|
||||
pydualsense.enums module
|
||||
------------------------
|
||||
|
||||
.. automodule:: pydualsense.enums
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
pydualsense.event\_system module
|
||||
--------------------------------
|
||||
|
||||
.. automodule:: pydualsense.event_system
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
pydualsense.hidguardian module
|
||||
------------------------------
|
||||
|
||||
.. automodule:: pydualsense.hidguardian
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
pydualsense.pydualsense module
|
||||
------------------------------
|
||||
|
||||
.. automodule:: pydualsense.pydualsense
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
Module contents
|
||||
---------------
|
||||
|
||||
.. automodule:: pydualsense
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
38
docs/source/usage.rst
Normal file
38
docs/source/usage.rst
Normal file
@@ -0,0 +1,38 @@
|
||||
Usage
|
||||
=====
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
To use **pydualsense**, first install it using pip:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
(.venv) $ pip install --upgrade pydualsense
|
||||
|
||||
This install the needed dependencies and the **pydualsense** library itself.
|
||||
|
||||
|
||||
Windows
|
||||
-------
|
||||
|
||||
If you are on Windows the hidapi need to downloaded from `here <https://github.com/libusb/hidapi/releases>`_.
|
||||
The downloaded `.dll` file need to be placed in a path that is in your environments variable `path`.
|
||||
|
||||
|
||||
Linux based
|
||||
-----------
|
||||
|
||||
If you are on a linux based system (e.g debian) you need to first need to install the hidapi through your package manager.
|
||||
|
||||
On Ubuntu systems the package `libhidapi-dev` is required.
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
sudo apt install libhidapi-dev
|
||||
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
For code examles on using the library see :doc:`examples`
|
15
examples/README.md
Normal file
15
examples/README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Examples
|
||||
|
||||
This folder contains some examples on applications for the library and its usage
|
||||
|
||||
## leds.py
|
||||
|
||||
The leds.py shows you how you can interact and change the lights of the controller
|
||||
|
||||
## effects.py
|
||||
|
||||
The effects.py show some effects of the controller
|
||||
|
||||
## read_controller.py
|
||||
|
||||
The read_controller.py display how you can access the button state of the controller
|
23
examples/effects.py
Normal file
23
examples/effects.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from pydualsense import *
|
||||
|
||||
# get dualsense instance
|
||||
dualsense = pydualsense()
|
||||
dualsense.init()
|
||||
|
||||
print('Trigger Effect demo started')
|
||||
|
||||
dualsense.setLeftMotor(255)
|
||||
dualsense.setRightMotor(100)
|
||||
dualsense.triggerL.setMode(TriggerModes.Rigid)
|
||||
dualsense.triggerL.setForce(1, 255)
|
||||
|
||||
dualsense.triggerR.setMode(TriggerModes.Pulse_A)
|
||||
dualsense.triggerR.setForce(0, 200)
|
||||
dualsense.triggerR.setForce(1, 255)
|
||||
dualsense.triggerR.setForce(2, 175)
|
||||
|
||||
# loop until r1 is pressed to feel effect
|
||||
while not dualsense.state.R1:
|
||||
...
|
||||
# terminate the thread for message and close the device
|
||||
dualsense.close()
|
16
examples/leds.py
Normal file
16
examples/leds.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from pydualsense import *
|
||||
|
||||
# get dualsense instance
|
||||
dualsense = pydualsense()
|
||||
dualsense.init()
|
||||
# set color around touchpad to red
|
||||
dualsense.light.setColorI(255,0,0)
|
||||
# mute microphone
|
||||
dualsense.audio.setMicrophoneState(True)
|
||||
# set all player 1 indicator on
|
||||
dualsense.light.setPlayerID(PlayerID.PLAYER_1)
|
||||
# sleep a little to see the result on the controller
|
||||
# this is not needed in normal usage
|
||||
import time; time.sleep(2)
|
||||
# terminate the thread for message and close the device
|
||||
dualsense.close()
|
54
examples/read_all_input_channels.py
Normal file
54
examples/read_all_input_channels.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import curses
|
||||
import time
|
||||
from pydualsense import *
|
||||
|
||||
|
||||
def print_states(stdscr):
|
||||
curses.curs_set(0)
|
||||
curses.use_default_colors()
|
||||
stdscr.nodelay(1)
|
||||
while True:
|
||||
stdscr.erase()
|
||||
pretty_states = [f"{state:03}" for state in dualsense.states]
|
||||
|
||||
stdscr.addstr(f"epoch: {time.time():.2f}\n")
|
||||
stdscr.addstr(f"states[0:10]: {pretty_states[0:10]}\n")
|
||||
stdscr.addstr(f"states[10:20]: {pretty_states[10:20]}\n")
|
||||
stdscr.addstr(f"states[20:30]: {pretty_states[20:30]}\n")
|
||||
stdscr.addstr(f"states[30:40]: {pretty_states[30:40]}\n")
|
||||
stdscr.addstr(f"states[40:50]: {pretty_states[40:50]}\n")
|
||||
stdscr.addstr(f"states[50:60]: {pretty_states[50:60]}\n")
|
||||
stdscr.addstr(f"states[60:70]: {pretty_states[60:70]}\n")
|
||||
stdscr.addstr(f"states[70:78]: {pretty_states[70:78]}\n")
|
||||
stdscr.addstr("\n")
|
||||
stdscr.addstr(f"square: {dualsense.state.square!s:>5} \t triangle: {dualsense.state.triangle!s:>5} \t circle: {dualsense.state.circle!s:>5} \t cross: {dualsense.state.cross!s:>5}\n")
|
||||
stdscr.addstr(f"DpadUp: {dualsense.state.DpadUp!s:>5} \t DpadDown: {dualsense.state.DpadDown!s:>5} \t DpadLeft: {dualsense.state.DpadLeft!s:>5} \t DpadRight: {dualsense.state.DpadRight!s:>5}\n")
|
||||
stdscr.addstr(f"L1: {dualsense.state.L1!s:>5} \t L2: {dualsense.state.L2:3} \t L2Btn: {dualsense.state.L2Btn!s:>5} \t L3: {dualsense.state.L3!s:>5} \t R1: {dualsense.state.R1!s:>5} \t R2: {dualsense.state.R2:3d} \t R2Btn: {dualsense.state.R2Btn!s:>5} \t R3: {dualsense.state.R3!s:>5}\n")
|
||||
stdscr.addstr(f"share: {dualsense.state.share!s:>5} \t options: {dualsense.state.options!s:>5} \t ps: {dualsense.state.ps!s:>5} \t touch1: {dualsense.state.touch1!s:>5} \t touch2: {dualsense.state.touch2!s:>5} \t touchBtn: {dualsense.state.touchBtn!s:>5} \t touchRight: {dualsense.state.touchRight!s:>5} \t touchLeft: {dualsense.state.touchLeft!s:>5}\n")
|
||||
stdscr.addstr(f"touchFinger1: {dualsense.state.touchFinger1} \t touchFinger2: {dualsense.state.touchFinger2}\n")
|
||||
stdscr.addstr(f"micBtn: {dualsense.state.micBtn!s:>5}\n")
|
||||
stdscr.addstr(f"RX: {dualsense.state.RX:4} \t RY: {dualsense.state.RY:4} \t LX: {dualsense.state.LX:4} \t LY: {dualsense.state.LY:4}\n")
|
||||
stdscr.addstr(f"trackPadTouch0: ID: {dualsense.state.trackPadTouch0.ID} \t isActive: {dualsense.state.trackPadTouch0.isActive!s:>5} \t X: {dualsense.state.trackPadTouch0.X:4d} \t Y: {dualsense.state.trackPadTouch0.Y:4d}\n")
|
||||
stdscr.addstr(f"trackPadTouch1: ID: {dualsense.state.trackPadTouch1.ID} \t isActive: {dualsense.state.trackPadTouch1.isActive!s:>5} \t X: {dualsense.state.trackPadTouch1.X:4d} \t Y: {dualsense.state.trackPadTouch1.Y:4d}\n")
|
||||
stdscr.addstr(f"gyro: roll: {dualsense.state.gyro.Roll:6} \t pitch: {dualsense.state.gyro.Pitch:6} \t yaw: {dualsense.state.gyro.Yaw:6}\n")
|
||||
stdscr.addstr(f"acc: X: {dualsense.state.accelerometer.X:6} \t Y: {dualsense.state.accelerometer.Y:6} \t Z: {dualsense.state.accelerometer.Z:6}\n")
|
||||
stdscr.addstr(f"battery : Level: {dualsense.battery.Level:6} \t State : {dualsense.battery.State}")
|
||||
stdscr.addstr("\n")
|
||||
stdscr.addstr("Exit script with 'q'\n")
|
||||
|
||||
stdscr.refresh()
|
||||
if stdscr.getch() == ord('q'):
|
||||
break
|
||||
|
||||
|
||||
dualsense = pydualsense()
|
||||
dualsense.init()
|
||||
|
||||
while dualsense.states is None:
|
||||
print("Waiting until connection is established...")
|
||||
print(f"epoch: {time.time():.0f}")
|
||||
time.sleep(0.5)
|
||||
|
||||
|
||||
curses.wrapper(print_states)
|
||||
dualsense.close()
|
41
examples/read_controller.py
Normal file
41
examples/read_controller.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from pydualsense import *
|
||||
|
||||
|
||||
def cross_down(state):
|
||||
print(f'cross {state}')
|
||||
|
||||
|
||||
def circle_down(state):
|
||||
print(f'circle {state}')
|
||||
|
||||
|
||||
def dpad_down(state):
|
||||
print(f'dpad {state}')
|
||||
|
||||
|
||||
def joystick(stateX, stateY):
|
||||
print(f'lj {stateX} {stateY}')
|
||||
|
||||
|
||||
def gyro_changed(pitch, yaw, roll):
|
||||
print(f'{pitch}, {yaw}, {roll}')
|
||||
|
||||
|
||||
# create dualsense
|
||||
dualsense = pydualsense()
|
||||
# find device and initialize
|
||||
dualsense.init()
|
||||
|
||||
# add events handler functions
|
||||
dualsense.cross_pressed += cross_down
|
||||
dualsense.circle_pressed += circle_down
|
||||
dualsense.dpad_down += dpad_down
|
||||
dualsense.left_joystick_changed += joystick
|
||||
dualsense.gyro_changed += gyro_changed
|
||||
|
||||
# read controller state until R1 is pressed
|
||||
while not dualsense.state.R1:
|
||||
...
|
||||
|
||||
# close device
|
||||
dualsense.close()
|
@@ -1,2 +1,3 @@
|
||||
from .enums import LedOptions,Brightness,PlayerID,PulseOptions,TriggerModes
|
||||
from .pydualsense import pydualsense, DSAudio, DSLight, DSTrigger
|
||||
from .enums import LedOptions, Brightness, PlayerID, PulseOptions, TriggerModes
|
||||
from .event_system import Event
|
||||
from .pydualsense import pydualsense, DSLight, DSState, DSTouchpad, DSTrigger, DSAudio
|
||||
|
47
pydualsense/checksum.py
Normal file
47
pydualsense/checksum.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import array
|
||||
|
||||
# from South-River
|
||||
|
||||
hashTable = array.array('I', [
|
||||
0xd202ef8d, 0xa505df1b, 0x3c0c8ea1, 0x4b0bbe37, 0xd56f2b94, 0xa2681b02, 0x3b614ab8, 0x4c667a2e,
|
||||
0xdcd967bf, 0xabde5729, 0x32d70693, 0x45d03605, 0xdbb4a3a6, 0xacb39330, 0x35bac28a, 0x42bdf21c,
|
||||
0xcfb5ffe9, 0xb8b2cf7f, 0x21bb9ec5, 0x56bcae53, 0xc8d83bf0, 0xbfdf0b66, 0x26d65adc, 0x51d16a4a,
|
||||
0xc16e77db, 0xb669474d, 0x2f6016f7, 0x58672661, 0xc603b3c2, 0xb1048354, 0x280dd2ee, 0x5f0ae278,
|
||||
0xe96ccf45, 0x9e6bffd3, 0x762ae69, 0x70659eff, 0xee010b5c, 0x99063bca, 0xf6a70, 0x77085ae6,
|
||||
0xe7b74777, 0x90b077e1, 0x9b9265b, 0x7ebe16cd, 0xe0da836e, 0x97ddb3f8, 0xed4e242, 0x79d3d2d4,
|
||||
0xf4dbdf21, 0x83dcefb7, 0x1ad5be0d, 0x6dd28e9b, 0xf3b61b38, 0x84b12bae, 0x1db87a14, 0x6abf4a82,
|
||||
0xfa005713, 0x8d076785, 0x140e363f, 0x630906a9, 0xfd6d930a, 0x8a6aa39c, 0x1363f226, 0x6464c2b0,
|
||||
0xa4deae1d, 0xd3d99e8b, 0x4ad0cf31, 0x3dd7ffa7, 0xa3b36a04, 0xd4b45a92, 0x4dbd0b28, 0x3aba3bbe,
|
||||
0xaa05262f, 0xdd0216b9, 0x440b4703, 0x330c7795, 0xad68e236, 0xda6fd2a0, 0x4366831a, 0x3461b38c,
|
||||
0xb969be79, 0xce6e8eef, 0x5767df55, 0x2060efc3, 0xbe047a60, 0xc9034af6, 0x500a1b4c, 0x270d2bda,
|
||||
0xb7b2364b, 0xc0b506dd, 0x59bc5767, 0x2ebb67f1, 0xb0dff252, 0xc7d8c2c4, 0x5ed1937e, 0x29d6a3e8,
|
||||
0x9fb08ed5, 0xe8b7be43, 0x71beeff9, 0x6b9df6f, 0x98dd4acc, 0xefda7a5a, 0x76d32be0, 0x1d41b76,
|
||||
0x916b06e7, 0xe66c3671, 0x7f6567cb, 0x862575d, 0x9606c2fe, 0xe101f268, 0x7808a3d2, 0xf0f9344,
|
||||
0x82079eb1, 0xf500ae27, 0x6c09ff9d, 0x1b0ecf0b, 0x856a5aa8, 0xf26d6a3e, 0x6b643b84, 0x1c630b12,
|
||||
0x8cdc1683, 0xfbdb2615, 0x62d277af, 0x15d54739, 0x8bb1d29a, 0xfcb6e20c, 0x65bfb3b6, 0x12b88320,
|
||||
0x3fba6cad, 0x48bd5c3b, 0xd1b40d81, 0xa6b33d17, 0x38d7a8b4, 0x4fd09822, 0xd6d9c998, 0xa1def90e,
|
||||
0x3161e49f, 0x4666d409, 0xdf6f85b3, 0xa868b525, 0x360c2086, 0x410b1010, 0xd80241aa, 0xaf05713c,
|
||||
0x220d7cc9, 0x550a4c5f, 0xcc031de5, 0xbb042d73, 0x2560b8d0, 0x52678846, 0xcb6ed9fc, 0xbc69e96a,
|
||||
0x2cd6f4fb, 0x5bd1c46d, 0xc2d895d7, 0xb5dfa541, 0x2bbb30e2, 0x5cbc0074, 0xc5b551ce, 0xb2b26158,
|
||||
0x4d44c65, 0x73d37cf3, 0xeada2d49, 0x9ddd1ddf, 0x3b9887c, 0x74beb8ea, 0xedb7e950, 0x9ab0d9c6,
|
||||
0xa0fc457, 0x7d08f4c1, 0xe401a57b, 0x930695ed, 0xd62004e, 0x7a6530d8, 0xe36c6162, 0x946b51f4,
|
||||
0x19635c01, 0x6e646c97, 0xf76d3d2d, 0x806a0dbb, 0x1e0e9818, 0x6909a88e, 0xf000f934, 0x8707c9a2,
|
||||
0x17b8d433, 0x60bfe4a5, 0xf9b6b51f, 0x8eb18589, 0x10d5102a, 0x67d220bc, 0xfedb7106, 0x89dc4190,
|
||||
0x49662d3d, 0x3e611dab, 0xa7684c11, 0xd06f7c87, 0x4e0be924, 0x390cd9b2, 0xa0058808, 0xd702b89e,
|
||||
0x47bda50f, 0x30ba9599, 0xa9b3c423, 0xdeb4f4b5, 0x40d06116, 0x37d75180, 0xaede003a, 0xd9d930ac,
|
||||
0x54d13d59, 0x23d60dcf, 0xbadf5c75, 0xcdd86ce3, 0x53bcf940, 0x24bbc9d6, 0xbdb2986c, 0xcab5a8fa,
|
||||
0x5a0ab56b, 0x2d0d85fd, 0xb404d447, 0xc303e4d1, 0x5d677172, 0x2a6041e4, 0xb369105e, 0xc46e20c8,
|
||||
0x72080df5, 0x50f3d63, 0x9c066cd9, 0xeb015c4f, 0x7565c9ec, 0x262f97a, 0x9b6ba8c0, 0xec6c9856,
|
||||
0x7cd385c7, 0xbd4b551, 0x92dde4eb, 0xe5dad47d, 0x7bbe41de, 0xcb97148, 0x95b020f2, 0xe2b71064,
|
||||
0x6fbf1d91, 0x18b82d07, 0x81b17cbd, 0xf6b64c2b, 0x68d2d988, 0x1fd5e91e, 0x86dcb8a4, 0xf1db8832,
|
||||
0x616495a3, 0x1663a535, 0x8f6af48f, 0xf86dc419, 0x660951ba, 0x110e612c, 0x88073096, 0xff000000
|
||||
])
|
||||
|
||||
|
||||
def compute(buffer):
|
||||
result = 0xeada2d49
|
||||
|
||||
for i in range(0, 74):
|
||||
result = hashTable[(result&0xFF)^(buffer[i]&0xFF)]^(result>>8)
|
||||
|
||||
return result
|
@@ -1,38 +1,56 @@
|
||||
from enum import IntFlag
|
||||
|
||||
class LedOptions(IntFlag):
|
||||
Off=0x0,
|
||||
PlayerLedBrightness=0x1,
|
||||
UninterrumpableLed=0x2,
|
||||
Both=0x01 | 0x02
|
||||
|
||||
class ConnectionType(IntFlag):
|
||||
BT = 0x0
|
||||
USB = 0x1
|
||||
|
||||
|
||||
class LedOptions(IntFlag):
|
||||
Off = 0x0
|
||||
PlayerLedBrightness = 0x1
|
||||
UninterrumpableLed = 0x2
|
||||
Both = 0x01 | 0x02
|
||||
|
||||
|
||||
class PulseOptions(IntFlag):
|
||||
Off=0x0,
|
||||
FadeBlue=0x1,
|
||||
FadeOut=0x2
|
||||
Off = 0x0
|
||||
FadeBlue = 0x1
|
||||
FadeOut = 0x2
|
||||
|
||||
|
||||
class Brightness(IntFlag):
|
||||
high = 0x0,
|
||||
medium = 0x1,
|
||||
high = 0x0
|
||||
medium = 0x1
|
||||
low = 0x2
|
||||
|
||||
|
||||
class PlayerID(IntFlag):
|
||||
player1 = 1,
|
||||
player2 = 2,
|
||||
player3 = 4,
|
||||
player4 = 8,
|
||||
player5 = 16,
|
||||
all = 31
|
||||
PLAYER_1 = 4
|
||||
PLAYER_2 = 10
|
||||
PLAYER_3 = 21
|
||||
PLAYER_4 = 27
|
||||
ALL = 31
|
||||
|
||||
|
||||
class TriggerModes(IntFlag):
|
||||
Off =0x0, # no resistance
|
||||
Rigid =0x1, # continous resistance
|
||||
Pulse =0x2, # section resistance
|
||||
Rigid_A=0x1 | 0x20,
|
||||
Rigid_B=0x1 | 0x04,
|
||||
Rigid_AB=0x1 | 0x20 | 0x04,
|
||||
Pulse_A = 0x2 | 0x20,
|
||||
Pulse_B = 0x2 | 0x04,
|
||||
Pulse_AB = 0x2 | 0x20 | 0x04,
|
||||
Calibration= 0xFC
|
||||
Off = 0x0 # no resistance
|
||||
Rigid = 0x1 # continous resistance
|
||||
Pulse = 0x2 # section resistance
|
||||
Rigid_A = 0x1 | 0x20
|
||||
Rigid_B = 0x1 | 0x04
|
||||
Rigid_AB = 0x1 | 0x20 | 0x04
|
||||
Pulse_A = 0x2 | 0x20
|
||||
Pulse_B = 0x2 | 0x04
|
||||
Pulse_AB = 0x2 | 0x20 | 0x04
|
||||
Calibration = 0xFC
|
||||
|
||||
|
||||
class BatteryState(IntFlag):
|
||||
POWER_SUPPLY_STATUS_DISCHARGING = 0x0
|
||||
POWER_SUPPLY_STATUS_CHARGING = 0x1
|
||||
POWER_SUPPLY_STATUS_FULL = 0x2
|
||||
POWER_SUPPLY_STATUS_NOT_CHARGING = 0xb
|
||||
POWER_SUPPLY_STATUS_ERROR = 0xf
|
||||
POWER_SUPPLY_TEMP_OR_VOLTAGE_OUT_OF_RANGE = 0xa
|
||||
POWER_SUPPLY_STATUS_UNKNOWN = 0x0
|
||||
|
60
pydualsense/event_system.py
Normal file
60
pydualsense/event_system.py
Normal file
@@ -0,0 +1,60 @@
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
class Event(object):
|
||||
"""
|
||||
Base class for the event driven system
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""
|
||||
initialise event system
|
||||
"""
|
||||
self._event_handler = []
|
||||
|
||||
def subscribe(self, fn):
|
||||
"""
|
||||
add a event subscription
|
||||
|
||||
Args:
|
||||
fn (function): _description_
|
||||
"""
|
||||
self._event_handler.append(fn)
|
||||
return self
|
||||
|
||||
def unsubscribe(self, fn):
|
||||
"""
|
||||
delete event subscription fn
|
||||
|
||||
Args:
|
||||
fn (function): _description_
|
||||
"""
|
||||
self._event_handler.remove(fn)
|
||||
return self
|
||||
|
||||
def __iadd__(self, fn):
|
||||
"""
|
||||
add event subscription fn
|
||||
|
||||
Args:
|
||||
fn (function): _description_
|
||||
"""
|
||||
self._event_handler.append(fn)
|
||||
return self
|
||||
|
||||
def __isub__(self, fn):
|
||||
"""
|
||||
delete event subscription fn
|
||||
|
||||
Args:
|
||||
fn (function): _description_
|
||||
"""
|
||||
self._event_handler.remove(fn)
|
||||
return self
|
||||
|
||||
def __call__(self, *args, **keywargs):
|
||||
"""
|
||||
calls all event subscription functions
|
||||
"""
|
||||
for eventhandler in self._event_handler:
|
||||
eventhandler(*args, **keywargs)
|
20
pydualsense/hidguardian.py
Normal file
20
pydualsense/hidguardian.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import winreg
|
||||
import sys
|
||||
|
||||
|
||||
def check_hide() -> bool:
|
||||
"""
|
||||
check if hidguardian is used and controller is hidden
|
||||
"""
|
||||
if sys.platform.startswith('win32'):
|
||||
try:
|
||||
access_reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
|
||||
access_key = winreg.OpenKey(access_reg, r'SYSTEM\CurrentControlSet\Services\HidGuardian\Parameters', 0, winreg.KEY_READ)
|
||||
affected_devices = winreg.QueryValueEx(access_key, 'AffectedDevices')[0]
|
||||
if "054C" in affected_devices and "0CE6" in affected_devices:
|
||||
return True
|
||||
return False
|
||||
except OSError as e:
|
||||
pass
|
||||
|
||||
return False
|
@@ -1,34 +0,0 @@
|
||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
import sys
|
||||
from interface import Ui_MainWindow
|
||||
from pydualsense import pydualsense
|
||||
|
||||
def colorR(value):
|
||||
global colorR
|
||||
colorR = value
|
||||
|
||||
def colorG(value):
|
||||
global colorG
|
||||
colorG = value
|
||||
|
||||
def colorB(value):
|
||||
global colorB
|
||||
colorB = value
|
||||
|
||||
def send():
|
||||
ds.setColor(colorR, colorG, colorB)
|
||||
ds.sendReport()
|
||||
if __name__ == "__main__":
|
||||
global ds
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
MainWindow = QtWidgets.QMainWindow()
|
||||
ui = Ui_MainWindow()
|
||||
ui.setupUi(MainWindow)
|
||||
ds = pydualsense()
|
||||
# connect interface to
|
||||
ui.slider_r.valueChanged.connect(colorR)
|
||||
ui.slider_g.valueChanged.connect(colorG)
|
||||
ui.slider_b.valueChanged.connect(colorB)
|
||||
ui.pushButton.clicked.connect(send)
|
||||
MainWindow.show()
|
||||
sys.exit(app.exec_())
|
File diff suppressed because it is too large
Load Diff
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
hid-usb
|
||||
sphinx
|
||||
furo
|
6
setup.py
6
setup.py
@@ -6,13 +6,13 @@ with open("README.md", "r") as fh:
|
||||
|
||||
setup(
|
||||
name='pydualsense',
|
||||
version='0.1.0',
|
||||
version='0.7.0',
|
||||
description='use your DualSense (PS5) controller with python',
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
url='https://github.com/flok/pydualsense',
|
||||
author='Florian K',
|
||||
author='Florian (flok) K',
|
||||
license='MIT License',
|
||||
packages=setuptools.find_packages(),
|
||||
install_requires=['hid>=1.0.4']
|
||||
install_requires=['hidapi-usb>=0.3', 'cffi']
|
||||
)
|
||||
|
Reference in New Issue
Block a user