9 Commits

Author SHA1 Message Date
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
6 changed files with 52 additions and 17 deletions

View File

@@ -30,7 +30,7 @@ Help wanted from people that want to use this and have feature requests. Just op
# dependecies
- hid >= 1.0.4
- hidapi-usb >= 0.2.6
# Credits

View File

@@ -5,8 +5,8 @@ dualsense = pydualsense()
dualsense.init()
# set color around touchpad to red
dualsense.light.setColorI(255,0,0)
# enable microphone indicator
dualsense.audio.setMicrophoneLED(1)
# mute microphone
dualsense.audio.setMicrophoneMute(True)
# set all player 1 indicator on
dualsense.light.setPlayerID(PlayerID.player1)
# sleep a little to see the result on the controller

View File

@@ -1,5 +1,8 @@
from enum import IntFlag
class ConnectionType(IntFlag):
BT = 0x0,
USB = 0x1
class LedOptions(IntFlag):
Off=0x0,
PlayerLedBrightness=0x1,

View File

@@ -13,6 +13,6 @@ def check_hide() -> bool:
return True
return False
except OSError as e:
print(e)
pass
return False

View File

@@ -1,19 +1,19 @@
# needed for python > 3.8
import os, sys
if sys.platform.startswith('win32') and sys.version_info >= (3,8):
from sys import platform
if platform.startswith('Windows') 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) # type: ignore
import threading
class pydualsense:
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
self.leftMotor = 0
self.rightMotor = 0
@@ -30,12 +30,31 @@ class pydualsense:
self.state = DSState() # controller states
if platform.startswith('Windows'):
self.conType = self.determineConnectionType() # determine USB or BT connection
else:
# set for usb manually
self.input_report_length = 64
self.output_report_length = 64
# thread for receiving and sending
self.ds_thread = True
self.report_thread = threading.Thread(target=self.sendReport)
self.report_thread.start()
def determineConnectionType(self) -> ConnectionType:
if self.device._device.input_report_length == 64:
self.input_report_length = 64
self.output_report_length = 64
return ConnectionType.USB
elif self.device._device.input_report_length == 78:
self.input_report_length = 78
self.output_report_length = 78
return ConnectionType.BT
def close(self):
"""
Stops the report thread and closes the HID device
@@ -117,10 +136,10 @@ class pydualsense:
"""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:
print(inReport)
# decrypt the packet and bind the inputs
self.readInput(inReport)
@@ -173,6 +192,7 @@ 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
@@ -215,7 +235,8 @@ class pydualsense:
Returns:
list: report to send to controller
"""
outReport = [0] * 48 # create empty list with range of output report
outReport = [0] * self.output_report_length # create empty list with range of output report
# packet type
outReport[0] = 0x2
@@ -249,6 +270,8 @@ class pydualsense:
# set Micrphone LED, setting doesnt effect microphone settings
outReport[9] = self.audio.microphone_led # [9]
outReport[10] = 0x10 if self.audio.microphone_mute == True else 0x00
# add right trigger mode + parameters to packet
outReport[11] = self.triggerR.mode.value
outReport[12] = self.triggerR.forces[0]
@@ -470,15 +493,24 @@ 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 setMicrophoneMute(self, state):
if not isinstance(state, bool):
raise TypeError('state needs to be bool')
self.setMicrophoneLED(state) # set led accordingly
self.microphone_mute = state
class DSTrigger:
def __init__(self) -> None:
# trigger modes

View File

@@ -6,7 +6,7 @@ with open("README.md", "r") as fh:
setup(
name='pydualsense',
version='0.5.0',
version='0.5.5',
description='use your DualSense (PS5) controller with python',
long_description=long_description,
long_description_content_type="text/markdown",
@@ -14,5 +14,5 @@ setup(
author='Florian K',
license='MIT License',
packages=setuptools.find_packages(),
install_requires=['hidapi-usb']
install_requires=['hidapi-usb>=0.3', 'cffi']
)