Попытка связать Nintendo Switch с Raspberry 3b + через USB - PullRequest
1 голос
/ 31 января 2020

Привет всем в месяц go моя племянница случайно сломала мой контроллер коммутатора Nintendo (https://www.powera.com/products/pokemon-wired-controller-for-nintendo-switch-pikachu-silhouette/), и я решил попробовать использовать малиновый 3b + для связи с моим Nintendo Switch ... Я никогда не программировал в python, не говоря уже о том, чтобы использовать малину, поэтому я полный новичок ie. Итак, через 3 недели, я пришел с этим кодом:

import USB
import time

#Test to see if a Nintendo Switch is connected or no
switch = usb.core.find(idVendor=1406)
if switch is None:
    print('Switch Not Detected')
    exit(0)
else:
    print('Switch Conected')
reconect = False

#Don't know why is this for but it helps to connect with the switch
if switch.is_kernel_driver_active(0):
    reconect = True
    switch.detach_kernel_driver(0)

switch.set_configuration()

cfg=switch.get_active_configuration()

interface_number = cfg[(0,0)].bInterfaceNumber
alternate_settting = usb.control.get_interface(switch, interface_number)
intf = usb.util.find_descriptor(cfg, bInterfaceNumber = interface_number,
                                bAlternateSetting = alternate_settting)

ep = usb.util.find_descriptor(intf,custom_match = \
                                  lambda e: \
                              usb.util.endpoint_direction(e.bEndpoindAddress) == \
                              usb.util.ENDPOINT_OUT)

ep.write(b'\x00\x00\x00\x0f\x80\x80\x80\x80\x00')   #Controller not pressed
time.sleep(0.1)
ep.write(b'\x04\x00\x0f\x80\x80\x80\x80\x00')       #Controller "A" button pressed
time.sleep(0.1)
ep.write(b'\x00\x00\x00\x0f\x80\x80\x80\x80\x00')   #Controller not pressed

usb.util.dispose_resources(dev)
if reconectar:
    switch.attach_kernel_driver(0)

print('Communication Finished') 

После запуска кода я получаю этот код ошибки

>>> %FastDebug testedousb.py
Switch Conected
Traceback (most recent call last):
  File "/home/pi/testedousb.py", line 41, in <module>
    alternate_settting = usb.control.get_interface(switch, interface_number)
  File "/usr/local/lib/python3.7/dist-packages/usb/control.py", line 244, in get_interface
    data_or_wLength = 1)[0]
  File "/usr/local/lib/python3.7/dist-packages/usb/core.py", line 1043, in ctrl_transfer
    self.__get_timeout(timeout))
  File "/usr/local/lib/python3.7/dist-packages/usb/backend/libusb1.py", line 883, in ctrl_transfer
    timeout))
  File "/usr/local/lib/python3.7/dist-packages/usb/backend/libusb1.py", line 595, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 32] Pipe error

Кто-нибудь, как исправить эту ошибку?

1 Ответ

0 голосов
/ 31 января 2020

Вместо того, чтобы писать свой собственный код с нуля, вы можете взглянуть на этот замечательный проект и его форки: https://github.com/ebith/Switch-Fightstick

...