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
|
||||
|
||||
- hid >= 1.0.4
|
||||
- hidapi-usb >= 0.2.6
|
||||
|
||||
# Credits
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -1,5 +1,8 @@
|
||||
from enum import IntFlag
|
||||
|
||||
class ConnectionType(IntFlag):
|
||||
BT = 0x0,
|
||||
USB = 0x1
|
||||
class LedOptions(IntFlag):
|
||||
Off=0x0,
|
||||
PlayerLedBrightness=0x1,
|
||||
|
@@ -13,6 +13,6 @@ def check_hide() -> bool:
|
||||
return True
|
||||
return False
|
||||
except OSError as e:
|
||||
print(e)
|
||||
pass
|
||||
|
||||
return False
|
||||
|
@@ -5,15 +5,13 @@ 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) # 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 +28,26 @@ class pydualsense:
|
||||
|
||||
self.state = DSState() # controller states
|
||||
|
||||
self.conType = self.determineConnectionType() # determine USB or BT connection
|
||||
|
||||
|
||||
# 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,9 +129,8 @@ 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)
|
||||
inReport = self.device.read(self.input_report_length)
|
||||
if self.verbose:
|
||||
print(inReport)
|
||||
# decrypt the packet and bind the inputs
|
||||
@@ -216,7 +227,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
|
||||
|
||||
@@ -250,6 +262,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_state == True else 0x00
|
||||
|
||||
# add right trigger mode + parameters to packet
|
||||
outReport[11] = self.triggerR.mode.value
|
||||
outReport[12] = self.triggerR.forces[0]
|
||||
@@ -471,15 +485,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_state = state
|
||||
|
||||
|
||||
class DSTrigger:
|
||||
def __init__(self) -> None:
|
||||
# trigger modes
|
||||
|
Reference in New Issue
Block a user