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
This commit is contained in:
@@ -30,7 +30,7 @@ Help wanted from people that want to use this and have feature requests. Just op
|
|||||||
|
|
||||||
# dependecies
|
# dependecies
|
||||||
|
|
||||||
- hid >= 1.0.4
|
- hidapi-usb >= 0.2.6
|
||||||
|
|
||||||
# Credits
|
# Credits
|
||||||
|
|
||||||
|
@@ -5,8 +5,8 @@ dualsense = pydualsense()
|
|||||||
dualsense.init()
|
dualsense.init()
|
||||||
# set color around touchpad to red
|
# set color around touchpad to red
|
||||||
dualsense.light.setColorI(255,0,0)
|
dualsense.light.setColorI(255,0,0)
|
||||||
# enable microphone indicator
|
# mute microphone
|
||||||
dualsense.audio.setMicrophoneLED(1)
|
dualsense.audio.setMicrophoneMute(True)
|
||||||
# set all player 1 indicator on
|
# set all player 1 indicator on
|
||||||
dualsense.light.setPlayerID(PlayerID.player1)
|
dualsense.light.setPlayerID(PlayerID.player1)
|
||||||
# sleep a little to see the result on the controller
|
# sleep a little to see the result on the controller
|
||||||
|
@@ -1,5 +1,8 @@
|
|||||||
from enum import IntFlag
|
from enum import IntFlag
|
||||||
|
|
||||||
|
class ConnectionType(IntFlag):
|
||||||
|
BT = 0x0,
|
||||||
|
USB = 0x1
|
||||||
class LedOptions(IntFlag):
|
class LedOptions(IntFlag):
|
||||||
Off=0x0,
|
Off=0x0,
|
||||||
PlayerLedBrightness=0x1,
|
PlayerLedBrightness=0x1,
|
||||||
|
@@ -13,6 +13,6 @@ def check_hide() -> bool:
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
print(e)
|
pass
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
@@ -5,15 +5,13 @@ if sys.platform.startswith('win32') and sys.version_info >= (3,8):
|
|||||||
os.add_dll_directory(os.getcwd())
|
os.add_dll_directory(os.getcwd())
|
||||||
|
|
||||||
import hidapi
|
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
|
import threading
|
||||||
class pydualsense:
|
class pydualsense:
|
||||||
|
|
||||||
def __init__(self, verbose: bool = False) -> 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.verbose = verbose
|
||||||
self.receive_buffer_size = 64
|
|
||||||
self.send_report_size = 48
|
|
||||||
|
|
||||||
self.leftMotor = 0
|
self.leftMotor = 0
|
||||||
self.rightMotor = 0
|
self.rightMotor = 0
|
||||||
@@ -30,12 +28,26 @@ class pydualsense:
|
|||||||
|
|
||||||
self.state = DSState() # controller states
|
self.state = DSState() # controller states
|
||||||
|
|
||||||
|
self.conType = self.determineConnectionType() # determine USB or BT connection
|
||||||
|
|
||||||
|
|
||||||
# thread for receiving and sending
|
# thread for receiving and sending
|
||||||
self.ds_thread = True
|
self.ds_thread = True
|
||||||
self.report_thread = threading.Thread(target=self.sendReport)
|
self.report_thread = threading.Thread(target=self.sendReport)
|
||||||
self.report_thread.start()
|
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):
|
def close(self):
|
||||||
"""
|
"""
|
||||||
Stops the report thread and closes the HID device
|
Stops the report thread and closes the HID device
|
||||||
@@ -117,9 +129,8 @@ class pydualsense:
|
|||||||
"""background thread handling the reading of the device and updating its states
|
"""background thread handling the reading of the device and updating its states
|
||||||
"""
|
"""
|
||||||
while self.ds_thread:
|
while self.ds_thread:
|
||||||
|
|
||||||
# read data from the input report of the controller
|
# read data from the input report of the controller
|
||||||
inReport = self.device.read(self.receive_buffer_size)
|
inReport = self.device.read(self.input_report_length)
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print(inReport)
|
print(inReport)
|
||||||
# decrypt the packet and bind the inputs
|
# decrypt the packet and bind the inputs
|
||||||
@@ -216,7 +227,8 @@ class pydualsense:
|
|||||||
Returns:
|
Returns:
|
||||||
list: report to send to controller
|
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
|
# packet type
|
||||||
outReport[0] = 0x2
|
outReport[0] = 0x2
|
||||||
|
|
||||||
@@ -250,6 +262,8 @@ class pydualsense:
|
|||||||
# set Micrphone LED, setting doesnt effect microphone settings
|
# set Micrphone LED, setting doesnt effect microphone settings
|
||||||
outReport[9] = self.audio.microphone_led # [9]
|
outReport[9] = self.audio.microphone_led # [9]
|
||||||
|
|
||||||
|
outReport[10] = 0x10 if self.audio.microphone_state == True else 0x00
|
||||||
|
|
||||||
# add right trigger mode + parameters to packet
|
# add right trigger mode + parameters to packet
|
||||||
outReport[11] = self.triggerR.mode.value
|
outReport[11] = self.triggerR.mode.value
|
||||||
outReport[12] = self.triggerR.forces[0]
|
outReport[12] = self.triggerR.forces[0]
|
||||||
@@ -471,15 +485,24 @@ class DSAudio:
|
|||||||
This doesnt change the mute/unmutes the microphone itself.
|
This doesnt change the mute/unmutes the microphone itself.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
value (int): On or off microphone LED
|
value (bool): On or off microphone LED
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
Exception: false state for the led
|
Exception: false state for the led
|
||||||
"""
|
"""
|
||||||
if value > 1 or value < 0:
|
if not isinstance(value, bool):
|
||||||
raise Exception('Microphone LED can only be on or off (0 .. 1)')
|
raise TypeError('MicrophoneLED can only be a bool')
|
||||||
self.microphone_led = value
|
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_state = state
|
||||||
|
|
||||||
|
|
||||||
class DSTrigger:
|
class DSTrigger:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
# trigger modes
|
# trigger modes
|
||||||
|
2
setup.py
2
setup.py
@@ -6,7 +6,7 @@ with open("README.md", "r") as fh:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='pydualsense',
|
name='pydualsense',
|
||||||
version='0.5.1',
|
version='0.5.2',
|
||||||
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",
|
||||||
|
Reference in New Issue
Block a user