Пример #1
0
        private void DeviceConnectedEvent(USBH_Device device)
        {
            if (XBoxJoystickData != null)
            {
                //we already have one connected so we will ignore any new events
                return;
            }

            if (device.TYPE == USBH_DeviceType.Unknown && device.VENDOR_ID == vendorId && device.PRODUCT_ID == productId)
            {
#if DEBUG
                Debug.Print("XBox Controller Found");
#endif

                XBoxJoystick = new USBH_RawDevice(device);

                // Get descriptors
                USBH_Descriptors.Configuration cd = XBoxJoystick.GetConfigurationDescriptors(0);

                // communication endpoint
                USBH_Descriptors.Endpoint XBoxInputEndPoint  = null;
                USBH_Descriptors.Endpoint XboxOutputEndPoint = null;

                // look for HID class
                for (int i = 0; i < cd.interfaces.Length; i++)
                {
                    // found
                    if (cd.interfaces[i].bInterfaceSubclass == 0x5D && cd.interfaces[i].bInterfaceProtocol == 0x01)
                    {
                        if (cd.interfaces[i].endpoints.Length == 2)
                        {
                            int ep = 0;

                            // set configuration
                            XBoxJoystick.SendSetupTransfer(0x00, 0x09, cd.bConfigurationValue, 0x00);

                            XBoxInputEndPoint             = cd.interfaces[i].endpoints[ep];           // get endpoint
                            XBoxInputPipe                 = XBoxJoystick.OpenPipe(XBoxInputEndPoint); // open pipe
                            XBoxInputPipe.TransferTimeout = 0;                                        // recommended for interrupt transfers

                            ep++;

                            XboxOutputEndPoint             = cd.interfaces[i].endpoints[ep];
                            XBoxOutputPipe                 = XBoxJoystick.OpenPipe(XboxOutputEndPoint);
                            XBoxOutputPipe.TransferTimeout = 0;


                            XBoxThread = new Thread(ReaderThread)
                            {
                                Priority = ThreadPriority.Highest                                     /* we should read as fast as possible*/
                            };                                                                        // create the polling thread
                            XBoxThread.Start();


                            IsConnected = true;

                            if (ControllerConnected != null)
                            {
                                ControllerConnected(this);
                            }
                        }

                        //break;
                    }
                }
            }
        }
Пример #2
0
        static void DeviceConnectedEvent(USBH_Device device)
        {
            Debug.Print("Inside the DeviceConnectedEvent!");
            if (!initPhaseOneComplete)
            {
                usb = new USBH_RawDevice(device);
                USBH_Descriptors.Configuration cd    = usb.GetConfigurationDescriptors(0);
                USBH_Descriptors.Endpoint      adbEP = null;
                USBH_Descriptors.Interface     adbIF = null;

                Debug.Print("[Device, Port " + usb.PORT_NUMBER + "]");
                Debug.Print("Interface: " + usb.INTERFACE_INDEX);
                Debug.Print("ID: " + usb.ID);
                Debug.Print("Type: " + usb.TYPE);
                Debug.Print("VID: " + usb.VENDOR_ID);
                Debug.Print("PID: " + usb.PRODUCT_ID);

                // look for HID class
                for (int i = 0; i < cd.bNumInterfaces; i++)
                {
                    adbIF = cd.interfaces[i];
                    if (adbIF.bInterfaceClass == 255)
                    {
                        Debug.Print("  === Interface ===");
                        Debug.Print("  Class: " + cd.interfaces[i].bInterfaceClass);
                        Debug.Print("  SubClass: " + cd.interfaces[i].bInterfaceSubclass);
                        Debug.Print("  Number: " + cd.interfaces[i].bInterfaceNumber);
                        Debug.Print("  Protocol: " + cd.interfaces[i].bInterfaceProtocol);
                        Debug.Print("  Type: " + cd.interfaces[i].bDescriptorType);

                        for (int ep = 0; ep < adbIF.bNumberEndpoints; ep++)
                        {
                            adbEP = adbIF.endpoints[ep];

                            Debug.Print("   -- Endpoint --");
                            Debug.Print("    Attributes: " + adbIF.endpoints[ep].bmAttributes);
                            Debug.Print("    Address: " + adbIF.endpoints[ep].bEndpointAddress);
                            Debug.Print("    Type: " + adbIF.endpoints[ep].bDescriptorType);
                            Debug.Print("    Interval: " + adbIF.endpoints[ep].bInterval);
                            Debug.Print(" ");

                            string str = adbEP.bEndpointAddress.ToString();
                            Debug.Print(str);



                            switch (adbEP.bEndpointAddress)
                            {
                            case 133:                          // ADB data in , 129 = (Thunder Board)
                                adbInPipe = usb.OpenPipe(adbEP);
                                adbInPipe.TransferTimeout = 0; // recommended for interrupt transfers
                                Debug.Print("in case .133...");
                                break;

                            case 4: // ADB data out,  1 = (Thunder Board)
                                adbOutPipe = usb.OpenPipe(adbEP);
                                Debug.Print("in case 5...");
                                break;
                            }
                        }
                        initPhaseOneComplete = true;
                        Debug.Print("Phase One Complete = true!");
                    }
                }
            }
            //else
            //{
            initPhaseTwoComplete = true;
            Debug.Print("Phase Two Complete = true!");
            //}

            if (initPhaseTwoComplete)
            {
                initPhaseOneComplete = false;
                initPhaseTwoComplete = false;
                isReady = true;
                Debug.Print("isReady is true!");
            }

            if (isReady)
            {
                Debug.Print("AdbListening Thread initialised!");
                usb.SendSetupTransfer(0x00, 0x09, 0x0001, 0x0000);
                adbInThread          = new Thread(AdbListening); // create the polling thread
                adbInThread.Priority = ThreadPriority.Highest;
                adbInThread.Start();

                SendAdbMessage(A_CNXN, 16777216, 4096, hostName);
                //SendAdbMessage(A_CNXN, 16777216, 4096, hostName);
            }
        }