49 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
31 changed files with 1448 additions and 219 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/*

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,28 +1,64 @@
# pydualsense
control your dualsense through python. using the hid library this package implements the report features for controlling your new PS5 controller.
control your dualsense through python. using the hid library this package implements the report features for controlling your PS5 controller.
# install
# Documentation
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, TriggerModes
def cross_pressed(state):
print(state)
ds = pydualsense() # open controller
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) 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
@@ -30,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
@@ -43,7 +79,5 @@ Most stuff for this implementation were provided by and used from:
# Coming soon
- add bluetooth support
- add multiple controllers
- reading the states of the controller to enable a fully compatibility with python - partially done
- 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

@@ -16,7 +16,8 @@ dualsense.triggerR.setForce(0, 200)
dualsense.triggerR.setForce(1, 255)
dualsense.triggerR.setForce(2, 175)
import time; time.sleep(3)
# 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.light.setColorI(255,0,0)
# enable microphone indicator
dualsense.audio.setMicrophoneLED(1)
dualsense.light.setColorI(255, 0, 0)
# mute microphone
dualsense.audio.setMicrophoneState(True)
# set all player 1 indicator on
dualsense.light.setPlayerID(PlayerID.player1)
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, DSLight, DSState, DSTouchpad, DSTrigger, DSAudio
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 = 4,
player2 = 10,
player3 = 21,
player4 = 27,
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

@@ -1,18 +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, '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:
print(e)
return False
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

View File

@@ -1,53 +1,162 @@
import logging
import os
import sys
from sys import platform
if platform.startswith("win32") and sys.version_info >= (3, 8):
os.environ["PATH"] += os.pathsep + os.path.dirname(__file__)
# needed for python > 3.8
import os, sys
if sys.platform.startswith('win32') and sys.version_info >= (3,8):
os.add_dll_directory(os.getcwd())
import hidapi
from .enums import (LedOptions, PlayerID, PulseOptions, TriggerModes, Brightness) # type: ignore
from .enums import (
LedOptions,
PlayerID,
PulseOptions,
TriggerModes,
Brightness,
ConnectionType,
BatteryState,
) # type: ignore
import threading
class pydualsense:
from .event_system import Event
from .checksum import compute
from copy import deepcopy
logger = logging.getLogger()
FORMAT = "%(asctime)s %(message)s"
logging.basicConfig(format=FORMAT)
logger.setLevel(logging.INFO)
class pydualsense:
OUTPUT_REPORT_USB = 0x02
OUTPUT_REPORT_BT = 0x31
def __init__(self, verbose: bool = False) -> None:
"""
initialise the library but dont connect to the controller. call :func:`init() <pydualsense.pydualsense.init>` to connect to the controller
Args:
verbose (bool, optional): display verbose out (debug prints of input and output). Defaults to False.
"""
def __init__(self, verbose: bool = False) -> None:#
# TODO: maybe add a init function to not automatically allocate controller when class is declared
self.verbose = verbose
self.receive_buffer_size = 64
self.send_report_size = 48
if self.verbose:
logger.setLevel(logging.DEBUG)
self.leftMotor = 0
self.rightMotor = 0
self.last_states = None
def init(self):
"""initialize module and device states
self.register_available_events()
def register_available_events(self) -> None:
"""
register all available events that can be used for the controller
"""
# button events
self.triangle_pressed = Event()
self.circle_pressed = Event()
self.cross_pressed = Event()
self.square_pressed = Event()
# dpad events
# TODO: add a event that sends the pressed key if any key is pressed
# self.dpad_changed = Event()
self.dpad_up = Event()
self.dpad_down = Event()
self.dpad_left = Event()
self.dpad_right = Event()
# joystick
self.left_joystick_changed = Event()
self.right_joystick_changed = Event()
# trigger back buttons
self.r1_changed = Event()
self.r2_changed = Event()
self.r3_changed = Event()
self.l1_changed = Event()
self.l2_changed = Event()
self.l3_changed = Event()
# misc
self.ps_pressed = Event()
self.touch_pressed = Event()
self.microphone_pressed = Event()
self.share_pressed = Event()
self.option_pressed = Event()
# trackpad touch
# handles 1 or 2 fingers
# self.trackpad_frame_reported = Event()
# gyrometer events
self.gyro_changed = Event()
self.accelerometer_changed = Event()
def init(self) -> None:
"""
initialize module and device states. Starts the sendReport background thread at the end
"""
self.device: hidapi.Device = self.__find_device()
self.light = DSLight() # control led light of ds
self.audio = DSAudio() # ds audio setting
self.triggerL = DSTrigger() # left trigger
self.triggerR = DSTrigger() # right trigger
self.state = DSState() # controller states
# thread for receiving and sending
self.light = DSLight() # control led light of ds
self.audio = DSAudio() # ds audio setting
self.triggerL = DSTrigger() # left trigger
self.triggerR = DSTrigger() # right trigger
self.state = DSState() # controller states
self.battery = DSBattery()
self.conType = self.determineConnectionType() # determine USB or BT connection
self.ds_thread = True
self.report_thread = threading.Thread(target=self.sendReport)
self.report_thread.start()
self.states = None
def close(self):
def determineConnectionType(self) -> ConnectionType:
"""
Determine the connection type of the controller. eg USB or BT.
We ask the controller for an input report with a length up to 100 bytes
and afterwords check the lenght of the received input report.
The connection type determines the length of the report.
This way of determining is not pretty but it works..
Returns:
ConnectionType: Detected connection type of the controller.
"""
dummy_report = self.device.read(100)
input_report_length = len(dummy_report)
if input_report_length == 64:
self.input_report_length = 64
self.output_report_length = 64
return ConnectionType.USB
elif input_report_length == 78:
self.input_report_length = 78
self.output_report_length = 78
return ConnectionType.BT
def close(self) -> None:
"""
Stops the report thread and closes the HID device
"""
# TODO: reset trigger effect to default
self.ds_thread = False
self.report_thread.join()
self.device.close()
def __find_device(self) -> hidapi.Device:
"""
find HID device and open it
find HID dualsense device and open it
Raises:
Exception: HIDGuardian detected
@@ -58,24 +167,28 @@ class pydualsense:
"""
# TODO: detect connection mode, bluetooth has a bigger write buffer
# TODO: implement multiple controllers working
if sys.platform.startswith('win32'):
if sys.platform.startswith("win32"):
import pydualsense.hidguardian as hidguardian
if hidguardian.check_hide():
raise Exception('HIDGuardian detected. Delete the controller from HIDGuardian and restart PC to connect to controller')
raise Exception(
"HIDGuardian detected. Delete the controller from HIDGuardian and restart PC to connect to controller"
)
detected_device: hidapi.Device = None
devices = hidapi.enumerate(vendor_id=0x054c)
devices = hidapi.enumerate(vendor_id=0x054C)
for device in devices:
if device.vendor_id == 0x054c and device.product_id == 0x0CE6:
if device.vendor_id == 0x054C and device.product_id == 0x0CE6:
detected_device = device
if detected_device is None:
raise Exception("No device detected")
if detected_device == None:
raise Exception('No device detected')
dual_sense = hidapi.Device(vendor_id=detected_device.vendor_id, product_id=detected_device.product_id)
dual_sense = hidapi.Device(
vendor_id=detected_device.vendor_id, product_id=detected_device.product_id
)
return dual_sense
def setLeftMotor(self, intensity: int):
def setLeftMotor(self, intensity: int) -> None:
"""
set left motor rumble
@@ -87,14 +200,13 @@ class pydualsense:
Exception: intensity out of bounds 0..255
"""
if not isinstance(intensity, int):
raise TypeError('left motor intensity needs to be an int')
raise TypeError("left motor intensity needs to be an int")
if intensity > 255 or intensity < 0:
raise Exception('maximum intensity is 255')
raise Exception("maximum intensity is 255")
self.leftMotor = intensity
def setRightMotor(self, intensity: int):
def setRightMotor(self, intensity: int) -> None:
"""
set right motor rumble
@@ -106,44 +218,49 @@ class pydualsense:
Exception: intensity out of bounds 0..255
"""
if not isinstance(intensity, int):
raise TypeError('right motor intensity needs to be an int')
raise TypeError("right motor intensity needs to be an int")
if intensity > 255 or intensity < 0:
raise Exception('maximum intensity is 255')
raise Exception("maximum intensity is 255")
self.rightMotor = intensity
def sendReport(self):
"""background thread handling the reading of the device and updating its states
"""
def sendReport(self) -> None:
"""background thread handling the reading of the device and updating its states"""
while self.ds_thread:
# read data from the input report of the controller
inReport = self.device.read(self.receive_buffer_size)
print(inReport)
inReport = self.device.read(self.input_report_length)
if self.verbose:
logger.debug(inReport)
# decrypt the packet and bind the inputs
self.readInput(inReport)
# prepare new report for device
outReport = self.prepareReport()
# write the report to the device
self.writeReport(outReport)
def readInput(self, inReport):
def readInput(self, inReport) -> None:
"""
read the input from the controller and assign the states
Args:
inReport (bytearray): read bytearray containing the state of the whole controller
"""
states = list(inReport) # convert bytes to list
if self.conType == ConnectionType.BT:
# the reports for BT and USB are structured the same,
# but there is one more byte at the start of the bluetooth report.
# We drop that byte, so that the format matches up again.
states = list(inReport)[1:] # convert bytes to list
else: # USB
states = list(inReport) # convert bytes to list
self.states = states
# states 0 is always 1
self.state.LX = states[1] - 127
self.state.LY = states[2] - 127
self.state.RX = states[3] - 127
self.state.RY = states[4] - 127
self.state.LX = states[1] - 128
self.state.LY = states[2] - 128
self.state.RX = states[3] - 128
self.state.RY = states[4] - 128
self.state.L2 = states[5]
self.state.R2 = states[6]
@@ -155,7 +272,6 @@ class pydualsense:
self.state.cross = (buttonState & (1 << 5)) != 0
self.state.square = (buttonState & (1 << 4)) != 0
# dpad
dpad_state = buttonState & 0x0F
self.state.setDPadState(dpad_state)
@@ -173,32 +289,151 @@ class pydualsense:
misc2 = states[10]
self.state.ps = (misc2 & (1 << 0)) != 0
self.state.touchBtn = (misc2 & 0x02) != 0
self.state.micBtn = (misc2 & 0x04) != 0
# trackpad touch
self.state.trackPadTouch0.ID = inReport[33] & 0x7F
self.state.trackPadTouch0.isActive = (inReport[33] & 0x80) == 0
self.state.trackPadTouch0.X = ((inReport[35] & 0x0f) << 8) | (inReport[34])
self.state.trackPadTouch0.Y = ((inReport[36]) << 4) | ((inReport[35] & 0xf0) >> 4)
self.state.trackPadTouch0.X = ((inReport[35] & 0x0F) << 8) | (inReport[34])
self.state.trackPadTouch0.Y = ((inReport[36]) << 4) | (
(inReport[35] & 0xF0) >> 4
)
# trackpad touch
self.state.trackPadTouch1.ID = inReport[37] & 0x7F
self.state.trackPadTouch1.isActive = (inReport[37] & 0x80) == 0
self.state.trackPadTouch1.X = ((inReport[39] & 0x0f) << 8) | (inReport[38])
self.state.trackPadTouch1.Y = ((inReport[40]) << 4) | ((inReport[39] & 0xf0) >> 4)
self.state.trackPadTouch1.X = ((inReport[39] & 0x0F) << 8) | (inReport[38])
self.state.trackPadTouch1.Y = ((inReport[40]) << 4) | (
(inReport[39] & 0xF0) >> 4
)
# print(f'1Active = {self.state.trackPadTouch0.isActive}')
# print(f'X1: {self.state.trackPadTouch0.X} Y2: {self.state.trackPadTouch0.Y}')
# accelerometer
self.state.accelerometer.X = int.from_bytes(
([inReport[16], inReport[17]]), byteorder="little", signed=True
)
self.state.accelerometer.Y = int.from_bytes(
([inReport[18], inReport[19]]), byteorder="little", signed=True
)
self.state.accelerometer.Z = int.from_bytes(
([inReport[20], inReport[21]]), byteorder="little", signed=True
)
# print(f'2Active = {self.state.trackPadTouch1.isActive}')
# print(f'X2: {self.state.trackPadTouch1.X} Y2: {self.state.trackPadTouch1.Y}')
# print(f'DPAD {self.state.DpadLeft} {self.state.DpadUp} {self.state.DpadRight} {self.state.DpadDown}')
# gyrometer
self.state.gyro.Pitch = int.from_bytes(
([inReport[22], inReport[23]]), byteorder="little", signed=True
)
self.state.gyro.Yaw = int.from_bytes(
([inReport[24], inReport[25]]), byteorder="little", signed=True
)
self.state.gyro.Roll = int.from_bytes(
([inReport[26], inReport[27]]), byteorder="little", signed=True
)
# from kit-nya
battery = states[53]
self.battery.State = BatteryState((battery & 0xF0) >> 4)
self.battery.Level = min((battery & 0x0F) * 10 + 5, 100)
# first call we dont have a "last state" so we create if with the first occurence
if self.last_states is None:
self.last_states = deepcopy(self.state)
return
# send all events if neede
if self.state.circle != self.last_states.circle:
self.circle_pressed(self.state.circle)
if self.state.cross != self.last_states.cross:
self.cross_pressed(self.state.cross)
if self.state.triangle != self.last_states.triangle:
self.triangle_pressed(self.state.triangle)
if self.state.square != self.last_states.square:
self.square_pressed(self.state.square)
if self.state.DpadDown != self.last_states.DpadDown:
self.dpad_down(self.state.DpadDown)
if self.state.DpadLeft != self.last_states.DpadLeft:
self.dpad_left(self.state.DpadLeft)
if self.state.DpadRight != self.last_states.DpadRight:
self.dpad_right(self.state.DpadRight)
if self.state.DpadUp != self.last_states.DpadUp:
self.dpad_up(self.state.DpadUp)
if self.state.LX != self.last_states.LX or self.state.LY != self.last_states.LY:
self.left_joystick_changed(self.state.LX, self.state.LY)
if self.state.RX != self.last_states.RX or self.state.RY != self.last_states.RY:
self.right_joystick_changed(self.state.RX, self.state.RY)
if self.state.R1 != self.last_states.R1:
self.r1_changed(self.state.R1)
if self.state.R2 != self.last_states.R2:
self.r2_changed(self.state.R2)
if self.state.L1 != self.last_states.L1:
self.l1_changed(self.state.L1)
if self.state.L2 != self.last_states.L2:
self.l2_changed(self.state.L2)
if self.state.R3 != self.last_states.R3:
self.r3_changed(self.state.R3)
if self.state.L3 != self.last_states.L3:
self.l3_changed(self.state.L3)
if self.state.ps != self.last_states.ps:
self.ps_pressed(self.state.ps)
if self.state.touchBtn != self.last_states.touchBtn:
self.touch_pressed(self.state.touchBtn)
if self.state.micBtn != self.last_states.micBtn:
self.microphone_pressed(self.state.micBtn)
if self.state.share != self.last_states.share:
self.share_pressed(self.state.share)
if self.state.options != self.last_states.options:
self.option_pressed(self.state.options)
if (
self.state.accelerometer.X != self.last_states.accelerometer.X
or self.state.accelerometer.Y != self.last_states.accelerometer.Y
or self.state.accelerometer.Z != self.last_states.accelerometer.Z
):
self.accelerometer_changed(
self.state.accelerometer.X,
self.state.accelerometer.Y,
self.state.accelerometer.Z,
)
if (
self.state.gyro.Pitch != self.last_states.gyro.Pitch
or self.state.gyro.Yaw != self.last_states.gyro.Yaw
or self.state.gyro.Roll != self.last_states.gyro.Roll
):
self.gyro_changed(
self.state.gyro.Pitch, self.state.gyro.Yaw, self.state.gyro.Roll
)
"""
copy current state into temp object to check next cycle if a change occuret
and event trigger is needed
"""
self.last_states = deepcopy(
self.state
) # copy current state into object to check next time
# TODO: implement gyrometer and accelerometer
# TODO: control mouse with touchpad for fun as DS4Windows
def writeReport(self, outReport):
def writeReport(self, outReport) -> None:
"""
write the report to the device
@@ -207,79 +442,164 @@ class pydualsense:
"""
self.device.write(bytes(outReport))
def prepareReport(self):
def prepareReport(self) -> None:
"""
prepare the output to be send to the controller
Returns:
list: report to send to controller
"""
outReport = [0] * 48 # create empty list with range of output report
# packet type
outReport[0] = 0x2
if self.conType == ConnectionType.USB:
outReport = (
[0] * self.output_report_length
) # create empty list with range of output report
# packet type
outReport[0] = self.OUTPUT_REPORT_USB
# flags determing what changes this packet will perform
# 0x01 set the main motors (also requires flag 0x02); setting this by itself will allow rumble to gracefully terminate and then re-enable audio haptics, whereas not setting it will kill the rumble instantly and re-enable audio haptics.
# 0x02 set the main motors (also requires flag 0x01; without bit 0x01 motors are allowed to time out without re-enabling audio haptics)
# 0x04 set the right trigger motor
# 0x08 set the left trigger motor
# 0x10 modification of audio volume
# 0x20 toggling of internal speaker while headset is connected
# 0x40 modification of microphone volume
outReport[1] = 0xff # [1]
# flags determing what changes this packet will perform
# 0x01 set the main motors (also requires flag 0x02); setting this by itself will allow rumble to gracefully terminate and then re-enable audio haptics, whereas not setting it will kill the rumble instantly and re-enable audio haptics.
# 0x02 set the main motors (also requires flag 0x01; without bit 0x01 motors are allowed to time out without re-enabling audio haptics)
# 0x04 set the right trigger motor
# 0x08 set the left trigger motor
# 0x10 modification of audio volume
# 0x20 toggling of internal speaker while headset is connected
# 0x40 modification of microphone volume
outReport[1] = 0xFF # [1]
# further flags determining what changes this packet will perform
# 0x01 toggling microphone LED
# 0x02 toggling audio/mic mute
# 0x04 toggling LED strips on the sides of the touchpad
# 0x08 will actively turn all LEDs off? Convenience flag? (if so, third parties might not support it properly)
# 0x10 toggling white player indicator LEDs below touchpad
# 0x20 ???
# 0x40 adjustment of overall motor/effect power (index 37 - read note on triggers)
# 0x80 ???
outReport[2] = 0x1 | 0x2 | 0x4 | 0x10 | 0x40 # [2]
# further flags determining what changes this packet will perform
# 0x01 toggling microphone LED
# 0x02 toggling audio/mic mute
# 0x04 toggling LED strips on the sides of the touchpad
# 0x08 will actively turn all LEDs off? Convenience flag? (if so, third parties might not support it properly)
# 0x10 toggling white player indicator LEDs below touchpad
# 0x20 ???
# 0x40 adjustment of overall motor/effect power (index 37 - read note on triggers)
# 0x80 ???
outReport[2] = 0x1 | 0x2 | 0x4 | 0x10 | 0x40 # [2]
outReport[3] = self.leftMotor # left low freq motor 0-255 # [3]
outReport[4] = self.rightMotor # right low freq motor 0-255 # [4]
outReport[3] = self.rightMotor # right low freq motor 0-255 # [3]
outReport[4] = self.leftMotor # left low freq motor 0-255 # [4]
# outReport[5] - outReport[8] audio related
# outReport[5] - outReport[8] audio related
# set Micrphone LED, setting doesnt effect microphone settings
outReport[9] = self.audio.microphone_led # [9]
# set Micrphone LED, setting doesnt effect microphone settings
outReport[9] = self.audio.microphone_led # [9]
# add right trigger mode + parameters to packet
outReport[11] = self.triggerR.mode.value
outReport[12] = self.triggerR.forces[0]
outReport[13] = self.triggerR.forces[1]
outReport[14] = self.triggerR.forces[2]
outReport[15] = self.triggerR.forces[3]
outReport[16] = self.triggerR.forces[4]
outReport[17] = self.triggerR.forces[5]
outReport[20] = self.triggerR.forces[6]
outReport[10] = 0x10 if self.audio.microphone_mute is True else 0x00
outReport[22] = self.triggerL.mode.value
outReport[23] = self.triggerL.forces[0]
outReport[24] = self.triggerL.forces[1]
outReport[25] = self.triggerL.forces[2]
outReport[26] = self.triggerL.forces[3]
outReport[27] = self.triggerL.forces[4]
outReport[28] = self.triggerL.forces[5]
outReport[31] = self.triggerL.forces[6]
# add right trigger mode + parameters to packet
outReport[11] = self.triggerR.mode.value
outReport[12] = self.triggerR.forces[0]
outReport[13] = self.triggerR.forces[1]
outReport[14] = self.triggerR.forces[2]
outReport[15] = self.triggerR.forces[3]
outReport[16] = self.triggerR.forces[4]
outReport[17] = self.triggerR.forces[5]
outReport[20] = self.triggerR.forces[6]
outReport[22] = self.triggerL.mode.value
outReport[23] = self.triggerL.forces[0]
outReport[24] = self.triggerL.forces[1]
outReport[25] = self.triggerL.forces[2]
outReport[26] = self.triggerL.forces[3]
outReport[27] = self.triggerL.forces[4]
outReport[28] = self.triggerL.forces[5]
outReport[31] = self.triggerL.forces[6]
outReport[39] = self.light.ledOption.value
outReport[42] = self.light.pulseOptions.value
outReport[43] = self.light.brightness.value
outReport[44] = self.light.playerNumber.value
outReport[45] = self.light.TouchpadColor[0]
outReport[46] = self.light.TouchpadColor[1]
outReport[47] = self.light.TouchpadColor[2]
elif self.conType == ConnectionType.BT:
outReport = (
[0] * self.output_report_length
) # create empty list with range of output report
# packet type
outReport[0] = self.OUTPUT_REPORT_BT # bt type
outReport[1] = 0x02
# flags determing what changes this packet will perform
# 0x01 set the main motors (also requires flag 0x02); setting this by itself will allow rumble to gracefully terminate and then re-enable audio haptics, whereas not setting it will kill the rumble instantly and re-enable audio haptics.
# 0x02 set the main motors (also requires flag 0x01; without bit 0x01 motors are allowed to time out without re-enabling audio haptics)
# 0x04 set the right trigger motor
# 0x08 set the left trigger motor
# 0x10 modification of audio volume
# 0x20 toggling of internal speaker while headset is connected
# 0x40 modification of microphone volume
outReport[2] = 0xFF # [1]
# further flags determining what changes this packet will perform
# 0x01 toggling microphone LED
# 0x02 toggling audio/mic mute
# 0x04 toggling LED strips on the sides of the touchpad
# 0x08 will actively turn all LEDs off? Convenience flag? (if so, third parties might not support it properly)
# 0x10 toggling white player indicator LEDs below touchpad
# 0x20 ???
# 0x40 adjustment of overall motor/effect power (index 37 - read note on triggers)
# 0x80 ???
outReport[3] = 0x1 | 0x2 | 0x4 | 0x10 | 0x40 # [2]
outReport[4] = self.rightMotor # right low freq motor 0-255 # [3]
outReport[5] = self.leftMotor # left low freq motor 0-255 # [4]
# outReport[5] - outReport[8] audio related
# set Micrphone LED, setting doesnt effect microphone settings
outReport[10] = self.audio.microphone_led # [9]
outReport[11] = 0x10 if self.audio.microphone_mute is True else 0x00
# add right trigger mode + parameters to packet
outReport[12] = self.triggerR.mode.value
outReport[13] = self.triggerR.forces[0]
outReport[14] = self.triggerR.forces[1]
outReport[15] = self.triggerR.forces[2]
outReport[16] = self.triggerR.forces[3]
outReport[17] = self.triggerR.forces[4]
outReport[18] = self.triggerR.forces[5]
outReport[21] = self.triggerR.forces[6]
outReport[23] = self.triggerL.mode.value
outReport[24] = self.triggerL.forces[0]
outReport[25] = self.triggerL.forces[1]
outReport[26] = self.triggerL.forces[2]
outReport[27] = self.triggerL.forces[3]
outReport[28] = self.triggerL.forces[4]
outReport[29] = self.triggerL.forces[5]
outReport[32] = self.triggerL.forces[6]
outReport[40] = self.light.ledOption.value
outReport[43] = self.light.pulseOptions.value
outReport[44] = self.light.brightness.value
outReport[45] = self.light.playerNumber.value
outReport[46] = self.light.TouchpadColor[0]
outReport[47] = self.light.TouchpadColor[1]
outReport[48] = self.light.TouchpadColor[2]
crcChecksum = compute(outReport)
outReport[74] = crcChecksum & 0x000000FF
outReport[75] = (crcChecksum & 0x0000FF00) >> 8
outReport[76] = (crcChecksum & 0x00FF0000) >> 16
outReport[77] = (crcChecksum & 0xFF000000) >> 24
outReport[39] = self.light.ledOption.value
outReport[42] = self.light.pulseOptions.value
outReport[43] = self.light.brightness.value
outReport[44] = self.light.playerNumber.value
outReport[45] = self.light.TouchpadColor[0]
outReport[46] = self.light.TouchpadColor[1]
outReport[47] = self.light.TouchpadColor[2]
if self.verbose:
print(outReport)
logger.debug(outReport)
return outReport
class DSTouchpad:
"""
Dualsense Touchpad class. Contains X and Y position of touch and if the touch isActive
"""
def __init__(self) -> None:
"""
Class represents the Touchpad of the controller
@@ -289,19 +609,53 @@ class DSTouchpad:
self.X = 0
self.Y = 0
class DSState:
def __init__(self) -> None:
self.packerC = 0
"""
All dualsense states (inputs) that can be read. Second method to check if a input is pressed.
"""
self.square, self.triangle, self.circle, self.cross = False, False, False, False
self.DpadUp, self.DpadDown, self.DpadLeft, self.DpadRight = False, False, False, False
self.L1, self.L2, self.L3, self.R1, self.R2, self.R3, self.R2Btn, self.L2Btn = False, False, False, False, False, False, False, False
self.share, self.options, self.ps, self.touch1, self.touch2, self.touchBtn, self.touchRight, self.touchLeft = False, False, False, False, False, False, False, False
self.DpadUp, self.DpadDown, self.DpadLeft, self.DpadRight = (
False,
False,
False,
False,
)
self.L1, self.L2, self.L3, self.R1, self.R2, self.R3, self.R2Btn, self.L2Btn = (
False,
False,
False,
False,
False,
False,
False,
False,
)
(
self.share,
self.options,
self.ps,
self.touch1,
self.touch2,
self.touchBtn,
self.touchRight,
self.touchLeft,
) = False, False, False, False, False, False, False, False
self.touchFinger1, self.touchFinger2 = False, False
self.RX, self.RY, self.LX, self.LY = 128,128,128,128
self.micBtn = False
self.RX, self.RY, self.LX, self.LY = 128, 128, 128, 128
self.trackPadTouch0, self.trackPadTouch1 = DSTouchpad(), DSTouchpad()
self.gyro = DSGyro()
self.accelerometer = DSAccelerometer()
def setDPadState(self, dpad_state):
def setDPadState(self, dpad_state: int):
"""
Sets the dpad state variables according to the integers that was read from the controller
Args:
dpad_state (int): integer number representing the dpad state
"""
if dpad_state == 0:
self.DpadUp = True
self.DpadDown = False
@@ -353,12 +707,13 @@ class DSLight:
"""
Represents all features of lights on the controller
"""
def __init__(self) -> None:
self.brightness: Brightness = Brightness.low # sets
self.playerNumber: PlayerID = PlayerID.player1
self.ledOption : LedOptions = LedOptions.Both
self.pulseOptions : PulseOptions = PulseOptions.Off
self.TouchpadColor = (0,0,255)
self.brightness: Brightness = Brightness.low # sets
self.playerNumber: PlayerID = PlayerID.PLAYER_1
self.ledOption: LedOptions = LedOptions.Both
self.pulseOptions: PulseOptions = PulseOptions.Off
self.TouchpadColor = (0, 0, 255)
def setLEDOption(self, option: LedOptions):
"""
@@ -371,7 +726,7 @@ class DSLight:
TypeError: LedOption is false type
"""
if not isinstance(option, LedOptions):
raise TypeError('Need LEDOption type')
raise TypeError("Need LEDOption type")
self.ledOption = option
def setPulseOption(self, option: PulseOptions):
@@ -385,7 +740,7 @@ class DSLight:
TypeError: Pulse option is false type
"""
if not isinstance(option, PulseOptions):
raise TypeError('Need PulseOption type')
raise TypeError("Need PulseOption type")
self.pulseOptions = option
def setBrightness(self, brightness: Brightness):
@@ -399,10 +754,10 @@ class DSLight:
TypeError: brightness false type
"""
if not isinstance(brightness, Brightness):
raise TypeError('Need Brightness type')
raise TypeError("Need Brightness type")
self.brightness = brightness
def setPlayerID(self, player : PlayerID):
def setPlayerID(self, player: PlayerID):
"""
Sets the PlayerID of the controller with the choosen LEDs.
The controller has 4 Player states
@@ -414,10 +769,10 @@ class DSLight:
TypeError: [description]
"""
if not isinstance(player, PlayerID):
raise TypeError('Need PlayerID type')
raise TypeError("Need PlayerID type")
self.playerNumber = player
def setColorI(self, r: int , g: int, b: int) -> None:
def setColorI(self, r: int, g: int, b: int) -> None:
"""
Sets the Color around the Touchpad of the controller
@@ -431,12 +786,11 @@ class DSLight:
Exception: color channels are out of bounds
"""
if not isinstance(r, int) or not isinstance(g, int) or not isinstance(b, int):
raise TypeError('Color parameter need to be int')
raise TypeError("Color parameter need to be int")
# check if color is out of bounds
if (r > 255 or g > 255 or b > 255) or (r < 0 or g < 0 or b < 0):
raise Exception('colors have values from 0 to 255 only')
self.TouchpadColor = (r,g,b)
raise Exception("colors have values from 0 to 255 only")
self.TouchpadColor = (r, g, b)
def setColorT(self, color: tuple) -> None:
"""
@@ -450,17 +804,20 @@ class DSLight:
Exception: color channels are out of bounds
"""
if not isinstance(color, tuple):
raise TypeError('Color type is tuple')
raise TypeError("Color type is tuple")
# unpack for out of bounds check
r,g,b = map(int, color)
r, g, b = map(int, color)
# check if color is out of bounds
if (r > 255 or g > 255 or b > 255) or (r < 0 or g < 0 or b < 0):
raise Exception('colors have values from 0 to 255 only')
self.TouchpadColor = (r,g,b)
raise Exception("colors have values from 0 to 255 only")
self.TouchpadColor = (r, g, b)
class DSAudio:
def __init__(self) -> None:
"""
initialize the limited Audio features of the controller
"""
self.microphone_mute = 0
self.microphone_led = 0
@@ -470,19 +827,43 @@ class DSAudio:
This doesnt change the mute/unmutes the microphone itself.
Args:
value (int): On or off microphone LED
value (bool): On or off microphone LED
Raises:
Exception: false state for the led
"""
if value > 1 or value < 0:
raise Exception('Microphone LED can only be on or off (0 .. 1)')
if not isinstance(value, bool):
raise TypeError("MicrophoneLED can only be a bool")
self.microphone_led = value
def setMicrophoneState(self, state: bool):
"""
Set the microphone state and also sets the microphone led accordingle
Args:
state (bool): desired state of the microphone
Raises:
TypeError: state was not a bool
"""
if not isinstance(state, bool):
raise TypeError("state needs to be bool")
self.setMicrophoneLED(state) # set led accordingly
self.microphone_mute = state
class DSTrigger:
"""
Dualsense trigger class. Allowes for multiple :class:`TriggerModes <pydualsense.enums.TriggerModes>` and multiple forces
# TODO: make this interface more userfriendly so a developer knows what he is doing
"""
def __init__(self) -> None:
# trigger modes
self.mode : TriggerModes = TriggerModes.Off
self.mode: TriggerModes = TriggerModes.Off
# force parameters for the triggers
self.forces = [0 for i in range(7)]
@@ -500,10 +881,10 @@ class DSTrigger:
Exception: choosen a false force parameter
"""
if not isinstance(forceID, int) or not isinstance(force, int):
raise TypeError('forceID and force needs to be type int')
raise TypeError("forceID and force needs to be type int")
if forceID > 6 or forceID < 0:
raise Exception('only 7 parameters available')
raise Exception("only 7 parameters available")
self.forces[forceID] = force
@@ -518,6 +899,38 @@ class DSTrigger:
TypeError: false Trigger mode type
"""
if not isinstance(mode, TriggerModes):
raise TypeError('Trigger mode parameter needs to be of type `TriggerModes`')
raise TypeError("Trigger mode parameter needs to be of type `TriggerModes`")
self.mode = mode
class DSGyro:
"""
Class representing the Gyro2 of the controller
"""
def __init__(self) -> None:
self.Pitch = 0
self.Yaw = 0
self.Roll = 0
class DSAccelerometer:
"""
Class representing the Accelerometer of the controller
"""
def __init__(self) -> None:
self.X = 0
self.Y = 0
self.Z = 0
class DSBattery:
"""
Class representing the Battery of the controller
"""
def __init__(self) -> None:
self.State = BatteryState.POWER_SUPPLY_STATUS_UNKNOWN
self.Level = 0

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

View File

@@ -1 +1,3 @@
hid==1.0.4
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.5.1',
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=['hidapi-usb', 'cffi']
install_requires=['hidapi-usb>=0.3', 'cffi']
)