-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from flok/event_system
Event System and Gyro / Accelerometer support
- Loading branch information
Showing
8 changed files
with
329 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,41 @@ | ||
from pydualsense import * | ||
|
||
|
||
def cross_down(state): | ||
print(f'cross {state}') | ||
|
||
|
||
def circle_down(state): | ||
print(f'circle {state}') | ||
|
||
|
||
def dpad_down(state): | ||
print(f'dpad {state}') | ||
|
||
|
||
def joystick(stateX, stateY): | ||
print(f'lj {stateX} {stateY}') | ||
|
||
|
||
def gyro_changed(pitch, yaw, roll): | ||
print(f'{pitch}, {yaw}, {roll}') | ||
|
||
|
||
# create dualsense | ||
dualsense = pydualsense() | ||
# find device and initialize | ||
dualsense.init() | ||
|
||
# add events handler functions | ||
dualsense.cross_pressed += cross_down | ||
dualsense.circle_pressed += circle_down | ||
dualsense.dpad_down += dpad_down | ||
dualsense.left_joystick_changed += joystick | ||
dualsense.gyro_changed += gyro_changed | ||
|
||
# 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() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from .enums import LedOptions,Brightness,PlayerID,PulseOptions,TriggerModes | ||
from .pydualsense import pydualsense, DSLight, DSState, DSTouchpad, DSTrigger, DSAudio | ||
from .enums import LedOptions, Brightness, PlayerID, PulseOptions, TriggerModes | ||
from .pydualsense import pydualsense, DSLight, DSState, DSTouchpad, DSTrigger, DSAudio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,46 @@ | ||
from enum import IntFlag | ||
|
||
|
||
class ConnectionType(IntFlag): | ||
BT = 0x0, | ||
BT = 0x0 | ||
USB = 0x1 | ||
|
||
|
||
class LedOptions(IntFlag): | ||
Off=0x0, | ||
PlayerLedBrightness=0x1, | ||
UninterrumpableLed=0x2, | ||
Both=0x01 | 0x02 | ||
Off = 0x0 | ||
PlayerLedBrightness = 0x1 | ||
UninterrumpableLed = 0x2 | ||
Both = 0x01 | 0x02 | ||
|
||
|
||
class PulseOptions(IntFlag): | ||
Off=0x0, | ||
FadeBlue=0x1, | ||
FadeOut=0x2 | ||
Off = 0x0 | ||
FadeBlue = 0x1 | ||
FadeOut = 0x2 | ||
|
||
|
||
class Brightness(IntFlag): | ||
high = 0x0, | ||
medium = 0x1, | ||
high = 0x0 | ||
medium = 0x1 | ||
low = 0x2 | ||
|
||
|
||
class PlayerID(IntFlag): | ||
player1 = 4, | ||
player2 = 10, | ||
player3 = 21, | ||
player4 = 27, | ||
all = 31 | ||
PLAYER_1 = 4 | ||
PLAYER_2 = 10 | ||
PLAYER_3 = 21 | ||
PLAYER_4 = 27 | ||
ALL = 31 | ||
|
||
|
||
class TriggerModes(IntFlag): | ||
Off = 0x0, # no resistance | ||
Rigid = 0x1, # continous resistance | ||
Pulse = 0x2, # section resistance | ||
Rigid_A = 0x1 | 0x20, | ||
Rigid_B = 0x1 | 0x04, | ||
Rigid_AB = 0x1 | 0x20 | 0x04, | ||
Pulse_A = 0x2 | 0x20, | ||
Pulse_B = 0x2 | 0x04, | ||
Pulse_AB = 0x2 | 0x20 | 0x04, | ||
Calibration= 0xFC | ||
|
||
Off = 0x0 # no resistance | ||
Rigid = 0x1 # continous resistance | ||
Pulse = 0x2 # section resistance | ||
Rigid_A = 0x1 | 0x20 | ||
Rigid_B = 0x1 | 0x04 | ||
Rigid_AB = 0x1 | 0x20 | 0x04 | ||
Pulse_A = 0x2 | 0x20 | ||
Pulse_B = 0x2 | 0x04 | ||
Pulse_AB = 0x2 | 0x20 | 0x04 | ||
Calibration = 0xFC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from collections import defaultdict | ||
|
||
|
||
class Event(object): | ||
""" | ||
Base class for the event driven system | ||
""" | ||
|
||
def __init__(self) -> None: | ||
""" | ||
initialise event system | ||
""" | ||
self._event_handler = [] | ||
|
||
def subscribe(self, fn): | ||
""" | ||
add a event subscription | ||
Args: | ||
fn (function): _description_ | ||
""" | ||
self._event_handler.append(fn) | ||
return self | ||
|
||
def unsubscribe(self, fn): | ||
""" | ||
delete event subscription fn | ||
Args: | ||
fn (function): _description_ | ||
""" | ||
self._event_handler.remove(fn) | ||
return self | ||
|
||
def __iadd__(self, fn): | ||
""" | ||
add event subscription fn | ||
Args: | ||
fn (function): _description_ | ||
""" | ||
self._event_handler.append(fn) | ||
return self | ||
|
||
def __isub__(self, fn): | ||
""" | ||
delete event subscription fn | ||
Args: | ||
fn (function): _description_ | ||
""" | ||
self._event_handler.remove(fn) | ||
return self | ||
|
||
def __call__(self, *args, **keywargs): | ||
""" | ||
calls all event subscription functions | ||
""" | ||
for eventhandler in self._event_handler: | ||
eventhandler(*args, **keywargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
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: | ||
pass | ||
""" | ||
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, r'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: | ||
pass | ||
|
||
return False | ||
return False |
Oops, something went wrong.