Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
32f9042abb | ||
|
4c86d71633 | ||
|
9c79d961f1 | ||
|
c1c10e4eac | ||
|
04ce807bc0 | ||
|
71a49da5d2 | ||
|
f4e1d73dd3 | ||
|
e766dca70f | ||
|
1e0b23da41 | ||
|
ff01788c89 | ||
|
c07b975bc5 | ||
|
7b0270fa7d | ||
|
d76717c163 | ||
|
786657cc90 | ||
|
11e78fbece | ||
|
a3f697866b | ||
|
1530c79dd7 | ||
|
83a37750d1 | ||
|
bc0eb35c3c |
21
.github/workflows/python-mypy.yml
vendored
21
.github/workflows/python-mypy.yml
vendored
@@ -1,21 +0,0 @@
|
|||||||
name: Mypy
|
|
||||||
|
|
||||||
on: [push]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Mypy
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v2
|
|
||||||
with:
|
|
||||||
python-version: '3.x'
|
|
||||||
- name: Install Dependencies
|
|
||||||
run: |
|
|
||||||
python -m pip install --upgrade pip
|
|
||||||
pip install mypy
|
|
||||||
- name: mypy
|
|
||||||
run: |
|
|
||||||
mypy pydualsense/
|
|
3
.gitignore
vendored
3
.gitignore
vendored
@@ -149,6 +149,9 @@ dmypy.json
|
|||||||
!.vscode/extensions.json
|
!.vscode/extensions.json
|
||||||
*.code-workspace
|
*.code-workspace
|
||||||
|
|
||||||
|
### pycharm ###
|
||||||
|
.idea/*
|
||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/python,vscode
|
# End of https://www.toptal.com/developers/gitignore/api/python,vscode
|
||||||
|
|
||||||
pydualsense/interface.py
|
pydualsense/interface.py
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
# 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 receive and update the controller.
|
control your dualsense through python. using the hid library this package implements the report features for controlling your new PS5 controller.
|
||||||
|
|
||||||
# install
|
# install
|
||||||
|
|
||||||
Just install the package from [pypi](https://pypi.org/project/pydualsense/)
|
Download [hidapi](https://github.com/libusb/hidapi/releases) and place the x64 .dll file into your Workspace. After that install the package from [pypi](https://pypi.org/project/pydualsense/).
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install pydualsense
|
pip install pydualsense
|
||||||
@@ -12,7 +12,7 @@ pip install pydualsense
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
|
|
||||||
from pydualsense import pydualsense
|
from pydualsense import pydualsense, TriggerModes
|
||||||
|
|
||||||
ds = pydualsense() # open controller
|
ds = pydualsense() # open controller
|
||||||
ds.init() # initialize controller
|
ds.init() # initialize controller
|
||||||
@@ -22,7 +22,7 @@ ds.triggerL.setForce(1, 255)
|
|||||||
ds.close() # closing the controller
|
ds.close() # closing the controller
|
||||||
```
|
```
|
||||||
|
|
||||||
See ``examples`` folder for some more ideas
|
See [examples](https://github.com/flok/pydualsense/tree/master/examples) folder for some more ideas
|
||||||
|
|
||||||
# Help wanted
|
# Help wanted
|
||||||
|
|
||||||
|
18
pydualsense/hidguardian.py
Normal file
18
pydualsense/hidguardian.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import winreg
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def check_hide() -> bool:
|
||||||
|
"""check if hidguardian is used and controller is hidden
|
||||||
|
"""
|
||||||
|
if sys.platform.startswith('win32'):
|
||||||
|
try:
|
||||||
|
access_reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
|
||||||
|
access_key = winreg.OpenKey(access_reg, 'SYSTEM\CurrentControlSet\Services\HidGuardian\Parameters', 0, winreg.KEY_READ)
|
||||||
|
affected_devices = winreg.QueryValueEx(access_key, 'AffectedDevices')[0]
|
||||||
|
if "054C" in affected_devices and "0CE6" in affected_devices:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
except OSError as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
return False
|
@@ -1,10 +1,12 @@
|
|||||||
from os import device_encoding
|
|
||||||
import hid # type: ignore
|
# needed for python > 3.8
|
||||||
from .enums import (LedOptions, PlayerID,
|
import os, sys
|
||||||
PulseOptions, TriggerModes, Brightness)
|
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
|
||||||
import threading
|
import threading
|
||||||
import sys
|
|
||||||
import winreg
|
|
||||||
class pydualsense:
|
class pydualsense:
|
||||||
|
|
||||||
def __init__(self, verbose: bool = False) -> None:#
|
def __init__(self, verbose: bool = False) -> None:#
|
||||||
@@ -20,7 +22,7 @@ class pydualsense:
|
|||||||
def init(self):
|
def init(self):
|
||||||
"""initialize module and device states
|
"""initialize module and device states
|
||||||
"""
|
"""
|
||||||
self.device: hid.Device = self.__find_device()
|
self.device: hidapi.Device = self.__find_device()
|
||||||
self.light = DSLight() # control led light of ds
|
self.light = DSLight() # control led light of ds
|
||||||
self.audio = DSAudio() # ds audio setting
|
self.audio = DSAudio() # ds audio setting
|
||||||
self.triggerL = DSTrigger() # left trigger
|
self.triggerL = DSTrigger() # left trigger
|
||||||
@@ -34,8 +36,6 @@ class pydualsense:
|
|||||||
self.report_thread = threading.Thread(target=self.sendReport)
|
self.report_thread = threading.Thread(target=self.sendReport)
|
||||||
self.report_thread.start()
|
self.report_thread.start()
|
||||||
|
|
||||||
self.init = True
|
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""
|
"""
|
||||||
Stops the report thread and closes the HID device
|
Stops the report thread and closes the HID device
|
||||||
@@ -44,24 +44,8 @@ class pydualsense:
|
|||||||
self.report_thread.join()
|
self.report_thread.join()
|
||||||
self.device.close()
|
self.device.close()
|
||||||
|
|
||||||
def _check_hide(self) -> bool:
|
|
||||||
"""check if hidguardian is used and controller is hidden
|
|
||||||
"""
|
|
||||||
if sys.platform.startswith('win32'):
|
|
||||||
try:
|
|
||||||
access_reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
|
|
||||||
access_key = winreg.OpenKey(access_reg, 'SYSTEM\CurrentControlSet\Services\HidGuardian\Parameters', 0, winreg.KEY_READ)
|
|
||||||
affected_devices = winreg.QueryValueEx(access_key, 'AffectedDevices')[0]
|
|
||||||
if "054C" in affected_devices and "0CE6" in affected_devices:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
except OSError as e:
|
|
||||||
print(e)
|
|
||||||
|
|
||||||
return False
|
def __find_device(self) -> hidapi.Device:
|
||||||
|
|
||||||
|
|
||||||
def __find_device(self) -> hid.Device:
|
|
||||||
"""
|
"""
|
||||||
find HID device and open it
|
find HID device and open it
|
||||||
|
|
||||||
@@ -74,19 +58,21 @@ class pydualsense:
|
|||||||
"""
|
"""
|
||||||
# TODO: detect connection mode, bluetooth has a bigger write buffer
|
# TODO: detect connection mode, bluetooth has a bigger write buffer
|
||||||
# TODO: implement multiple controllers working
|
# TODO: implement multiple controllers working
|
||||||
if self._check_hide():
|
if sys.platform.startswith('win32'):
|
||||||
raise Exception('HIDGuardian detected. Delete the controller from HIDGuardian and restart PC to connect to controller')
|
import pydualsense.hidguardian as hidguardian
|
||||||
detected_device: hid.Device = None
|
if hidguardian.check_hide():
|
||||||
devices = hid.enumerate(vid=0x054c)
|
raise Exception('HIDGuardian detected. Delete the controller from HIDGuardian and restart PC to connect to controller')
|
||||||
|
detected_device: hidapi.Device = None
|
||||||
|
devices = hidapi.enumerate(vendor_id=0x054c)
|
||||||
for device in devices:
|
for device in devices:
|
||||||
if device['vendor_id'] == 0x054c and device['product_id'] == 0x0CE6:
|
if device.vendor_id == 0x054c and device.product_id == 0x0CE6:
|
||||||
detected_device = device
|
detected_device = device
|
||||||
|
|
||||||
|
|
||||||
if detected_device == None:
|
if detected_device == None:
|
||||||
raise Exception('No device detected')
|
raise Exception('No device detected')
|
||||||
|
|
||||||
dual_sense = hid.Device(vid=detected_device['vendor_id'], pid=detected_device['product_id'])
|
dual_sense = hidapi.Device(vendor_id=detected_device.vendor_id, product_id=detected_device.product_id)
|
||||||
return dual_sense
|
return dual_sense
|
||||||
|
|
||||||
def setLeftMotor(self, intensity: int):
|
def setLeftMotor(self, intensity: int):
|
||||||
@@ -134,7 +120,7 @@ class pydualsense:
|
|||||||
|
|
||||||
# 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.receive_buffer_size)
|
||||||
|
print(inReport)
|
||||||
# decrypt the packet and bind the inputs
|
# decrypt the packet and bind the inputs
|
||||||
self.readInput(inReport)
|
self.readInput(inReport)
|
||||||
|
|
||||||
@@ -534,4 +520,4 @@ class DSTrigger:
|
|||||||
if not isinstance(mode, TriggerModes):
|
if not isinstance(mode, TriggerModes):
|
||||||
raise TypeError('Trigger mode parameter needs to be of type `TriggerModes`')
|
raise TypeError('Trigger mode parameter needs to be of type `TriggerModes`')
|
||||||
|
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
|
4
setup.py
4
setup.py
@@ -6,7 +6,7 @@ with open("README.md", "r") as fh:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='pydualsense',
|
name='pydualsense',
|
||||||
version='0.4.1',
|
version='0.5.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",
|
||||||
@@ -14,5 +14,5 @@ setup(
|
|||||||
author='Florian K',
|
author='Florian K',
|
||||||
license='MIT License',
|
license='MIT License',
|
||||||
packages=setuptools.find_packages(),
|
packages=setuptools.find_packages(),
|
||||||
install_requires=['hid>=1.0.4']
|
install_requires=['hidapi-usb']
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user