73 Commits

Author SHA1 Message Date
Florian Kaiser
5238a1f0ed remove debug print 2024-03-02 23:43:58 +01:00
Florian Kaiser
519e667fe9 implementing poetry 2024-03-02 23:42:13 +01:00
Flo
fc60c0fda0 Merge pull request #51 from kappaj/kappaj-int8-fix
Fix state value conversion for joystick (LX, LY, RX, RY) to make it int8 compatible
2023-12-03 21:30:57 +01:00
Jens Kabisch
f193fad5ea Fix state value conversion for joystick (LX, LY, RX, RY)
This makes the joystick values int8 compatible.
Before this fix the joystick ranges from -127 to 128. But this corrects it to -128 to 127.
2023-06-04 18:44:02 +02:00
Florian Kaiser
b67bcb2b9d Bump to 0.7.0 2023-02-24 22:12:29 +01:00
Florian Kaiser
546a00c9b4 Add BT support, with crc calculation and batery readout 2023-02-24 22:11:15 +01:00
Flo
c0797ced0b Merge pull request #47 from flok/revert-45-bluetooth_impl
Revert "Bluetooth implementation"
2023-02-24 21:44:35 +01:00
Flo
bb3ab10b91 Revert "Bluetooth implementation" 2023-02-24 21:44:25 +01:00
Flo
875b5f66f8 Merge pull request #45 from kit-nya/bluetooth_impl
Bluetooth & Battery implementation
2023-02-24 12:55:43 +01:00
Kit
aebe1e581e Bluetooth implementation
Added in support for bluetooth. Also added in battery status support too.
2023-02-19 16:45:50 +09:00
Flo
de894fca7e Update setup.py 2023-02-05 16:32:04 +01:00
Flo
1b06033d4c Merge pull request #42 from triveria/add-bluetooth-readout
Add bluetooth readout
2023-02-05 16:30:11 +01:00
Michael Wagner
4105048784 Add option to leave channel-readout example with 'q' 2023-02-04 14:43:39 +01:00
Michael Wagner
e2c16cd29e Detect connection type and support bluetooth receiving 2023-02-02 22:27:59 +01:00
Michael Wagner
3b3ec445ad Hard code bluetooth mode for now 2023-02-02 20:21:03 +01:00
Michael Wagner
dc14382b62 Add example to continuously read out all states 2023-02-02 20:20:37 +01:00
Michael Wagner
bda77189f7 Add udev rule for reading controller without root privileges 2023-02-02 20:15:39 +01:00
Flo
d34302b494 Merge pull request #41 from CrimsonZen/patch-1
fixing leds.py example PlayerID reference
2023-01-14 19:13:54 +01:00
Chris Woytowitz
a808741b7f fixing leds.py example PlayerID reference 2023-01-14 09:01:50 -08:00
Flo
6f7413ecad Update docs_publish.yml 2023-01-05 20:49:25 +01:00
Flo
7c79dc5fbf Update setup.py 2023-01-04 17:57:12 +01:00
Flo
98271e866f Merge pull request #39 from dsb298/dsb298-contribution
fixed left/right motors
2023-01-04 17:56:24 +01:00
devlin
caa2062cea fixed left/right motors 2023-01-02 00:14:57 -05:00
Flo
9359e6eac4 Merge pull request #37 from flok/dev
Update doc
2022-10-23 09:56:49 +02:00
Florian Kaiser
c54f58bcee Update doc 2022-10-23 09:55:56 +02:00
Flo
d19bfc6507 release of 0.6.2
Update to 0.6.2 for typo and new release
2022-08-17 15:57:28 +02:00
Flo
2a448890ff Fix small typo on l2 event
Add small typo on the l2 event #35 - thanks to @thiagonc2 for reporting
2022-08-17 15:56:24 +02:00
Flo
5404852ec4 Merge pull request #34 from flok/dev
Update readme with docs link
2022-08-15 13:54:44 +02:00
Florian Kaiser
12b5743895 Update readme with docs link 2022-08-15 13:53:13 +02:00
Florian Kaiser
ab3f786013 added more documentation 2022-08-14 22:51:18 +02:00
Florian Kaiser
e8cb5de594 Update doc-strings and examples 2022-08-14 22:51:02 +02:00
Florian Kaiser
79bf833c9a Update requirements and author name in setup.py 2022-08-14 22:06:34 +02:00
Florian Kaiser
e1907e7a6f Add github action to publish docs 2022-08-14 20:29:41 +02:00
Florian Kaiser
60aa11b496 Add Docs 2022-08-14 20:27:55 +02:00
Florian Kaiser
330d117340 Fix wrong import v0.6.1 2022-08-14 16:20:15 +02:00
Flo
9d8ab950de Merge pull request #32 from flok/event_system
Event System and Gyro / Accelerometer support
2022-08-14 15:55:03 +02:00
Florian Kaiser
40f74472d7 Update README.md and version to 0.6 2022-08-14 15:51:39 +02:00
Florian Kaiser
b091660130 Add event system for states, added gyro and accelerometer 2022-08-14 15:48:58 +02:00
Florian Kaiser
82d407bfe2 Linting with pep8 2022-08-14 14:08:57 +02:00
Flo
0f279f1ee8 Update hidapi-usb version for linux support 2021-08-05 23:02:39 +02:00
Flo
624d17c919 Update README.md with Linux instructions 2021-08-05 21:55:24 +02:00
Florian Kaiser
24c628a182 Update package version 2021-06-28 23:04:55 +02:00
Florian Kaiser
36e8886754 Update version 2021-06-28 23:03:23 +02:00
Florian Kaiser
28605e0023 Update with linux support over usb 2021-06-28 23:00:22 +02:00
Florian Kaiser
f5529f1463 Add state for microphone button 2021-03-07 21:40:55 +01:00
Florian Kaiser
b3ff9fd375 Update 0.5.2
- Added Microphone mute
- changed MicrphoneLED function to boolean instead of int parameter
- using diffrent hidapi library for interacting with c library to get length of reports from device for bt support later
2021-03-07 21:21:01 +01:00
Flo
98b13798cd Merge pull request #19 from nougator/master
Fixed verbose
2021-01-17 21:10:33 +01:00
Nougator
b51c8b49f6 Fixed verbose. 2021-01-17 20:55:59 +01:00
Nougator
cdbe03ad56 Merge pull request #1 from flok/master
e
2021-01-17 20:55:19 +01:00
Flo
3a14ab3e7a Update setup.py 2021-01-10 14:53:56 +01:00
Flo
32f9042abb Merge pull request #16 from flok/hidapi_rewrite
Refactor hidapi
2021-01-10 14:08:31 +01:00
Florian Kaiser
4c86d71633 Refactor hidapi 2021-01-10 14:06:53 +01:00
Flo
9c79d961f1 Merge pull request #15 from TheComputerDan/master
Adapting Platform Agnostic Practices
2021-01-07 10:13:15 +01:00
Dan
c1c10e4eac Remove self reference 2021-01-06 18:25:15 -05:00
Dan
04ce807bc0 Added platform check for add_dll_directory 2021-01-03 22:16:31 -05:00
Dan
71a49da5d2 Removing accidently merged imports 2021-01-02 23:29:59 -05:00
Dan
f4e1d73dd3 Merge remote-tracking branch 'upstream/master'
Updating Fork with Master
2021-01-02 23:25:19 -05:00
Florian K
e766dca70f Deleting mypy action
Mypy gives weird results on github. Lets only work with it locally
2021-01-01 23:42:29 +01:00
Florian K
1e0b23da41 Update python-mypy.yml 2021-01-01 23:41:15 +01:00
Florian K
ff01788c89 Mypy enums import error fix 2021-01-01 23:39:54 +01:00
Florian K
c07b975bc5 Merge pull request #13 from nougator/patch-1
Update README.md
2021-01-01 23:16:08 +01:00
Nougator
7b0270fa7d Update README.md 2021-01-01 20:56:57 +01:00
Florian Kaiser
d76717c163 Fix missing import 2021-01-01 20:34:42 +01:00
Florian Kaiser
786657cc90 Merge branch 'master' of https://github.com/flok/pydualsense into master 2021-01-01 20:33:39 +01:00
Florian Kaiser
11e78fbece Fix Python > 3.8 dll import 2021-01-01 20:32:55 +01:00
Florian K
a3f697866b Changed place for hidapi.dll
Adding dlls to your System32 is not a good idea. Place the dll into your Workspace
2021-01-01 19:01:30 +01:00
Florian K
1530c79dd7 Update install instructions
Updated the install instructions with the hidapi download and placement.
2021-01-01 11:36:35 +01:00
Dan
83a37750d1 linting 2021-01-01 00:28:46 -05:00
Dan
bc0eb35c3c Moving winreg check to support other OSes 2020-12-31 20:39:50 -05:00
Florian Kaiser
93b5e38e6e v0.4.1
- Fix mypy errors
2020-12-31 23:53:23 +01:00
Florian Kaiser
94cb09dbdd v0.4.0
- refactored code structure
- fixed playerID led display
- added Color function with tuple support
- added type checking in every function
- added more Exceptions for out of bound values
2020-12-31 23:48:34 +01:00
Florian Kaiser
8fb31f86ba added mypy static analyzer action on push 2020-12-31 23:09:03 +01:00
Florian Kaiser
e04766d48d Add requirements.txt for dependabot 2020-12-27 15:06:23 +01:00
32 changed files with 1643 additions and 353 deletions

22
.github/workflows/docs_publish.yml vendored Normal file
View 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

View File

@@ -21,11 +21,11 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install setuptools wheel twine poetry
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
poetry build
twine upload dist/*

3
.gitignore vendored
View File

@@ -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
View 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"

View File

@@ -1,29 +1,64 @@
# 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 receive and 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](https://pypi.org/project/pydualsense/)
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`` folder for some more ideas
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
@@ -31,7 +66,7 @@ Help wanted from people that want to use this and have feature requests. Just op
# dependecies
- hid >= 1.0.4
- hidapi-usb >= 0.3
# Credits
@@ -44,5 +79,5 @@ Most stuff for this implementation were provided by and used from:
# Coming soon
- reading the states of the controller to enable a fully compatibility with python - partially done
- add multiple controllers
- add documentation using sphinx

0
docs/.nojekyll Normal file
View File

23
docs/Makefile Normal file
View 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
View 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
View File

@@ -0,0 +1,43 @@
import sys
from pathlib import Path
# 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.7.1'
sys.path.append(str(Path(__file__).parents[2]))
# -- 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
View 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:

View 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
View 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
View 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
View 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
View File

@@ -0,0 +1,7 @@
pydualsense
===========
.. toctree::
:maxdepth: 4
pydualsense

View 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
View 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`

View File

@@ -8,15 +8,16 @@ print('Trigger Effect demo started')
dualsense.setLeftMotor(255)
dualsense.setRightMotor(100)
dualsense.setLeftTriggerMode(TriggerModes.Rigid)
dualsense.setLeftTriggerForce(1, 255)
dualsense.triggerL.setMode(TriggerModes.Rigid)
dualsense.triggerL.setForce(1, 255)
dualsense.setRightTriggerMode(TriggerModes.Pulse_A)
dualsense.setRightTriggerForce(0, 200)
dualsense.setRightTriggerForce(1, 255)
dualsense.setRightTriggerForce(2, 175)
import time; time.sleep(3)
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()

View File

@@ -1,16 +1,18 @@
from pydualsense import *
from pydualsense import pydualsense
from pydualsense.enums import PlayerID
import time
# get dualsense instance
dualsense = pydualsense()
dualsense.init()
# set color around touchpad to red
dualsense.setColor(0,0,255)
# enable microphone indicator
dualsense.setMicrophoneLED(1)
# set all player indicators on
dualsense.setPlayerID(PlayerID.all)
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)
time.sleep(2)
# terminate the thread for message and close the device
dualsense.close()
dualsense.close()

View 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()

View File

@@ -1,15 +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:
print(f"Circle : {dualsense.state.circle} Cross : {dualsense.state.cross} L Stick X : {dualsense.state.LX} L Stick Y : {dualsense.state.LY}")
...
# close device
dualsense.close()

185
poetry.lock generated Normal file
View File

@@ -0,0 +1,185 @@
# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand.
[[package]]
name = "cffi"
version = "1.15.1"
description = "Foreign Function Interface for Python calling C code."
optional = false
python-versions = "*"
files = [
{file = "cffi-1.15.1-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:a66d3508133af6e8548451b25058d5812812ec3798c886bf38ed24a98216fab2"},
{file = "cffi-1.15.1-cp27-cp27m-manylinux1_i686.whl", hash = "sha256:470c103ae716238bbe698d67ad020e1db9d9dba34fa5a899b5e21577e6d52ed2"},
{file = "cffi-1.15.1-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:9ad5db27f9cabae298d151c85cf2bad1d359a1b9c686a275df03385758e2f914"},
{file = "cffi-1.15.1-cp27-cp27m-win32.whl", hash = "sha256:b3bbeb01c2b273cca1e1e0c5df57f12dce9a4dd331b4fa1635b8bec26350bde3"},
{file = "cffi-1.15.1-cp27-cp27m-win_amd64.whl", hash = "sha256:e00b098126fd45523dd056d2efba6c5a63b71ffe9f2bbe1a4fe1716e1d0c331e"},
{file = "cffi-1.15.1-cp27-cp27mu-manylinux1_i686.whl", hash = "sha256:d61f4695e6c866a23a21acab0509af1cdfd2c013cf256bbf5b6b5e2695827162"},
{file = "cffi-1.15.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:ed9cb427ba5504c1dc15ede7d516b84757c3e3d7868ccc85121d9310d27eed0b"},
{file = "cffi-1.15.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:39d39875251ca8f612b6f33e6b1195af86d1b3e60086068be9cc053aa4376e21"},
{file = "cffi-1.15.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:285d29981935eb726a4399badae8f0ffdff4f5050eaa6d0cfc3f64b857b77185"},
{file = "cffi-1.15.1-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3eb6971dcff08619f8d91607cfc726518b6fa2a9eba42856be181c6d0d9515fd"},
{file = "cffi-1.15.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:21157295583fe8943475029ed5abdcf71eb3911894724e360acff1d61c1d54bc"},
{file = "cffi-1.15.1-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:5635bd9cb9731e6d4a1132a498dd34f764034a8ce60cef4f5319c0541159392f"},
{file = "cffi-1.15.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2012c72d854c2d03e45d06ae57f40d78e5770d252f195b93f581acf3ba44496e"},
{file = "cffi-1.15.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dd86c085fae2efd48ac91dd7ccffcfc0571387fe1193d33b6394db7ef31fe2a4"},
{file = "cffi-1.15.1-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:fa6693661a4c91757f4412306191b6dc88c1703f780c8234035eac011922bc01"},
{file = "cffi-1.15.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:59c0b02d0a6c384d453fece7566d1c7e6b7bae4fc5874ef2ef46d56776d61c9e"},
{file = "cffi-1.15.1-cp310-cp310-win32.whl", hash = "sha256:cba9d6b9a7d64d4bd46167096fc9d2f835e25d7e4c121fb2ddfc6528fb0413b2"},
{file = "cffi-1.15.1-cp310-cp310-win_amd64.whl", hash = "sha256:ce4bcc037df4fc5e3d184794f27bdaab018943698f4ca31630bc7f84a7b69c6d"},
{file = "cffi-1.15.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:3d08afd128ddaa624a48cf2b859afef385b720bb4b43df214f85616922e6a5ac"},
{file = "cffi-1.15.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:3799aecf2e17cf585d977b780ce79ff0dc9b78d799fc694221ce814c2c19db83"},
{file = "cffi-1.15.1-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a591fe9e525846e4d154205572a029f653ada1a78b93697f3b5a8f1f2bc055b9"},
{file = "cffi-1.15.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3548db281cd7d2561c9ad9984681c95f7b0e38881201e157833a2342c30d5e8c"},
{file = "cffi-1.15.1-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:91fc98adde3d7881af9b59ed0294046f3806221863722ba7d8d120c575314325"},
{file = "cffi-1.15.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:94411f22c3985acaec6f83c6df553f2dbe17b698cc7f8ae751ff2237d96b9e3c"},
{file = "cffi-1.15.1-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:03425bdae262c76aad70202debd780501fabeaca237cdfddc008987c0e0f59ef"},
{file = "cffi-1.15.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:cc4d65aeeaa04136a12677d3dd0b1c0c94dc43abac5860ab33cceb42b801c1e8"},
{file = "cffi-1.15.1-cp311-cp311-win32.whl", hash = "sha256:a0f100c8912c114ff53e1202d0078b425bee3649ae34d7b070e9697f93c5d52d"},
{file = "cffi-1.15.1-cp311-cp311-win_amd64.whl", hash = "sha256:04ed324bda3cda42b9b695d51bb7d54b680b9719cfab04227cdd1e04e5de3104"},
{file = "cffi-1.15.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50a74364d85fd319352182ef59c5c790484a336f6db772c1a9231f1c3ed0cbd7"},
{file = "cffi-1.15.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e263d77ee3dd201c3a142934a086a4450861778baaeeb45db4591ef65550b0a6"},
{file = "cffi-1.15.1-cp36-cp36m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:cec7d9412a9102bdc577382c3929b337320c4c4c4849f2c5cdd14d7368c5562d"},
{file = "cffi-1.15.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:4289fc34b2f5316fbb762d75362931e351941fa95fa18789191b33fc4cf9504a"},
{file = "cffi-1.15.1-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:173379135477dc8cac4bc58f45db08ab45d228b3363adb7af79436135d028405"},
{file = "cffi-1.15.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:6975a3fac6bc83c4a65c9f9fcab9e47019a11d3d2cf7f3c0d03431bf145a941e"},
{file = "cffi-1.15.1-cp36-cp36m-win32.whl", hash = "sha256:2470043b93ff09bf8fb1d46d1cb756ce6132c54826661a32d4e4d132e1977adf"},
{file = "cffi-1.15.1-cp36-cp36m-win_amd64.whl", hash = "sha256:30d78fbc8ebf9c92c9b7823ee18eb92f2e6ef79b45ac84db507f52fbe3ec4497"},
{file = "cffi-1.15.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:198caafb44239b60e252492445da556afafc7d1e3ab7a1fb3f0584ef6d742375"},
{file = "cffi-1.15.1-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:5ef34d190326c3b1f822a5b7a45f6c4535e2f47ed06fec77d3d799c450b2651e"},
{file = "cffi-1.15.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8102eaf27e1e448db915d08afa8b41d6c7ca7a04b7d73af6514df10a3e74bd82"},
{file = "cffi-1.15.1-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:5df2768244d19ab7f60546d0c7c63ce1581f7af8b5de3eb3004b9b6fc8a9f84b"},
{file = "cffi-1.15.1-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:a8c4917bd7ad33e8eb21e9a5bbba979b49d9a97acb3a803092cbc1133e20343c"},
{file = "cffi-1.15.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0e2642fe3142e4cc4af0799748233ad6da94c62a8bec3a6648bf8ee68b1c7426"},
{file = "cffi-1.15.1-cp37-cp37m-win32.whl", hash = "sha256:e229a521186c75c8ad9490854fd8bbdd9a0c9aa3a524326b55be83b54d4e0ad9"},
{file = "cffi-1.15.1-cp37-cp37m-win_amd64.whl", hash = "sha256:a0b71b1b8fbf2b96e41c4d990244165e2c9be83d54962a9a1d118fd8657d2045"},
{file = "cffi-1.15.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:320dab6e7cb2eacdf0e658569d2575c4dad258c0fcc794f46215e1e39f90f2c3"},
{file = "cffi-1.15.1-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1e74c6b51a9ed6589199c787bf5f9875612ca4a8a0785fb2d4a84429badaf22a"},
{file = "cffi-1.15.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a5c84c68147988265e60416b57fc83425a78058853509c1b0629c180094904a5"},
{file = "cffi-1.15.1-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3b926aa83d1edb5aa5b427b4053dc420ec295a08e40911296b9eb1b6170f6cca"},
{file = "cffi-1.15.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:87c450779d0914f2861b8526e035c5e6da0a3199d8f1add1a665e1cbc6fc6d02"},
{file = "cffi-1.15.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4f2c9f67e9821cad2e5f480bc8d83b8742896f1242dba247911072d4fa94c192"},
{file = "cffi-1.15.1-cp38-cp38-win32.whl", hash = "sha256:8b7ee99e510d7b66cdb6c593f21c043c248537a32e0bedf02e01e9553a172314"},
{file = "cffi-1.15.1-cp38-cp38-win_amd64.whl", hash = "sha256:00a9ed42e88df81ffae7a8ab6d9356b371399b91dbdf0c3cb1e84c03a13aceb5"},
{file = "cffi-1.15.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:54a2db7b78338edd780e7ef7f9f6c442500fb0d41a5a4ea24fff1c929d5af585"},
{file = "cffi-1.15.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:fcd131dd944808b5bdb38e6f5b53013c5aa4f334c5cad0c72742f6eba4b73db0"},
{file = "cffi-1.15.1-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7473e861101c9e72452f9bf8acb984947aa1661a7704553a9f6e4baa5ba64415"},
{file = "cffi-1.15.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6c9a799e985904922a4d207a94eae35c78ebae90e128f0c4e521ce339396be9d"},
{file = "cffi-1.15.1-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3bcde07039e586f91b45c88f8583ea7cf7a0770df3a1649627bf598332cb6984"},
{file = "cffi-1.15.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:33ab79603146aace82c2427da5ca6e58f2b3f2fb5da893ceac0c42218a40be35"},
{file = "cffi-1.15.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5d598b938678ebf3c67377cdd45e09d431369c3b1a5b331058c338e201f12b27"},
{file = "cffi-1.15.1-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:db0fbb9c62743ce59a9ff687eb5f4afbe77e5e8403d6697f7446e5f609976f76"},
{file = "cffi-1.15.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:98d85c6a2bef81588d9227dde12db8a7f47f639f4a17c9ae08e773aa9c697bf3"},
{file = "cffi-1.15.1-cp39-cp39-win32.whl", hash = "sha256:40f4774f5a9d4f5e344f31a32b5096977b5d48560c5592e2f3d2c4374bd543ee"},
{file = "cffi-1.15.1-cp39-cp39-win_amd64.whl", hash = "sha256:70df4e3b545a17496c9b3f41f5115e69a4f2e77e94e1d2a8e1070bc0c38c8a3c"},
{file = "cffi-1.15.1.tar.gz", hash = "sha256:d400bfb9a37b1351253cb402671cea7e89bdecc294e8016a707f6d1d8ac934f9"},
]
[package.dependencies]
pycparser = "*"
[[package]]
name = "colorama"
version = "0.4.6"
description = "Cross-platform colored terminal text."
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
files = [
{file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
]
[[package]]
name = "hidapi-usb"
version = "0.3.1"
description = "CFFI wrapper for hidapi with changes by flok"
optional = false
python-versions = "*"
files = [
{file = "hidapi-usb-0.3.1.tar.gz", hash = "sha256:447ebf44942ab6c4ec2ac355567934b73f688a833266ab0094ea4e10f968cc13"},
{file = "hidapi_usb-0.3.1-py3-none-any.whl", hash = "sha256:b5556ea285e5df02d5f53c2e03b432c87fcc692830279c3f0064040116211679"},
]
[package.dependencies]
cffi = "*"
[[package]]
name = "mslex"
version = "1.1.0"
description = "shlex for windows"
optional = false
python-versions = ">=3.5"
files = [
{file = "mslex-1.1.0-py2.py3-none-any.whl", hash = "sha256:8826f4bb8d8c63402203d921dc8c2df0c7fec0d9c91d020ddf02fc9d0dce81bd"},
{file = "mslex-1.1.0.tar.gz", hash = "sha256:7fe305fbdc9721283875e0b737fdb344374b761338a7f41af91875de278568e4"},
]
[[package]]
name = "psutil"
version = "5.9.8"
description = "Cross-platform lib for process and system monitoring in Python."
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*"
files = [
{file = "psutil-5.9.8-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:26bd09967ae00920df88e0352a91cff1a78f8d69b3ecabbfe733610c0af486c8"},
{file = "psutil-5.9.8-cp27-cp27m-manylinux2010_i686.whl", hash = "sha256:05806de88103b25903dff19bb6692bd2e714ccf9e668d050d144012055cbca73"},
{file = "psutil-5.9.8-cp27-cp27m-manylinux2010_x86_64.whl", hash = "sha256:611052c4bc70432ec770d5d54f64206aa7203a101ec273a0cd82418c86503bb7"},
{file = "psutil-5.9.8-cp27-cp27mu-manylinux2010_i686.whl", hash = "sha256:50187900d73c1381ba1454cf40308c2bf6f34268518b3f36a9b663ca87e65e36"},
{file = "psutil-5.9.8-cp27-cp27mu-manylinux2010_x86_64.whl", hash = "sha256:02615ed8c5ea222323408ceba16c60e99c3f91639b07da6373fb7e6539abc56d"},
{file = "psutil-5.9.8-cp27-none-win32.whl", hash = "sha256:36f435891adb138ed3c9e58c6af3e2e6ca9ac2f365efe1f9cfef2794e6c93b4e"},
{file = "psutil-5.9.8-cp27-none-win_amd64.whl", hash = "sha256:bd1184ceb3f87651a67b2708d4c3338e9b10c5df903f2e3776b62303b26cb631"},
{file = "psutil-5.9.8-cp36-abi3-macosx_10_9_x86_64.whl", hash = "sha256:aee678c8720623dc456fa20659af736241f575d79429a0e5e9cf88ae0605cc81"},
{file = "psutil-5.9.8-cp36-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8cb6403ce6d8e047495a701dc7c5bd788add903f8986d523e3e20b98b733e421"},
{file = "psutil-5.9.8-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d06016f7f8625a1825ba3732081d77c94589dca78b7a3fc072194851e88461a4"},
{file = "psutil-5.9.8-cp36-cp36m-win32.whl", hash = "sha256:7d79560ad97af658a0f6adfef8b834b53f64746d45b403f225b85c5c2c140eee"},
{file = "psutil-5.9.8-cp36-cp36m-win_amd64.whl", hash = "sha256:27cc40c3493bb10de1be4b3f07cae4c010ce715290a5be22b98493509c6299e2"},
{file = "psutil-5.9.8-cp37-abi3-win32.whl", hash = "sha256:bc56c2a1b0d15aa3eaa5a60c9f3f8e3e565303b465dbf57a1b730e7a2b9844e0"},
{file = "psutil-5.9.8-cp37-abi3-win_amd64.whl", hash = "sha256:8db4c1b57507eef143a15a6884ca10f7c73876cdf5d51e713151c1236a0e68cf"},
{file = "psutil-5.9.8-cp38-abi3-macosx_11_0_arm64.whl", hash = "sha256:d16bbddf0693323b8c6123dd804100241da461e41d6e332fb0ba6058f630f8c8"},
{file = "psutil-5.9.8.tar.gz", hash = "sha256:6be126e3225486dff286a8fb9a06246a5253f4c7c53b475ea5f5ac934e64194c"},
]
[package.extras]
test = ["enum34", "ipaddress", "mock", "pywin32", "wmi"]
[[package]]
name = "pycparser"
version = "2.21"
description = "C parser in Python"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
files = [
{file = "pycparser-2.21-py2.py3-none-any.whl", hash = "sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9"},
{file = "pycparser-2.21.tar.gz", hash = "sha256:e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206"},
]
[[package]]
name = "taskipy"
version = "1.12.2"
description = "tasks runner for python projects"
optional = false
python-versions = ">=3.6,<4.0"
files = [
{file = "taskipy-1.12.2-py3-none-any.whl", hash = "sha256:ffdbb0bb0db54c0ec5c424610a3a087eea22706d4d1f6e3e8b4f12ebba05f98f"},
{file = "taskipy-1.12.2.tar.gz", hash = "sha256:eadfdc20d6bb94d8018eda32f1dbf584cf4aa6cffb71ba5cc2de20d344f8c4fb"},
]
[package.dependencies]
colorama = ">=0.4.4,<0.5.0"
mslex = {version = ">=1.1.0,<2.0.0", markers = "sys_platform == \"win32\""}
psutil = ">=5.7.2,<6.0.0"
tomli = {version = ">=2.0.1,<3.0.0", markers = "python_version >= \"3.7\" and python_version < \"4.0\""}
[[package]]
name = "tomli"
version = "2.0.1"
description = "A lil' TOML parser"
optional = false
python-versions = ">=3.7"
files = [
{file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"},
{file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"},
]
[metadata]
lock-version = "2.0"
python-versions = "^3.7"
content-hash = "df693da77db69c7bc101566cbef11e351c47e416f881226e88e8d58114b55c41"

View File

@@ -1,2 +1,9 @@
from .enums import LedOptions,Brightness,PlayerID,PulseOptions,TriggerModes
from .pydualsense import pydualsense, DSAudio, DSLight, DSTrigger
import os
import sys
sys.path.append(os.path.dirname(__file__))
from .enums import LedOptions, Brightness, PlayerID, PulseOptions, TriggerModes # noqa : F401
from .event_system import Event # noqa : F401
from .pydualsense import pydualsense, DSLight, DSState, DSTouchpad, DSTrigger, DSAudio # noqa : F401
__version__ = "0.7.1"

48
pydualsense/checksum.py Normal file
View File

@@ -0,0 +1,48 @@
import array
# from South-River
# fmt: off
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
])
# fmt:on
def compute(buffer):
result = 0xEADA2D49
for i in range(0, 74):
result = hashTable[(result & 0xFF) ^ (buffer[i] & 0xFF)] ^ (result >> 8)
return result

View File

@@ -1,38 +1,56 @@
from enum import IntFlag
class ConnectionType(IntFlag):
BT = 0x0
USB = 0x1
class LedOptions(IntFlag):
Off=0x0,
PlayerLedBrightness=0x1,
UninterrumpableLed=0x2,
Both=0x01 | 0x02
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

View File

@@ -0,0 +1,57 @@
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)

BIN
pydualsense/hidapi.dll Normal file

Binary file not shown.

View File

@@ -0,0 +1,25 @@
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:
pass
return False

File diff suppressed because it is too large Load Diff

36
pyproject.toml Normal file
View File

@@ -0,0 +1,36 @@
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "pydualsense"
version = "0.7.1"
description = "use your DualSense (PS5) controller with python"
license = "MIT"
repository = "https://github.com/flok/pydualsense"
authors = ["Florian (flok) K"]
readme = "README.md"
packages = [{include = "pydualsense"}]
include = ["pydualsense/hidapi.dll"]
[tool.poetry.dependencies]
python = "^3.7"
hidapi-usb = "^0.3.1"
[tool.poetry.group.dev.dependencies]
taskipy = "^1.12.2"
[tool.taskipy.tasks]
clear = "find pydualsense/ -type f \\( -iname \\*.c -o -iname \\*.cpp -o -iname \\*.pyd -o -iname \\*.so \\) -delete"
build = "poetry build"
html_docs = "make html -C docs"
post_build = "task clear"
post_test = "task clear"
[tool.poetry_bumpversion.file."pydualsense/__init__.py"]
[tool.ruff]
exclude = [".venv"]
line-length = 120

3
requirements.txt Normal file
View File

@@ -0,0 +1,3 @@
cffi==1.15.1 ; python_version >= "3.7" and python_version < "4.0"
hidapi-usb==0.3.1 ; python_version >= "3.7" and python_version < "4.0"
pycparser==2.21 ; python_version >= "3.7" and python_version < "4.0"

View File

@@ -6,13 +6,13 @@ with open("README.md", "r") as fh:
setup(
name='pydualsense',
version='0.3.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']
)