public PS3Controller(USBH_Device device)
        {
            if (device.VENDOR_ID != PS3_VENDOR_ID || device.PRODUCT_ID != PS3_PRODUCT_ID)
            {
                throw new InvalidOperationException();
            }

            raw = new USBH_RawDevice(device);
            USBH_Descriptors.Configuration cd = raw.GetConfigurationDescriptors(0);

            readPipe = raw.OpenPipe(cd.interfaces[0].endpoints[1]); // to read buttons
            readPipe.TransferTimeout = 0;
            //Set configuration
            raw.SendSetupTransfer(0x00, 0x09, cd.bConfigurationValue, 0x00);

            //Set the BD address automatically
            SetBD_Addr(Bluetooth.BDaddr);

            try
            {
                //request the PS3 controller to send button presses etc back
                //Host to device (0x00) | Class (0x20) | Interface (0x01), Set Report (0x09), Report Type (Feature 0x03) - Report ID (0xF4), Host to device (0x00) - Endpoint 0 (0x00), data, dataoffset, datalength
                raw.SendSetupTransfer(0x21, 0x09, 0x03F4, 0x0000, enableUSB, 0x00, 0x04);
            }
            catch (Exception ex)
            {
                Debug.Print("==============================");
                Debug.Print(DateTime.Now.ToString());
                Debug.Print(ex.Message);
                Debug.Print(ex.StackTrace);
                if (ex.InnerException != null)
                {
                    Debug.Print("Inner Exception: " + ex.InnerException.Message);
                }
            }

            for (int i = 0; i < OUTPUT_REPORT_BUFFER.Length; i++)
            {
                writeBuffer[i] = OUTPUT_REPORT_BUFFER[i];
            }

            PS3Thread          = new Thread(ReaderThread); // create the polling thread
            PS3Thread.Priority = ThreadPriority.Highest;   // we should read as fast as possible
            PS3Thread.Start();
        }
Example #2
0
        Thread PS3ReadThread;//The LED and rumble values, has to be written again and again, for it to stay turned on

        public PS3Navigation(USBH_Device device)
        {
            if (device.VENDOR_ID != PS3NAVIGATION_VENDOR_ID || device.PRODUCT_ID != PS3NAVIGATION_PRODUCT_ID)
            {
                throw new InvalidOperationException();
            }

            raw = new USBH_RawDevice(device);
            USBH_Descriptors.Configuration cd = raw.GetConfigurationDescriptors(0);

            readPipe = raw.OpenPipe(cd.interfaces[0].endpoints[1]);
            readPipe.TransferTimeout = 0;

            //Set configuration
            raw.SendSetupTransfer(0x00, 0x09, cd.bConfigurationValue, 0x00);

            //Set the BD address automatically
            SetBD_Addr(Bluetooth.BDaddr);

            try
            {
                //request the PS3 controller to send button presses etc back
                //Host to device (0x00) | Class (0x20) | Interface (0x01), Set Report (0x09), Report Type (Feature 0x03) - Report ID (0xF4), Host to device (0x00) - Endpoint 0 (0x00), data, dataoffset, datalength
                raw.SendSetupTransfer(0x21, 0x09, 0x03F4, 0x0000, PS3Controller.enableUSB, 0x00, 0x04);
            }
            catch (Exception ex)
            {
                Debug.Print("==============================");
                Debug.Print(DateTime.Now.ToString());
                Debug.Print(ex.Message);
                Debug.Print(ex.StackTrace);
                if (ex.InnerException != null)
                {
                    Debug.Print("Inner Exception: " + ex.InnerException.Message);
                }
            }

            PS3NavigationConnected = true;
            PS3ReadThread          = new Thread(ReaderThread);// create the write thread - needed for the LED's and rumble to stay turned on
            PS3ReadThread.Priority = ThreadPriority.Highest;
            PS3ReadThread.Start();
        }
Example #3
0
        Thread PS3MoveWriteThread;                   //The LED and rumble values, has to be written again and again, for it to stay turned on

        public PS3Move(USBH_Device device)
        {
            if (device.VENDOR_ID != PS3MOVE_VENDOR_ID || device.PRODUCT_ID != PS3MOVE_PRODUCT_ID)
            {
                throw new InvalidOperationException();
            }

            raw = new USBH_RawDevice(device);
            USBH_Descriptors.Configuration cd = raw.GetConfigurationDescriptors(0);

            writePipe = raw.OpenPipe(cd.interfaces[0].endpoints[0]); // to write settings (LEDs, rumble...)
            writePipe.TransferTimeout = 0;

            //Set configuration
            raw.SendSetupTransfer(0x00, 0x09, cd.bConfigurationValue, 0x00);

            //Set the BD address automatically
            SetBD_Addr(Bluetooth.BDaddr);

            SetLed(Bluetooth.Colors.Green);               //Indicate that it's connected

            PS3MoveWriteThread = new Thread(WriteThread); // create the write thread - needed for the LED's and rumble to stay turned on
            PS3MoveWriteThread.Start();
        }
Example #4
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;
                    }
                }
            }
        }
Example #5
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);
            }
        }