Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ynsta/steamcontroller.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStany MARCEL <stanypub@gmail.com>2016-01-04 17:14:00 +0300
committerStany MARCEL <stanypub@gmail.com>2016-01-04 17:14:00 +0300
commitab603295200ef96ecaf2d5e5f13beebb2d0b0d0a (patch)
tree37a8638463b3286667424589951d7de062c3beef
parenta8c0b8ab6da60e3b6794db6ab139d0d19538440c (diff)
parent6dbdc361ba4e63ae3430e70e56502e1150b40ac1 (diff)
Merge pull request #14 from syr1us/trigger_axes_callback
Added callback for trigger axes event
-rw-r--r--scripts/sc-callbacks.py7
-rw-r--r--src/events.py27
2 files changed, 23 insertions, 11 deletions
diff --git a/scripts/sc-callbacks.py b/scripts/sc-callbacks.py
index 41d4078..eaeb658 100644
--- a/scripts/sc-callbacks.py
+++ b/scripts/sc-callbacks.py
@@ -32,7 +32,7 @@ from steamcontroller.uinput import Keys
def button_pressed_callback(evm, btn, pressed):
print "Button {} was {}.".format(btn, 'pressed' if pressed else 'released')
-
+
if btn == SCButtons.STEAM and not pressed:
print "pressing the STEAM button terminates the programm"
sys.exit()
@@ -49,6 +49,9 @@ def stick_pressed_callback(evm):
def stick_axes_callback(evm, x, y):
print "Stick Position is {}, {}".format(x, y)
+def tigger_axes_callback(evm, pos, value):
+ print "Trigger axes {} has value {}".format(pos, value)
+
def evminit():
evm = EventMapper()
evm.setButtonCallback(SCButtons.STEAM, button_pressed_callback)
@@ -68,6 +71,8 @@ def evminit():
evm.setPadButtonCallback(Pos.RIGHT, touchpad_click_callback, clicked=True)
evm.setStickAxesCallback(stick_axes_callback)
evm.setStickPressedCallback(stick_pressed_callback)
+ evm.setTrigAxesCallback(Pos.RIGHT, tigger_axes_callback)
+ evm.setTrigAxesCallback(Pos.LEFT, tigger_axes_callback)
return evm
diff --git a/src/events.py b/src/events.py
index 14b06a5..e6dc5b1 100644
--- a/src/events.py
+++ b/src/events.py
@@ -113,8 +113,9 @@ class EventMapper(object):
self._stick_rxs = None
self._stick_axes_callback = None
self._stick_pressed_callback = None
-
+
self._trig_s = [None, None]
+ self._trig_axes_callbacks = [None, None]
self._moved = [0, 0]
@@ -372,8 +373,10 @@ class EventMapper(object):
trigval = sci.ltrig if pos == Pos.LEFT else sci.rtrig
trigval_prev = sci_p.ltrig if pos == Pos.LEFT else sci_p.rtrig
mode, ev = self._trig_evts[pos]
- if self._trig_modes[pos] == TrigModes.AXIS:
- if trigval != trigval_prev:
+ if trigval != trigval_prev:
+ if self._trig_axes_callbacks[pos]:
+ self._trig_axes_callbacks[pos](self, pos, trigval)
+ elif self._trig_modes[pos] == TrigModes.AXIS:
syn.add(mode)
self._uip[mode].axisEvent(ev, trigval)
elif self._trig_modes[pos] == TrigModes.BUTTON:
@@ -467,11 +470,11 @@ class EventMapper(object):
set callback function to be executed when button is clicked
callback is called with parameters self(EventMapper), btn
and pushed (boollean True -> Button pressed, False -> Button released)
-
+
@param btn Button
@param function callback Callback function
"""
-
+
self._btn_map[btn] = (Modes.CALLBACK, callback)
@@ -504,13 +507,13 @@ class EventMapper(object):
self._btn_map[SCButtons.LPAD] = (None, 0)
else:
self._btn_map[SCButtons.RPAD] = (None, 0)
-
+
def setPadButtonCallback(self, pos, callback, clicked=False):
"""
set callback function to be executed when Pad clicked or touched
if clicked is False callback will be called with pad, xpos and ypos
else with pad and boolean is_pressed
-
+
@param Pos pos designate left or right pad
@param callback Callback function
@param bool clicked callback on touch or on click event
@@ -593,6 +596,10 @@ class EventMapper(object):
self._trig_modes[pos] = TrigModes.AXIS
self._trig_evts[pos] = (Modes.GAMEPAD, abs_event)
+ def setTrigAxesCallback(self, pos, callback):
+ self._trig_modes[pos] = StickModes.AXIS
+ self._trig_axes_callbacks[pos] = callback
+
def setStickAxes(self, abs_x_event, abs_y_event, revert=True):
self._stick_mode = StickModes.AXIS
self._stick_evts = [(Modes.GAMEPAD, abs_x_event),
@@ -603,7 +610,7 @@ class EventMapper(object):
"""
Set Callback on StickAxes Movement
the function will be called with EventMapper, pos_x, pos_y
-
+
@param function callback the callback function
"""
self._stick_axes_callback = callback
@@ -631,7 +638,7 @@ class EventMapper(object):
"""
Set callback on StickPressed event.
the function will be called with EventMapper as first (and only) argument
-
+
@param function Callback function function that is called on buton press.
"""
- self._stick_pressed_callback = callback \ No newline at end of file
+ self._stick_pressed_callback = callback