Playstation USBアダプター不足ボタン

Playstation USBアダプター不足ボタン

PC / LinuxでPS2 Guitar Hero IIコントローラを使用しようとしています。さまざまなPlaystation-USBアダプタを試した後、ついに入力遅延が発生しないアダプタが見つかりました。

しかし、Linuxでは、次のすべてのボタンを検出するのに問題があります。linux-inputメーリングリストスレッド

Windows

  • すべてのボタンが検出されましたが、方向キー(ストラムの上/下)が「Whammy bar」と同じ軸に正しくマッピングされていません。これはゲームを中断するのではなく、単に不快感を与えます。

Linux

  • Linux検出コントローラにはID 054c:0268 Sony Corp. Batoh Device / PlayStation 3 Controller13個のボタンと6個の軸があります。

  • 一部のボタンはイベントを発生させません。/dev/input/jsX

  • ボタンが機能しません。するで検出されたHIDイベントを発生させます/dev/hidrawX

これがバグであることを理解し、ドライバが修正されるのを待つ必要があります。修理中に解決策を見つけたいです。

生のHIDイベントを入力イベントにマッピングするために、いくつかのudevルールを簡単に作成できますか?

また、WindowsでWiresharkを使用してUSBハンドシェイクプロセスをキャプチャしました。

ベストアンサー1

私はそれを使用して動作させました。Python用ヒダフィ。結局は簡単だった。道具が足りなかっただけでした。

誰でも指示が必要な場合、スクリプト全体は次のようになります。

from __future__ import print_function

import hid
import time
import uinput

MAPPING = {
    'green': uinput.BTN_0,
    'red': uinput.BTN_1,
    'yellow': uinput.BTN_2,
    'blue': uinput.BTN_3,
    'orange': uinput.BTN_4,
    'tilt': uinput.BTN_SELECT,  # SELECT
    'start': uinput.BTN_START,  # START
    'select': uinput.BTN_SELECT,  # SELECT
    'whammy': uinput.ABS_X,  # WHAMMY
    'strumdown': uinput.BTN_DPAD_DOWN,
    'strumup': uinput.BTN_DPAD_UP,
}

DEVICE = uinput.Device(MAPPING.values())

# enumerate USB devices

for d in hid.enumerate():
    keys = list(d.keys())
    keys.sort()
    for key in keys:
        print("%s : %s" % (key, d[key]))
    print()

# try opening a device, then perform write and read


def diff(new_arr, old_arr):
    for i in range(len(new_arr)):
        if new_arr[i] != old_arr[i]:
            yield (i, new_arr[i]) 


try:
    print("Opening the device")

    h = hid.device()
    h.open(0x054c, 0x0268)  # VendorID/ProductID

    print("Manufacturer: %s" % h.get_manufacturer_string())
    print("Product: %s" % h.get_product_string())
    print("Serial No: %s" % h.get_serial_number_string())

    # enable non-blocking mode
    h.set_nonblocking(1)

    # write some data to the device
    print("Write the data")
    h.write([0, 63, 35, 35] + [0] * 61)

    # wait
    time.sleep(0.05)

    # read back the answer
    print("Read the data")
    previous = None
    INPUT = {
        'green': False,
        'red': False,
        'yellow': False,
        'blue': False,
        'orange': False,
        'tilt': False,
        'start': False,
        'select': False,
        'whammy': False,
        'strumdown': False,
        'strumup': False,
    }

    def set_input(key, val, tmp):
        prev = INPUT[key]
        if tmp >= val:
            tmp -= val
            INPUT[key] = True
        else:
            INPUT[key] = False

        if prev != INPUT[key]:
            # SEND EVENT
            DEVICE.emit(MAPPING[key], INPUT[key])
            pass

        return tmp

    counter = 0
    while True:
        try:
            time.sleep(0.001)
            d = h.read(64)
            counter += 1
            if d:
                if previous and d != previous:
                    for ret in diff(d, previous):
                        if ret[0] == 7:
                            DEVICE.emit(MAPPING['whammy'], ret[1])

                        if ret[0] == 2:
                            tmp = ret[1] - 128
                            tmp = set_input('strumdown', 64, tmp)
                            tmp = set_input('strumup', 16, tmp)
                            tmp = set_input('start', 8, tmp)
                            tmp = set_input('select', 1, tmp)

                        if ret[0] == 3:
                            tmp = ret[1]
                            tmp = set_input('orange', 128, tmp)
                            tmp = set_input('blue', 64, tmp)
                            tmp = set_input('red', 32, tmp)
                            tmp = set_input('yellow', 16, tmp)
                            tmp = set_input('green', 2, tmp)
                            tmp = set_input('tilt', 1, tmp)

                previous = d
            else:
                continue
        except KeyboardInterrupt:
            break
        print(counter, end="\r")
        # print(INPUT)

    print("Closing the device")
    h.close()

except IOError as ex:
    print(ex)
    print("You probably don't have the hard coded device. Update the hid.device line")
    print("in this script with one from the enumeration list output above and try again.")

print("Done")

おすすめ記事