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>2015-10-30 00:11:25 +0300
committerStany MARCEL <stanypub@gmail.com>2015-10-30 00:11:25 +0300
commitb9e9ddc8845f27fe42929efedfe8c6ec46bac494 (patch)
treee8bdfc264c71ff9b1cdb186d4a0a047503898627 /scripts
parente5f1c576cdfc5e84cc1a8073d3f5a41fb317b7ee (diff)
Add Simple xbox 360 emulator
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/sc-xbox.py98
1 files changed, 92 insertions, 6 deletions
diff --git a/scripts/sc-xbox.py b/scripts/sc-xbox.py
index 10d8e93..cd0fb4d 100755
--- a/scripts/sc-xbox.py
+++ b/scripts/sc-xbox.py
@@ -25,14 +25,100 @@
"""Steam Controller XBOX Driver"""
import sys
-from steamcontroller import SteamController, SteamControllerInput
+from steamcontroller import \
+ SteamController, \
+ SteamControllerInput, \
+ SCStatus, \
+ SCButtons
import steamcontroller.uinput
-from steamcontroller.uinput import Keys as K
-from steamcontroller.uinput import Axes as A
+from steamcontroller.uinput import Keys
+from steamcontroller.uinput import Axes
-def scInput2Uinput(sci, uinput):
- # FIXME
- pass
+prev_buttons = 0
+
+button_map = {
+ SCButtons.A : Keys.BTN_A,
+ SCButtons.B : Keys.BTN_B,
+ SCButtons.X : Keys.BTN_X,
+ SCButtons.Y : Keys.BTN_Y,
+ SCButtons.Back : Keys.BTN_BACK,
+ SCButtons.Start : Keys.BTN_START,
+ SCButtons.Steam : Keys.BTN_MODE,
+ SCButtons.LB : Keys.BTN_TL,
+ SCButtons.RB : Keys.BTN_TR,
+ SCButtons.Stick : Keys.BTN_THUMBL,
+ SCButtons.RPad : Keys.BTN_THUMBR,
+ SCButtons.LGrip : Keys.BTN_A,
+ SCButtons.RGrip : Keys.BTN_B,
+}
+
+
+def lpad_func(x, btn, threshold, evstick, evtouch, clicked, invert):
+ global prev_buttons
+
+ removed = prev_buttons ^ btn
+
+ if btn & SCButtons.LPadTouch != SCButtons.LPadTouch:
+ return (evstick, x if not invert else -x)
+
+ if btn & (SCButtons.LPad if clicked else SCButtons.LPadTouch):
+ if x >= 0:
+ if x >= threshold:
+ x = 32767
+ else:
+ x = 0
+ else:
+ if x <= -threshold:
+ x = -32767
+ else:
+ x = 0
+ return (evtouch, x if not invert else -x)
+
+ if removed & SCButtons.LPadTouch != SCButtons.LPadTouch:
+ return (evstick, 0)
+
+ if removed & (SCButtons.LPad if clicked else SCButtons.LPadTouch):
+ return (evtouch, 0)
+
+ return (None, None)
+
+axis_map = {
+ 'ltrig' : lambda x, btn: (Axes.ABS_Z, int(-32767 + ((x*2.0*32767.0)/255.))),
+ 'rtrig' : lambda x, btn: (Axes.ABS_RZ, int(-32767 + ((x*2.0*32767.0)/255.))),
+ 'lpad_x' : lambda x, btn: lpad_func(x, btn, 16384, Axes.ABS_X, Axes.ABS_HAT0X, True, False),
+ 'lpad_y' : lambda x, btn: lpad_func(x, btn, 16384, Axes.ABS_Y, Axes.ABS_HAT0Y, True, True),
+ 'rpad_x' : lambda x, btn: (Axes.ABS_RX, x),
+ 'rpad_y' : lambda x, btn: (Axes.ABS_RY, -x),
+}
+
+
+def scInput2Uinput(sci, xb):
+
+ global prev_buttons
+
+ if sci.status != SCStatus.Input:
+ return
+
+ removed = prev_buttons ^ sci.buttons
+
+ for btn, ev in button_map.items():
+
+ if btn == SCButtons.Stick and sci.buttons & SCButtons.LPadTouch:
+ xb.keyEvent(ev, 0)
+ continue
+
+ if sci.buttons & btn:
+ xb.keyEvent(ev, 1)
+ if removed & btn:
+ xb.keyEvent(ev, 0)
+
+ for name, func in axis_map.items():
+ ev, val = func(sci._asdict()[name], sci.buttons)
+ if ev != None:
+ xb.axisEvent(ev, val)
+
+ xb.synEvent()
+ prev_buttons = sci.buttons
def _main():