Skip to content
7 changes: 6 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ The effects.py show some effects of the controller
The read_controller.py display how you can access the button state of the controller

## test_trigger_value.py
The `test_trigger_value.py` show the left / right trigger analog value changing when press button (range from 0 to 255)

The `test_trigger_value.py` show the left / right trigger analog value changing when press button (range from 0 to 255)

## trigger_effects.py

The `trigger_effects.py` set the left / right trigger with a few effects: rigid, weapon and vibration
23 changes: 23 additions & 0 deletions examples/trigger_effects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from pydualsense import pydualsense
import time

dualsense = pydualsense()
dualsense.init()


dualsense.triggerR.setEffect('rigid')
dualsense.triggerL.setEffect('rigid')
time.sleep(5)

dualsense.triggerR.setEffect('weapon')
dualsense.triggerL.setEffect('weapon')
time.sleep(5)

dualsense.triggerR.setEffect('vibration')
dualsense.triggerL.setEffect('vibration')
time.sleep(5)

dualsense.triggerR.setEffect('off')
dualsense.triggerL.setEffect('off')
time.sleep(0.5)
dualsense.close()
44 changes: 44 additions & 0 deletions pydualsense/pydualsense.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,50 @@ def setMode(self, mode: TriggerModes) -> None:

self.mode = mode

def setEffect(self, effect: str) -> None:
"""
Select effect
"""

match effect:
case 'vibration':
self.mode = TriggerModes.Pulse_AB
self.forces[0] = 255
self.forces[1] = 3
self.forces[2] = 255
self.forces[3] = 255
self.forces[4] = 255
self.forces[5] = 63
self.forces[6] = 15
case 'weapon':
self.mode = TriggerModes.Rigid_AB
self.forces[0] = 36
self.forces[1] = 0
self.forces[2] = 7
self.forces[3] = 0
self.forces[4] = 0
self.forces[5] = 0
self.forces[6] = 0
case 'rigid':
self.mode = TriggerModes.Rigid
self.forces[0] = 0
self.forces[1] = 255
self.forces[2] = 0
self.forces[3] = 0
self.forces[4] = 0
self.forces[5] = 0
self.forces[6] = 0
case _:
self.mode = TriggerModes.Off

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we please change the effects from string type to a enum?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, i think now it is easier add new effects in the future:

class TriggersEffects(Enum):
    VIBRATION = (TriggerModes.Pulse_AB, [255, 3, 255, 255, 255, 63, 15]) 
    WEAPON = (TriggerModes.Rigid_AB, [36, 0, 7, 0, 0, 0, 0])  
    RIGID = (TriggerModes.Rigid, [0, 255, 0, 0, 0, 0, 0])  
    OFF = (TriggerModes.Off, [0] * 7)

Also reduce code

    def setEffect(self, effect: TriggersEffects) -> None:
        """
        Select effect
        """
        if not isinstance(effect, TriggersEffects):
            raise TypeError("Triggers effects parameter needs to be of type 'TriggersEffects'")
        
        self.mode, self.forces = effect.value


# force parameters for the triggers
self.forces[0] = 0
self.forces[1] = 0
self.forces[2] = 0
self.forces[3] = 0
self.forces[4] = 0
self.forces[5] = 0
self.forces[6] = 0

class DSGyro:
"""
Expand Down