Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
de894fca7e | ||
|
1b06033d4c | ||
|
4105048784 | ||
|
e2c16cd29e | ||
|
3b3ec445ad | ||
|
dc14382b62 | ||
|
bda77189f7 | ||
|
d34302b494 | ||
|
a808741b7f | ||
|
6f7413ecad | ||
|
7c79dc5fbf | ||
|
98271e866f | ||
|
caa2062cea | ||
|
9359e6eac4 | ||
|
c54f58bcee |
4
.github/workflows/docs_publish.yml
vendored
4
.github/workflows/docs_publish.yml
vendored
@@ -1,5 +1,5 @@
|
||||
name: publish_docs
|
||||
on: [push, pull_request, workflow_dispatch]
|
||||
on: [push, workflow_dispatch]
|
||||
jobs:
|
||||
docs:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -19,4 +19,4 @@ jobs:
|
||||
publish_branch: gh-pages
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: docs/build/
|
||||
force_orphan: true
|
||||
force_orphan: true
|
||||
|
11
70-ps5-controller.rules
Normal file
11
70-ps5-controller.rules
Normal file
@@ -0,0 +1,11 @@
|
||||
# ref.: https://boilingsteam.com/the-dualsense-is-making-even-more-sense/
|
||||
# copy this file to /etc/udev/rules.d
|
||||
# reload udev rules with:
|
||||
# udevadm control --reload-rules
|
||||
# udevadm trigger
|
||||
|
||||
# PS5 DualSense controller over USB hidraw
|
||||
KERNEL=="hidraw*", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="0ce6", MODE="0660", TAG+="uaccess"
|
||||
|
||||
# PS5 DualSense controller over bluetooth hidraw
|
||||
KERNEL=="hidraw*", KERNELS=="*054C:0CE6*", MODE="0660", TAG+="uaccess"
|
10
README.md
10
README.md
@@ -17,7 +17,15 @@ pip install --upgrade pydualsense
|
||||
|
||||
## Linux
|
||||
|
||||
On Linux based system you first need to install the hidapi through your package manager of your system.
|
||||
On Linux based system you first need to add a udev rule to let the user access the PS5 controller without requiring root privileges.
|
||||
|
||||
```bash
|
||||
sudo cp 70-ps5-controller.rules /etc/udev/rules.d
|
||||
sudo udevadm control --reload-rules
|
||||
sudo udevadm trigger
|
||||
```
|
||||
|
||||
Then install the hidapi through your package manager of your system.
|
||||
|
||||
On an Ubuntu system the package ```libhidapi-dev``` is required.
|
||||
|
||||
|
@@ -6,4 +6,5 @@ This is the front page for the API documentation of the **pydualsense** library.
|
||||
|
||||
.. toctree::
|
||||
ds_enum
|
||||
ds_main
|
||||
ds_main
|
||||
ds_eventsystem
|
10
docs/source/ds_eventsystem.rst
Normal file
10
docs/source/ds_eventsystem.rst
Normal file
@@ -0,0 +1,10 @@
|
||||
pydualsense event system classes
|
||||
=========================
|
||||
|
||||
The `Event System` implements the event system used for the button callbacks
|
||||
|
||||
.. automodule:: pydualsense.event_system
|
||||
:noindex:
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
@@ -17,6 +17,7 @@ Contents
|
||||
usage
|
||||
api
|
||||
examples
|
||||
modules
|
||||
|
||||
|
||||
TODOs
|
||||
|
@@ -8,9 +8,9 @@ dualsense.light.setColorI(255,0,0)
|
||||
# mute microphone
|
||||
dualsense.audio.setMicrophoneState(True)
|
||||
# set all player 1 indicator on
|
||||
dualsense.light.setPlayerID(PlayerID.player1)
|
||||
dualsense.light.setPlayerID(PlayerID.PLAYER_1)
|
||||
# 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()
|
||||
dualsense.close()
|
||||
|
53
examples/read_all_input_channels.py
Normal file
53
examples/read_all_input_channels.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import curses
|
||||
import time
|
||||
from pydualsense import *
|
||||
|
||||
|
||||
def print_states(stdscr):
|
||||
curses.curs_set(0)
|
||||
curses.use_default_colors()
|
||||
stdscr.nodelay(1)
|
||||
while True:
|
||||
stdscr.erase()
|
||||
pretty_states = [f"{state:03}" for state in dualsense.states]
|
||||
|
||||
stdscr.addstr(f"epoch: {time.time():.2f}\n")
|
||||
stdscr.addstr(f"states[0:10]: {pretty_states[0:10]}\n")
|
||||
stdscr.addstr(f"states[10:20]: {pretty_states[10:20]}\n")
|
||||
stdscr.addstr(f"states[20:30]: {pretty_states[20:30]}\n")
|
||||
stdscr.addstr(f"states[30:40]: {pretty_states[30:40]}\n")
|
||||
stdscr.addstr(f"states[40:50]: {pretty_states[40:50]}\n")
|
||||
stdscr.addstr(f"states[50:60]: {pretty_states[50:60]}\n")
|
||||
stdscr.addstr(f"states[60:70]: {pretty_states[60:70]}\n")
|
||||
stdscr.addstr(f"states[70:78]: {pretty_states[70:78]}\n")
|
||||
stdscr.addstr("\n")
|
||||
stdscr.addstr(f"square: {dualsense.state.square!s:>5} \t triangle: {dualsense.state.triangle!s:>5} \t circle: {dualsense.state.circle!s:>5} \t cross: {dualsense.state.cross!s:>5}\n")
|
||||
stdscr.addstr(f"DpadUp: {dualsense.state.DpadUp!s:>5} \t DpadDown: {dualsense.state.DpadDown!s:>5} \t DpadLeft: {dualsense.state.DpadLeft!s:>5} \t DpadRight: {dualsense.state.DpadRight!s:>5}\n")
|
||||
stdscr.addstr(f"L1: {dualsense.state.L1!s:>5} \t L2: {dualsense.state.L2:3} \t L2Btn: {dualsense.state.L2Btn!s:>5} \t L3: {dualsense.state.L3!s:>5} \t R1: {dualsense.state.R1!s:>5} \t R2: {dualsense.state.R2:3d} \t R2Btn: {dualsense.state.R2Btn!s:>5} \t R3: {dualsense.state.R3!s:>5}\n")
|
||||
stdscr.addstr(f"share: {dualsense.state.share!s:>5} \t options: {dualsense.state.options!s:>5} \t ps: {dualsense.state.ps!s:>5} \t touch1: {dualsense.state.touch1!s:>5} \t touch2: {dualsense.state.touch2!s:>5} \t touchBtn: {dualsense.state.touchBtn!s:>5} \t touchRight: {dualsense.state.touchRight!s:>5} \t touchLeft: {dualsense.state.touchLeft!s:>5}\n")
|
||||
stdscr.addstr(f"touchFinger1: {dualsense.state.touchFinger1} \t touchFinger2: {dualsense.state.touchFinger2}\n")
|
||||
stdscr.addstr(f"micBtn: {dualsense.state.micBtn!s:>5}\n")
|
||||
stdscr.addstr(f"RX: {dualsense.state.RX:4} \t RY: {dualsense.state.RY:4} \t LX: {dualsense.state.LX:4} \t LY: {dualsense.state.LY:4}\n")
|
||||
stdscr.addstr(f"trackPadTouch0: ID: {dualsense.state.trackPadTouch0.ID} \t isActive: {dualsense.state.trackPadTouch0.isActive!s:>5} \t X: {dualsense.state.trackPadTouch0.X:4d} \t Y: {dualsense.state.trackPadTouch0.Y:4d}\n")
|
||||
stdscr.addstr(f"trackPadTouch1: ID: {dualsense.state.trackPadTouch1.ID} \t isActive: {dualsense.state.trackPadTouch1.isActive!s:>5} \t X: {dualsense.state.trackPadTouch1.X:4d} \t Y: {dualsense.state.trackPadTouch1.Y:4d}\n")
|
||||
stdscr.addstr(f"gyro: roll: {dualsense.state.gyro.Roll:6} \t pitch: {dualsense.state.gyro.Pitch:6} \t yaw: {dualsense.state.gyro.Yaw:6}\n")
|
||||
stdscr.addstr(f"acc: X: {dualsense.state.accelerometer.X:6} \t Y: {dualsense.state.accelerometer.Y:6} \t Z: {dualsense.state.accelerometer.Z:6}\n")
|
||||
stdscr.addstr("\n")
|
||||
stdscr.addstr("Exit script with 'q'\n")
|
||||
|
||||
stdscr.refresh()
|
||||
if stdscr.getch() == ord('q'):
|
||||
break
|
||||
|
||||
|
||||
dualsense = pydualsense()
|
||||
dualsense.init()
|
||||
|
||||
while dualsense.states is None:
|
||||
print("Waiting until connection is established...")
|
||||
print(f"epoch: {time.time():.0f}")
|
||||
time.sleep(0.5)
|
||||
|
||||
|
||||
curses.wrapper(print_states)
|
||||
dualsense.close()
|
@@ -98,33 +98,34 @@ class pydualsense:
|
||||
self.triggerL = DSTrigger() # left trigger
|
||||
self.triggerR = DSTrigger() # right trigger
|
||||
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
|
||||
|
||||
self.conType = self.determineConnectionType() # determine USB or BT connection
|
||||
self.ds_thread = True
|
||||
self.report_thread = threading.Thread(target=self.sendReport)
|
||||
self.report_thread.start()
|
||||
self.states = None
|
||||
|
||||
def determineConnectionType(self) -> ConnectionType:
|
||||
"""
|
||||
Determine the connection type of the controller. eg USB or BT.
|
||||
|
||||
Currently only USB is supported.
|
||||
We ask the controller for an input report with a length up to 100 bytes
|
||||
and afterwords check the lenght of the received input report.
|
||||
The connection type determines the length of the report.
|
||||
|
||||
This way of determining is not pretty but it works..
|
||||
|
||||
Returns:
|
||||
ConnectionType: Detected connection type of the controller.
|
||||
"""
|
||||
|
||||
if self.device._device.input_report_length == 64:
|
||||
dummy_report = self.device.read(100)
|
||||
input_report_length = len(dummy_report)
|
||||
|
||||
if 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:
|
||||
elif input_report_length == 78:
|
||||
self.input_report_length = 78
|
||||
self.output_report_length = 78
|
||||
return ConnectionType.BT
|
||||
@@ -228,7 +229,15 @@ class pydualsense:
|
||||
Args:
|
||||
inReport (bytearray): read bytearray containing the state of the whole controller
|
||||
"""
|
||||
states = list(inReport) # convert bytes to list
|
||||
if self.conType == ConnectionType.BT:
|
||||
# the reports for BT and USB are structured the same,
|
||||
# but there is one more byte at the start of the bluetooth report.
|
||||
# We drop that byte, so that the format matches up again.
|
||||
states = list(inReport)[1:] # convert bytes to list
|
||||
else: # USB
|
||||
states = list(inReport) # convert bytes to list
|
||||
|
||||
self.states = states
|
||||
# states 0 is always 1
|
||||
self.state.LX = states[1] - 127
|
||||
self.state.LY = states[2] - 127
|
||||
@@ -415,8 +424,8 @@ class pydualsense:
|
||||
# 0x80 ???
|
||||
outReport[2] = 0x1 | 0x2 | 0x4 | 0x10 | 0x40 # [2]
|
||||
|
||||
outReport[3] = self.leftMotor # left low freq motor 0-255 # [3]
|
||||
outReport[4] = self.rightMotor # right low freq motor 0-255 # [4]
|
||||
outReport[3] = self.rightMotor # right low freq motor 0-255 # [3]
|
||||
outReport[4] = self.leftMotor # left low freq motor 0-255 # [4]
|
||||
|
||||
# outReport[5] - outReport[8] audio related
|
||||
|
||||
|
Reference in New Issue
Block a user