5 Commits
0.1.0 ... 0.2.0

Author SHA1 Message Date
Florian Kaiser
a54fb55b91 0.2.0
- added more light functions
- added docstrings for functions
2020-11-29 22:41:09 +01:00
Florian Kaiser
0bf55f756b delete demo 2020-11-29 22:32:02 +01:00
Florian K
2a5afd7cb0 Merge pull request #2 from flok/examples
- examples
- verbose mode
2020-11-29 19:47:57 +01:00
Florian Kaiser
0a6fee2f85 Reference example in README 2020-11-29 19:44:53 +01:00
Florian Kaiser
2f5579cc49 Examples, closing controller HID device on close function 2020-11-29 19:40:37 +01:00
7 changed files with 111 additions and 63 deletions

View File

@@ -1,5 +1,5 @@
# pydualsense # pydualsense
control your dualsense through python. using the hid library this module implements the sending report for controlling you new PS5 controller. It creates a background thread to constantly update the controller. control your dualsense through python. using the hid library this module implements the sending report for controlling you new PS5 controller. It creates a background thread to constantly receive and update the controller.
# install # install
@@ -10,6 +10,8 @@ pip install pydualsense
``` ```
# usage # usage
```python ```python
from pydualsense import pydualsense from pydualsense import pydualsense
@@ -20,6 +22,10 @@ ds.setLeftTriggerMode(TriggerModes.Rigid)
ds.setLeftTriggerForce(1, 255) ds.setLeftTriggerForce(1, 255)
ds.close() # closing the controller ds.close() # closing the controller
``` ```
See ``examples`` folder for some more ideas
# dependecies # dependecies
- hid >= 1.0.4 - hid >= 1.0.4

15
examples/leds.py Normal file
View File

@@ -0,0 +1,15 @@
from pydualsense import *
# get dualsense instance
dualsense = pydualsense()
# set color around touchpad to red
dualsense.setColor(0,0,255)
# enable microphone indicator
dualsense.setMicrophoneLED(1)
# set all player indicators on
dualsense.setPlayer(PlayerID.all)
# sleep a little to see the result on the controller
# this is not needed in normal usage
import time; time.sleep(2)
# terminate the thread for message and close the device
dualsense.close()

View File

@@ -0,0 +1,12 @@
from pydualsense import *
# get dualsense instance
dualsense = pydualsense()
# set left trigger mode to rigid and put some force values on it
dualsense.setLeftTriggerMode(TriggerModes.Rigid)
dualsense.setLeftTriggerForce(1, 255)
# sleep a little to see the result on the controller
# this is not needed in normal usage
import time; time.sleep(2)
# terminate the thread for message and close the device
dualsense.close()

View File

@@ -25,12 +25,12 @@ class PlayerID(IntFlag):
all = 31 all = 31
class TriggerModes(IntFlag): class TriggerModes(IntFlag):
Off =0x0, # no resistance Off = 0x0, # no resistance
Rigid =0x1, # continous resistance Rigid = 0x1, # continous resistance
Pulse =0x2, # section resistance Pulse = 0x2, # section resistance
Rigid_A=0x1 | 0x20, Rigid_A = 0x1 | 0x20,
Rigid_B=0x1 | 0x04, Rigid_B = 0x1 | 0x04,
Rigid_AB=0x1 | 0x20 | 0x04, Rigid_AB = 0x1 | 0x20 | 0x04,
Pulse_A = 0x2 | 0x20, Pulse_A = 0x2 | 0x20,
Pulse_B = 0x2 | 0x04, Pulse_B = 0x2 | 0x04,
Pulse_AB = 0x2 | 0x20 | 0x04, Pulse_AB = 0x2 | 0x20 | 0x04,

View File

@@ -1,34 +0,0 @@
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from interface import Ui_MainWindow
from pydualsense import pydualsense
def colorR(value):
global colorR
colorR = value
def colorG(value):
global colorG
colorG = value
def colorB(value):
global colorB
colorB = value
def send():
ds.setColor(colorR, colorG, colorB)
ds.sendReport()
if __name__ == "__main__":
global ds
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
ds = pydualsense()
# connect interface to
ui.slider_r.valueChanged.connect(colorR)
ui.slider_g.valueChanged.connect(colorG)
ui.slider_b.valueChanged.connect(colorB)
ui.pushButton.clicked.connect(send)
MainWindow.show()
sys.exit(app.exec_())

View File

@@ -5,9 +5,14 @@ import threading
class pydualsense: class pydualsense:
def __init__(self) -> None: def __init__(self, verbose: bool = False) -> None:
# TODO: maybe add a init function to not automatically allocate controller when class is declared # TODO: maybe add a init function to not automatically allocate controller when class is declared
self.verbose = verbose
self.device: hid.Device = self.__find_device() self.device: hid.Device = self.__find_device()
self.light = DSLight() # control led light of ds self.light = DSLight() # control led light of ds
self.audio = DSAudio() self.audio = DSAudio()
self.triggerL = DSTrigger() self.triggerL = DSTrigger()
@@ -15,6 +20,7 @@ class pydualsense:
self.color = (0,0,255) # set color around touchpad to blue self.color = (0,0,255) # set color around touchpad to blue
self.receive_buffer_size = 64 self.receive_buffer_size = 64
self.send_report_size = 48 self.send_report_size = 48
# controller states # controller states
@@ -28,6 +34,7 @@ class pydualsense:
def close(self): def close(self):
self.ds_thread = False self.ds_thread = False
self.report_thread.join() self.report_thread.join()
self.device.close()
def __find_device(self): def __find_device(self):
devices = hid.enumerate(vid=0x054c) devices = hid.enumerate(vid=0x054c)
@@ -46,12 +53,6 @@ class pydualsense:
return dual_sense return dual_sense
# color stuff
def setColor(self, r: int, g:int, b:int):
if r > 255 or g > 255 or b > 255:
raise Exception('colors have values from 0 to 255 only')
self.color = (r,g,b)
# right trigger # right trigger
def setRightTriggerMode(self, mode: TriggerModes): def setRightTriggerMode(self, mode: TriggerModes):
@@ -102,8 +103,56 @@ class pydualsense:
# TODO: audio # TODO: audio
# audio stuff # audio stuff
def setMicrophoneLED(self, value): def setMicrophoneLED(self, value):
self.audio.microphoneLED = value self.audio.microphone_led = value
# color stuff
def setColor(self, r: int, g:int, b:int):
"""sets the led colour around the touchpad
:param r: red channel, 0..255
:type r: int
:param g: green channel, 0..255
:type g: int
:param b: blue channel, 0..255
:type b: int
:raises Exception: wron color values
"""
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.color = (r,g,b)
def setLEDOption(self, option: LedOptions):
"""set led option
:param option: led option
:type option: LedOptions
"""
self.light.ledOption = option
def setPulseOption(self, option: PulseOptions):
"""set the pulse option for the leds
:param option: [description]
:type option: PulseOptions
"""
self.light.pulseOptions = option
def setBrightness(self, brightness: Brightness):
"""set the brightness of the player leds
:param brightness: brightness for the leds
:type brightness: Brightness
"""
self.light.brightness = brightness
def setPlayerID(self, player : PlayerID):
"""set the player ID. The controller has 5 white LED which signals
which player the controller is
:param player: the player id from 1 to 5
:type player: PlayerID
"""
self.light.playerNumber = player
def sendReport(self): def sendReport(self):
"""background thread handling the reading of the device and updating its states """background thread handling the reading of the device and updating its states
@@ -189,7 +238,6 @@ class pydualsense:
# TODO: control mouse with touchpad for fun as DS4Windows # TODO: control mouse with touchpad for fun as DS4Windows
def writeReport(self, outReport): def writeReport(self, outReport):
"""Write the given report to the device """Write the given report to the device
@@ -231,7 +279,7 @@ class pydualsense:
# 0x80 ??? # 0x80 ???
outReport[2] = 0x1 | 0x2 | 0x4 | 0x10 | 0x40 # [2] outReport[2] = 0x1 | 0x2 | 0x4 | 0x10 | 0x40 # [2]
outReport[3]= 0 # left low freq motor 0-255 # [3] outReport[3] = 0 # left low freq motor 0-255 # [3]
outReport[4] = 0 # right low freq motor 0-255 # [4] outReport[4] = 0 # right low freq motor 0-255 # [4]
# outReport[5] - outReport[8] audio related # outReport[5] - outReport[8] audio related
@@ -265,7 +313,8 @@ class pydualsense:
outReport[45] = self.color[0] outReport[45] = self.color[0]
outReport[46] = self.color[1] outReport[46] = self.color[1]
outReport[47] = self.color[2] outReport[47] = self.color[2]
if self.verbose:
print(outReport)
return outReport return outReport
class DSTouchpad: class DSTouchpad:

View File

@@ -6,7 +6,7 @@ with open("README.md", "r") as fh:
setup( setup(
name='pydualsense', name='pydualsense',
version='0.1.0', version='0.2.0',
description='use your DualSense (PS5) controller with python', description='use your DualSense (PS5) controller with python',
long_description=long_description, long_description=long_description,
long_description_content_type="text/markdown", long_description_content_type="text/markdown",