Skip to content

Commit

Permalink
updated docs, default to 3Bh2b, default mapping class
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturSpirin committed Jan 14, 2021
1 parent ddef38d commit 0e2c87a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ All of that info you can acquire by turning on debug mode and pressing buttons o
Here is an example on how to do it.

```python
from pyPS4Controller.controller import Controller, Event
from pyPS4Controller.controller import Controller
from pyPS4Controller.event_mapping.DefaultMapping import DefaultMapping


class MyController(Controller):
Expand All @@ -157,15 +158,16 @@ class MyController(Controller):
print("Goodbye world")


class MyEventDefinition(Event):
class MyEventDefinition(DefaultMapping):

def __init__(self, **kwargs):
Event.__init__(self, **kwargs)
DefaultMapping.__init__(self, **kwargs)

# each overloaded function, has access to:
# - self.button_id
# - self.button_type
# - self.value
# - self.overflow
# use those variables to determine which button is being pressed
def x_pressed(self):
return self.button_id == 0 and self.button_type == 1 and self.value == 1
Expand Down
10 changes: 5 additions & 5 deletions pyPS4Controller/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ def __init__(
# when device is connected via ds4drv its sending hundreds of events for those button IDs
# thus they are blacklisted by default. Feel free to adjust this list to your linking when sub-classing
self.black_listed_buttons += [6, 7, 8, 11, 12, 13]
self.event_format = event_format if event_format else "LhBB"
self.event_format = event_format if event_format else "3Bh2b"

if event_definition is None: # means it wasn't specified by user
if self.event_format == "3Bh2b":
if self.event_format == "LhBB":
from pyPS4Controller.event_mapping.DefaultMapping import DefaultMapping
self.event_definition = DefaultMapping
else:
from pyPS4Controller.event_mapping.Mapping3Bh2b import Mapping3Bh2b
self.event_definition = Mapping3Bh2b
else:
from pyPS4Controller.event_mapping.MappingLhBB import MappingLhBB
self.event_definition = MappingLhBB
else:
self.event_definition = event_definition

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


class MappingLhBB:
class DefaultMapping:

def __init__(self, button_id, button_type, value, connecting_using_ds4drv, overflow=None, debug=False):
"""
Expand All @@ -16,8 +16,10 @@ def __init__(self, button_id, button_type, value, connecting_using_ds4drv, overf
self.button_type = button_type
self.value = value
self.connecting_using_ds4drv = connecting_using_ds4drv
self.overflow = overflow
if debug:
print("button_id: {} button_type: {} value: {}".format(self.button_id, self.button_type, self.value))
print("button_id: {} button_type: {} value: {} overflow: {}"
.format(self.button_id, self.button_type, self.value, self.overflow))

# L joystick group #
def L3_event(self): # L3 has the same mapping on ds4drv as it does when connecting to bluetooth directly
Expand Down
10 changes: 6 additions & 4 deletions pyPS4Controller/event_mapping/Mapping3Bh2b.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pyPS4Controller.event_mapping.MappingLhBB import MappingLhBB
from pyPS4Controller.event_mapping.DefaultMapping import DefaultMapping


class Mapping3Bh2b(MappingLhBB):
class Mapping3Bh2b(DefaultMapping):

def __init__(self, button_id, button_type, value, connecting_using_ds4drv, overflow, debug=False):
"""
Expand All @@ -17,9 +17,11 @@ def __init__(self, button_id, button_type, value, connecting_using_ds4drv, overf
self.button_type = overflow[1]
self.value = overflow[0]
self.connecting_using_ds4drv = connecting_using_ds4drv
MappingLhBB.__init__(self, self.button_id, self.button_type, self.value, connecting_using_ds4drv)
self.overflow = overflow
if debug:
print("button_id: {} button_type: {} value: {}".format(self.button_id, self.button_type, self.value))
print("button_id: {} button_type: {} value: {} overflow: {}"
.format(self.button_id, self.button_type, self.value, self.overflow))
DefaultMapping.__init__(self, self.button_id, self.button_type, self.value, connecting_using_ds4drv)

# Square / Triangle / Circle / X Button group #
def circle_pressed(self):
Expand Down

0 comments on commit 0e2c87a

Please sign in to comment.