fixed structure of the package
added background send thread
added close function for terminating the background thread
This commit is contained in:
Florian Kaiser
2020-11-29 12:49:16 +01:00
parent 78a49d0ee3
commit a55fe59d2b
6 changed files with 95 additions and 79 deletions

2
.gitignore vendored
View File

@@ -151,3 +151,5 @@ dmypy.json
# End of https://www.toptal.com/developers/gitignore/api/python,vscode
pydualsense/interface.py
pydualsense/interface.ui

View File

@@ -1,2 +1,22 @@
# pydualsense
controll your dualsense through python
control your dualsense through python. using the hid library this module implements the sending report for controlling you new PS5 controller. It creates a background thread to constantly update the controller.
# dependecies
- hid >= 1.0.4
# usage
```python
from pydualsense import pydualsense
ds = pydualsense() # open controller
ds.setColor(255,0,0) # set touchpad color to red
ds.close() # closing the controller
```
# Coming soon
- reading the states of the controller to enable a fully compatibility with python
- add documentation

View File

@@ -0,0 +1,2 @@
from .enums import LedOptions,Brightness,PlayerID,PulseOptions,TriggerModes
from .pydualsense import pydualsense, DSAudio, DSLight, DSTrigger

View File

@@ -1,5 +1,4 @@
from enum import Enum, IntFlag
from flags import Flags # bitflag
from enum import IntFlag
class LedOptions(IntFlag):
Off=0x0,

View File

@@ -1,5 +1,5 @@
import hid
from enums import (LedOptions, PlayerID,
from .enums import (LedOptions, PlayerID,
PulseOptions, TriggerModes, Brightness)
import threading
@@ -17,15 +17,19 @@ class pydualsense:
self.color = (0,0,255) # set dualsense color around the touchpad to blue
self.send_thread = True
send_report = threading.Thread(target=self.sendReport)
#send_report.start()
self.report_thread = threading.Thread(target=self.sendReport)
self.report_thread.start()
# create thread for sending
def close(self):
self.send_thread = False
self.report_thread.join()
def __find_device(self):
devices = hid.enumerate(vid=0x054c)
found_devices = []
for device in devices:
if device['vendor_id'] == 0x54c and device['product_id'] == 0xCE6:
if device['vendor_id'] == 0x054c and device['product_id'] == 0x0CE6:
found_devices.append(device)
# TODO: detect connection mode, bluetooth has a bigger write buffer
@@ -98,7 +102,7 @@ class pydualsense:
def sendReport(self):
# while self.send_thread:
while self.send_thread:
outReport = [0] * 48 # create empty list with range of output report
# packet type
outReport[0] = 0x2
@@ -158,16 +162,6 @@ class pydualsense:
outReport[28] = self.triggerL.forces[5]
outReport[31] = self.triggerL.forces[6]
"""
outReport.append(self.light.ledOption.value[0]) #
outReport.append(self.light.pulseOptions.value[0])
outReport.append(self.light.brightness.value[0])
outReport.append(self.light.playerNumber.value[0])
outReport.append(self.color[0]) # r
outReport.append(self.color[1]) # g
outReport.append(self.color[2]) # b
"""
outReport[39] = self.light.ledOption.value
outReport[42] = self.light.pulseOptions.value
outReport[43] = self.light.brightness.value

View File

@@ -6,14 +6,13 @@ with open("README.md", "r") as fh:
setup(
name='pydualsense',
version='0.0.1',
description='control your dualsense controller with python',
version='0.0.4',
description='control your DualSense (PS5) controller with python',
long_description=long_description,
long_description_content_type="text/markdown",
url='https://github.com/flok/pydualsense',
author='Florian Kaiser',
author_email='shudson@anl.gov',
license='BSD 2-clause',
license='MIT License',
packages=setuptools.find_packages(),
install_requires=['hid>=1.0.4']
)