Merge pull request #6 from flok/examples

Examples
This commit is contained in:
Florian K
2020-12-22 15:12:05 +01:00
committed by GitHub
7 changed files with 60 additions and 14 deletions

View File

@@ -35,8 +35,10 @@ Help wanted from people that want to use this and have feature requests. Just op
# Credits
Most stuff for this implementation were provided by and used from:
- [https://www.reddit.com/r/gamedev/comments/jumvi5/dualsense_haptics_leds_and_more_hid_output_report/](https://www.reddit.com/r/gamedev/comments/jumvi5/dualsense_haptics_leds_and_more_hid_output_report/)
- [https://github.com/Ryochan7/DS4Windows](https://github.com/Ryochan7/DS4Windows)

15
examples/README.md Normal file
View File

@@ -0,0 +1,15 @@
# Examples
This folder contains some examples on applications for the library and its usage
## leds.py
The leds.py shows you how you can interact and change the lights of the controller
## effects.py
The effects.py show some effects of the controller
## read_controller.py
The read_controller.py display how you can access the button state of the controller

22
examples/effects.py Normal file
View File

@@ -0,0 +1,22 @@
from pydualsense import *
# get dualsense instance
dualsense = pydualsense()
dualsense.init()
print('Trigger Effect demo started')
dualsense.setLeftMotor(255)
dualsense.setRightMotor(100)
dualsense.setLeftTriggerMode(TriggerModes.Rigid)
dualsense.setLeftTriggerForce(1, 255)
dualsense.setRightTriggerMode(TriggerModes.Pulse_A)
dualsense.setRightTriggerForce(0, 200)
dualsense.setRightTriggerForce(1, 255)
dualsense.setRightTriggerForce(2, 175)
import time; time.sleep(3)
# terminate the thread for message and close the device
dualsense.close()

View File

@@ -2,12 +2,13 @@ from pydualsense import *
# get dualsense instance
dualsense = pydualsense()
dualsense.init()
# set color around touchpad to red
dualsense.setColor(0,0,255)
# enable microphone indicator
dualsense.setMicrophoneLED(1)
# set all player indicators on
dualsense.setPlayer(PlayerID.all)
dualsense.setPlayerID(PlayerID.all)
# sleep a little to see the result on the controller
# this is not needed in normal usage
import time; time.sleep(2)

View File

@@ -0,0 +1,15 @@
from pydualsense import *
# create dualsense
dualsense = pydualsense()
# find device and initialize
dualsense.init()
# read controller state until R1 is pressed
while not dualsense.state.R1:
print(f"Circle : {dualsense.state.circle} Cross : {dualsense.state.cross} L Stick X : {dualsense.state.LX} L Stick Y : {dualsense.state.LY}")
# close device
dualsense.close()

View File

@@ -1,12 +0,0 @@
from pydualsense import *
# get dualsense instance
dualsense = pydualsense()
# set left trigger mode to rigid and put some force values on it
dualsense.setLeftTriggerMode(TriggerModes.Rigid)
dualsense.setLeftTriggerForce(1, 255)
# 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()

View File

@@ -13,6 +13,7 @@ class pydualsense:
self.receive_buffer_size = 64
self.send_report_size = 48
self.color = (0,0,255) # set color around touchpad to blue
self.leftMotor = 0
self.rightMotor = 0
@@ -82,11 +83,13 @@ class pydualsense:
raise Exception('maximum intensity is 255')
self.leftMotor = intensity
def setRightMotor(self, intensity: int):
if intensity > 255:
raise Exception('maximum intensity is 255')
self.rightMotor = intensity
# right trigger
def setRightTriggerMode(self, mode: TriggerModes):
"""set the trigger mode for R2