Esempio n. 1
0
 private static void USBDevice_Connected(USBH_Device device)
 {
     if (USBDeviceInserted != null)
     {
         USBDeviceInserted(device);
     }
 }
Esempio n. 2
0
 private static void USBDevice_Disconnected(USBH_Device device)
 {
     if (USBDeviceRemoved != null)
     {
         USBDeviceRemoved(device);
     }
 }
Esempio n. 3
0
 private static void USBDevice_BadConnection(USBH_Device device)
 {
     if (USBDeviceBadConnection != null)
     {
         USBDeviceBadConnection(device);
     }
 }
Esempio n. 4
0
        // USB Device Connected Event
        static void UsbHostControllerDeviceConnectedEvent(USBH_Device device)
        {
            Console.WriteLine("Device connected...");
            Console.WriteLine("ID: " + device.ID + ", Interface: " + device.INTERFACE_INDEX + ", Type: " + device.TYPE);

            if (device.TYPE == USBH_DeviceType.MassStorage)
            {
                Console.WriteLine("USB Mass Storage detected...");
                Console.WriteLine("Mounting file system");
                usbDrive.Mount(device);
            }

            if (device.TYPE == USBH_DeviceType.HID)
            {
                Console.WriteLine("New USB HID Connected");
                if (device.VENDOR_ID == 2867 && device.PRODUCT_ID == 16)
                {
                    Console.WriteLine("Jog wheel connected.");
                    jogger = new UsbShuttlePro(device);
                    jogger.JogButtonDown += b =>
                    {
                        Console.WriteLine("Button+ " + b);
                        if (b == 0)
                        {
                            Console.WriteLine("Creating and opening port to device");
                            port               = EmvPedConnection.Factory.Create(new PedEndpointAddress());
                            port.Diagnostics  += (sender, e) => Console.WriteLine(e);
                            port.DataReceived += (sender, e) => Console.WriteLine(e.Length);
                            port.DataSent     += (sender, e) => Console.WriteLine(e.Length);
                            port.Open();
                        }

                        if (b == 1)
                        {
                            Console.WriteLine("Sending in a reset command");
                            try
                            {
                                var reset = new byte[] { 0x01, 0x00, 0x04, 0xD0, 0x00, 0x00, 0x01, 0xD4 };
                                port.Send(reset);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }

                        if (b == 2)
                        {
                            Console.WriteLine("Disposing of port to device");
                            port.Dispose();
                        }
                    };

                    jogger.JogButtonUp            += e => Console.WriteLine("Button- " + e);
                    jogger.JogPositionChanged     += e => Console.WriteLine("Jog: " + e);
                    jogger.ShuttlePositionChanged += e => Console.WriteLine("Shuttle: " + e);
                }
            }
        }
Esempio n. 5
0
 void USBHostController_DeviceConnectedEvent(USBH_Device device)
 {
     if (device.TYPE == USBH_DeviceType.MassStorage)
     {
         PersistentStorage usbStorage = new PersistentStorage(device);
         usbStorage.MountFileSystem();
         _usbStorages.Add(device.ID, usbStorage);
     }
 }
Esempio n. 6
0
 public void BeginMonitorMouseFrom(USBH_Device device)
 {
     _Mouse = new USBH_Mouse(device);
     _Mouse.Disconnected += new USBH_MouseEventHandler(Mouse_Disconnected);
     _Mouse.MouseDown    += new USBH_MouseEventHandler(Mouse_Activity);
     _Mouse.MouseUp      += new USBH_MouseEventHandler(Mouse_Activity);
     _Mouse.MouseMove    += new USBH_MouseEventHandler(Mouse_Activity);
     _Mouse.MouseWheel   += new USBH_MouseEventHandler(Mouse_Activity);
 }
 void USBHostController_DeviceConnectedEvent(USBH_Device device)
 {
     if (device.TYPE == USBH_DeviceType.MassStorage)
     {
         PersistentStorage usbStorage = new PersistentStorage(device);
         usbStorage.MountFileSystem();
         _usbStorages.Add(device.ID, usbStorage);
     }
 }
 static void DeviceConnectedEvent(USBH_Device device)
 {
     if ((int)device.TYPE == 2)
     {
         joysticks[jCount] = new USBH_Joystick(device);
         joysticks[jCount].JoystickXYMove += JoystickXYMove;
         jCount++;
     }
 }
        private void DeviceDisconnectedEvent(USBH_Device device)
        {
            if (device.PRODUCT_ID == 0x0202 && device.VENDOR_ID == 0x1130)
            {
                Debug.Print("Device disconnected...");
                multicolorLed.TurnRed();

            }
        }
Esempio n. 10
0
 void USBHostController_DeviceDisconnectedEvent(USBH_Device device)
 {
     if (device.TYPE == USBH_DeviceType.MassStorage && _usbStorages.Contains(device.ID))
     {
         PersistentStorage usbStorage = (PersistentStorage)_usbStorages[device.ID];
         usbStorage.UnmountFileSystem();
         usbStorage.Dispose();
         _usbStorages.Remove(device.ID);
     }
 }
 void USBHostController_DeviceDisconnectedEvent(USBH_Device device)
 {
     if (device.TYPE == USBH_DeviceType.MassStorage && _usbStorages.Contains(device.ID))
     {
         PersistentStorage usbStorage = (PersistentStorage)_usbStorages[device.ID];
         usbStorage.UnmountFileSystem();
         usbStorage.Dispose();
         _usbStorages.Remove(device.ID);
     }
 }
Esempio n. 12
0
        public void Mount(USBH_Device device)
        {
            if (driveMounted)
            {
                return;
            }

            persistantStorage = new PersistentStorage(device);
            persistantStorage.MountFileSystem();
            driveMounted = true;
        }
        private void DeviceConnectedEvent(USBH_Device device)
        {
            if (device.PRODUCT_ID == 0x0202 && device.VENDOR_ID == 0x1130 && device.INTERFACE_INDEX == 0)
            {
                Debug.Print("Device connected...");
                launcherPod = new MisileLauncher(device);

                // Notify the user that misile launcher is available
                multicolorLed.TurnGreen();
            }
        }
Esempio n. 14
0
        private void USBHostController_DeviceDisconnectedEvent(USBH_Device device)
        {
            switch (device.TYPE)
            {
            case USBH_DeviceType.MassStorage:
                lock (this.storageDevices)
                {
                    if (!this.storageDevices.Contains(device.ID))
                    {
                        return;
                    }

                    var ps = (PersistentStorage)this.storageDevices[device.ID];
                    ps.UnmountFileSystem();
                    ps.Dispose();
                    this.storageDevices.Remove(device.ID);
                }

                break;

            case USBH_DeviceType.Mouse:
                lock (this.mice)
                {
                    if (!this.mice.Contains(device.ID))
                    {
                        return;
                    }

                    var mouse = (USBH_Mouse)this.mice[device.ID];
                    this.OnMouseDisconnectedEvent(this, mouse);
                    this.mice.Remove(device.ID);
                }

                break;

            case USBH_DeviceType.Keyboard:
                lock (this.keyboards)
                {
                    if (!this.keyboards.Contains(device.ID))
                    {
                        return;
                    }

                    var keyboard = (USBH_Keyboard)this.keyboards[device.ID];
                    this.OnKeyboardDisconnectedEvent(this, keyboard);
                    this.keyboards.Remove(device.ID);
                }

                break;

            default:
                break;
            }
        }
Esempio n. 15
0
        private void DeviceDisconnectedEvent(USBH_Device device)
        {
            // this is not implemented yet
            if (IsConnected && device.TYPE == USBH_DeviceType.Unknown && device.VENDOR_ID == vendorId && productId == productId)
            {
                IsConnected = false;

                XBoxThread.Join();

                XBoxInputPipe    = null;
                XBoxJoystickData = null;
            }
        }
Esempio n. 16
0
        /// <summary>
        /// This method is called when a device is plugged into the USB host.
        /// </summary>
        /// <param name="device">The device detected.</param>
        private static void DeviceConnected(USBH_Device device)
        {
            switch (device.TYPE)
            {
            case USBH_DeviceType.MassStorage:
                ps = new PersistentStorage(device);
                ps.MountFileSystem();
                break;

            default:
                break;
            }
        }
Esempio n. 17
0
        private void USBHostController_DeviceConnectedEvent(USBH_Device device)
        {
            try
            {
                switch (device.TYPE)
                {
                case USBH_DeviceType.MassStorage:
                    lock (this.storageDevices)
                    {
                        var ps = new PersistentStorage(device);
                        ps.MountFileSystem();
                        this.storageDevices.Add(device.ID, ps);
                    }

                    break;

                case USBH_DeviceType.Mouse:
                    lock (this.mice)
                    {
                        var mouse = new USBH_Mouse(device);
                        mouse.SetCursorBounds(int.MinValue, int.MaxValue, int.MinValue, int.MaxValue);
                        this.mice.Add(device.ID, mouse);
                        this.OnMouseConnectedEvent(this, mouse);
                    }

                    break;

                case USBH_DeviceType.Keyboard:
                    lock (this.keyboards)
                    {
                        var keyboard = new USBH_Keyboard(device);
                        this.keyboards.Add(device.ID, keyboard);
                        this.OnKeyboardConnectedEvent(this, keyboard);
                    }

                    break;

                case USBH_DeviceType.Webcamera:
                    ErrorPrint("Use GTM.GHIElectronics.Camera for USB WebCamera support.");
                    break;

                default:
                    ErrorPrint("USB device is not supported by the Gadgeteer driver. More devices are supported by the GHI USB Host driver. Remove the USB Host from the designer, and proceed without using Gadgeteer code.");
                    break;
                }
            }
            catch (Exception)
            {
                ErrorPrint("Unable to identify USB Host device.");
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UsbShuttlePro"/> class.
        /// </summary>
        /// <param name="device">USB Host RAW Device</param>
        public UsbShuttlePro(USBH_Device device)
        {
            jogWheel = new USBH_RawDevice(device);
            var cd = jogWheel.GetConfigurationDescriptors(0);

            jogWheel.SendSetupTransfer(0x00, 0x09, cd.bConfigurationValue, 0x00);
            var jogWheelEp = cd.interfaces[0].endpoints[0];

            jogWheelPipe = jogWheel.OpenPipe(jogWheelEp);
            jogWheelPipe.TransferTimeout = 0;

            jogWheelThread = ThreadFactory.CreateThread(JogReaderMonitor, ThreadPriority.Highest);
            jogWheelThread.Start();
        }
Esempio n. 19
0
 void USBHostController_DeviceConnectedEvent(USBH_Device device)
 {
     if (device.TYPE == USBH_DeviceType.Keyboard)
     {
         if (_KeyboardAndMouseInput == null)
             _KeyboardAndMouseInput = new KeyboardAndMouseInput(_UI, _KeyboardAndMouseOutput, _FiddleConfig, _DebuggerOnUsb);
         _KeyboardAndMouseInput.BeginMonitorKeyboardFrom(device);
     }
     else if (device.TYPE == USBH_DeviceType.Mouse)
     {
         if (_KeyboardAndMouseInput == null)
             _KeyboardAndMouseInput = new KeyboardAndMouseInput(_UI, _KeyboardAndMouseOutput, _FiddleConfig, _DebuggerOnUsb);
         _KeyboardAndMouseInput.BeginMonitorMouseFrom(device);
     }
 }
Esempio n. 20
0
 static void DeviceDisconnectedEvent(USBH_Device device)
 {
     if (device.TYPE == USBH_DeviceType.Keyboard)
     {
         _keyboard.KeyDown -= _keyboard_KeyDown;
         _keyboard.KeyUp   -= _keyboard_KeyUp;
         _keyboard          = null;
     }
     else if (device.TYPE == USBH_DeviceType.Mouse)
     {
         _mouse.MouseMove   -= _mouse_MouseMove;
         _mouse              = null;
         Core.MouseAvailable = false;
     }
 }
        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();
        }
Esempio n. 22
0
        static void DeviceConnectedEvent(USBH_Device device)
        {
            //Check if device is a PS3 Controller
            if (device.VENDOR_ID != PS3Controller.PS3_VENDOR_ID || device.PRODUCT_ID != PS3Controller.PS3_PRODUCT_ID)
            {
                if (device.TYPE == USBH_DeviceType.Hub)
                {
                    WriteSerial("Hub Connected");
                }
                else if (device.PRODUCT_ID == Bluetooth.CSR_PRODUCT_ID && device.VENDOR_ID == Bluetooth.CSR_VENDOR_ID)//Check if it is the bluetooth dongle
                {
                    WriteSerial("Bluetooth Dongle Connected");
                    BT = new Bluetooth(device);
                }
                else if (device.VENDOR_ID == PS3Move.PS3MOVE_VENDOR_ID && device.PRODUCT_ID == PS3Move.PS3MOVE_PRODUCT_ID)
                {
                    WriteSerial("PS3 Move Controller Connected");
                    Move = new PS3Move(device);
                }
                else if (device.VENDOR_ID == PS3Navigation.PS3NAVIGATION_VENDOR_ID && device.PRODUCT_ID == PS3Navigation.PS3NAVIGATION_PRODUCT_ID)
                {
                    WriteSerial("PS3 Navigation Controller Connected");
                    Navigation = new PS3Navigation(device);
                }
                else
                {
                    WriteSerial("Unknown Device Connected");
                }
                return;
            }
            if (PS3Connected == PS3Max)//Check if the maximum number of controller is exceeded
            {
                WriteSerial(PS3Max + " Controllers are already connected");
                return;
            }

            PS3[PS3Connected]       = new PS3Controller(device); //Connect the PS3 Controller
            PS3Device[PS3Connected] = device;                    //Store the device see "DeviceDisconnectedEvent"
            PS3SetLED(PS3Connected);                             //Set the specific LED on
            runThread[PS3Connected] = true;                      //Start the loop
            WriteSerial("PS3 Controller: " + (PS3Connected + 1) + " - Connected");

            PS3Connected++;
        }
Esempio n. 23
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();
        }
Esempio n. 24
0
        private void USBHostController_DeviceDisconnectedEvent(USBH_Device device)
        {
            try {
                if (device.TYPE == USBH_DeviceType.Webcamera)
                {
                    _cameraStatus    = CameraStatus.Disconnected;
                    _runThread       = false;
                    _TakePictureFlag = false;
                    this._camera.StopStreaming();
                    _camera = null;
                    DebugPrint("Camera disconnected.");
                }
            }
            catch { }

            if (device.TYPE == USBH_DeviceType.Webcamera)
            {
                OnCameraDisconnectedEvent(this);
            }
        }
Esempio n. 25
0
        private static void USBDevice_Connected(USBH_Device device)
        {
            if (device.TYPE == USBH_DeviceType.MassStorage)
            {
                Drive drive = new Drive()
                {
                    Device = device
                };

                try
                {
                    drive.Storage = new PersistentStorage(device);
                    drive.Storage.MountFileSystem();
                    drives.Add(drive); // Add drive to Array
                }
                catch (Exception)      // e)
                {
                    //Debug.Print("couldn't mount!\n" + e.Message);
                }
            }
        }
        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();
        }
        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();
        }
Esempio n. 28
0
        private void USBHostController_DeviceConnectedEvent(USBH_Device device)
        {
            try {
                if (device.TYPE == USBH_DeviceType.Webcamera)
                {
                    _camera = new USBH_Webcam(device);

                    this._cameraThread = new Thread(CameraCommunication);
                    _runThread         = true;
                    this._cameraThread.Start();

                    this._cameraStatus = CameraStatus.Ready;
                    DebugPrint("Camera connected.");
                }
            }
            catch { }

            if (device.TYPE == USBH_DeviceType.Webcamera)
            {
                CameraConnectedEvent(this);
            }
        }
Esempio n. 29
0
 static void DeviceConnectedEvent(USBH_Device device)
 {
     if (device.TYPE == USBH_DeviceType.Keyboard)
     {
         _keyboard          = new USBH_Keyboard(device);
         _keyboard.KeyDown += _keyboard_KeyDown;
         _keyboard.KeyUp   += _keyboard_KeyUp;
         Debug.Print("Keyboard attached");
     }
     else if (device.TYPE == USBH_DeviceType.Mouse)
     {
         _mouse = new USBH_Mouse(device);
         _mouse.SetCursorBounds(0, Core.ScreenWidth, 0, Core.ScreenHeight);
         _mouse.SetCursor(0, 0);
         _mouse.Scale(20);
         _mouse.MouseMove   += _mouse_MouseMove;
         _mouse.MouseDown   += _mouse_MouseDown;
         _mouse.MouseUp     += _mouse_MouseUp;
         Core.MouseAvailable = true;
         Debug.Print("Mouse attached");
     }
 }
Esempio n. 30
0
        public void BeginMonitorKeyboardFrom(USBH_Device device)
        {
            _Keyboard               = new USBH_Keyboard(device);
            _Keyboard.KeyUp        += new USBH_KeyboardEventHandler(_HostKeyboard_KeyUp);
            _Keyboard.KeyDown      += new USBH_KeyboardEventHandler(_HostKeyboard_KeyDown);
            _Keyboard.Disconnected += new USBH_KeyboardEventHandler(_Keyboard_Disconnected);

            // Create a random seed using:
            uint seed = _Config.RandomSeed;                                             // A random number from the internet!

            seed  = seed ^ (uint)(((uint)device.VENDOR_ID << 16) | device.PRODUCT_ID);  // The USB vendor and device ids.
            seed  = seed ^ (uint)(device.ID << 9);                                      // Some other USB ID.
            seed  = seed ^ (uint)(Utility.GetMachineTime().Ticks & 0x00000000ffffffff); // The current time.
            _Rand = new Random((int)seed);

            // Nothing is scheduled up front, we have to wait for the minimum time & keystrokes before anything happens.
            SetMinimumCounters();
            _NextFiddleEvents.Change(Timeout.Infinite, Timeout.Infinite);
            _InactivityTimer.Change(Timeout.Infinite, Timeout.Infinite);
            _PublishedFiddle = null;
            _SelectedFiddle  = null;
            _IsInactive      = false;
        }
Esempio n. 31
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();
        }
        static void DeviceDisconnectedEvent(USBH_Device device)
        {
            //Check if device is a PS3 Controller
            if (device.VENDOR_ID != PS3Controller.PS3_VENDOR_ID || device.PRODUCT_ID != PS3Controller.PS3_PRODUCT_ID)
            {
                if (device.TYPE == USBH_DeviceType.Hub)
                {
                    WriteSerial("Hub Disconnected");
                    for (byte i = 0; i < PS3Connected; i++)//All controllers has to be stopped
                    {
                        runThread[i] = false;
                        PS3[i].Abort();
                        BT.Abort();
                    }
                }
                else if (device.PRODUCT_ID == Bluetooth.CSR_PRODUCT_ID && device.VENDOR_ID == Bluetooth.CSR_VENDOR_ID)
                {
                    WriteSerial("Bluetooth Dongle Disconnected");
                    PS3RumbleBT = false;
                    BT.Abort();
                }
                else if (device.VENDOR_ID == PS3Move.PS3MOVE_VENDOR_ID && device.PRODUCT_ID == PS3Move.PS3MOVE_PRODUCT_ID)
                {
                    WriteSerial("PS3 Move Controller Disconnected");
                    Move.Abort();
                }
                else if (device.VENDOR_ID == PS3Navigation.PS3NAVIGATION_VENDOR_ID && device.PRODUCT_ID == PS3Navigation.PS3NAVIGATION_PRODUCT_ID)
                {
                    WriteSerial("PS3 Navigation Disconnected");
                    Navigation.Abort();
                }
                else
                    WriteSerial("Unknown Device Disconnected");
                return;
            }

            PS3Connected--;

            if (device.ID == PS3Device[PS3Connected].ID)//Check if it is the last one
            {
                runThread[PS3Connected] = false;//Stop the loop for the last controller
                PS3Rumble[PS3Connected] = false;//Also stop the rumble thread if active
                PS3[PS3Connected].Abort();//Abort the reading thread
                WriteSerial("PS3 Controller: " + (PS3Connected + 1) + " - Disconnected");
            }
            else
            {
                byte PS3number;
                for (PS3number = 0; PS3number < PS3Connected; PS3number++)//Check which number that was disconnected
                    if (device.ID == PS3Device[PS3number].ID)
                        break;

                runThread[PS3number] = false;
                PS3Rumble[PS3number] = false;//Also stop the rumble thread if active
                PS3[PS3number].Abort();
                WriteSerial("PS3 Controller: " + (PS3number + 1) + " - Disconnected");

                //Move all the controllers from that point one down
                for (byte i = PS3number; i < PS3Connected; i++)//Does not include the last one, as it is allways moved one down
                {
                    //Stop that thread including the next one
                    runThread[i] = false;
                    PS3[i].Abort();
                    runThread[i + 1] = false;
                    PS3[i + 1].Abort();

                    //Move one down
                    PS3[i] = new PS3Controller(PS3Device[i + 1]);
                    PS3Device[i] = PS3Device[i + 1];
                    PS3SetLED(i);

                    runThread[i] = true;
                    WriteSerial("PS3 Controller: " + (i + 2) + " - Changed to " + (i + 1));
                }
            }
        }
Esempio n. 33
0
 /// <summary>
 /// This method is called when a device is pulled out of the USB host.
 /// </summary>
 /// <param name="device">The device pulled out.</param>
 private static void DeviceDisconnected(USBH_Device device)
 {
     ps.UnmountFileSystem();
     ps.Dispose();
     ps = null;
 }
        static void DeviceConnectedEvent(USBH_Device device)
        {
            //Check if device is a PS3 Controller
            if (device.VENDOR_ID != PS3Controller.PS3_VENDOR_ID || device.PRODUCT_ID != PS3Controller.PS3_PRODUCT_ID)
            {
                if (device.TYPE == USBH_DeviceType.Hub)
                    WriteSerial("Hub Connected");
                else if (device.PRODUCT_ID == Bluetooth.CSR_PRODUCT_ID && device.VENDOR_ID == Bluetooth.CSR_VENDOR_ID)//Check if it is the bluetooth dongle
                {
                    WriteSerial("Bluetooth Dongle Connected");
                    BT = new Bluetooth(device);
                }
                else if (device.VENDOR_ID == PS3Move.PS3MOVE_VENDOR_ID && device.PRODUCT_ID == PS3Move.PS3MOVE_PRODUCT_ID)
                {
                    WriteSerial("PS3 Move Controller Connected");
                    Move = new PS3Move(device);
                }
                else if (device.VENDOR_ID == PS3Navigation.PS3NAVIGATION_VENDOR_ID && device.PRODUCT_ID == PS3Navigation.PS3NAVIGATION_PRODUCT_ID)
                {
                    WriteSerial("PS3 Navigation Controller Connected");
                    Navigation = new PS3Navigation(device);
                }
                else
                    WriteSerial("Unknown Device Connected");
                return;
            }
            if (PS3Connected == PS3Max)//Check if the maximum number of controller is exceeded
            {
                WriteSerial(PS3Max + " Controllers are already connected");
                return;
            }

            PS3[PS3Connected] = new PS3Controller(device);//Connect the PS3 Controller
            PS3Device[PS3Connected] = device;//Store the device see "DeviceDisconnectedEvent"
            PS3SetLED(PS3Connected);//Set the specific LED on
            runThread[PS3Connected] = true;//Start the loop
            WriteSerial("PS3 Controller: " + (PS3Connected + 1) + " - Connected");

            PS3Connected++;
        }
Esempio n. 35
0
        private static void USBDevice_Connected(USBH_Device device)
        {
            if (device.TYPE == USBH_DeviceType.MassStorage)
            {
                Drive drive = new Drive() { Device = device };

                try
                {
                    drive.Storage = new PersistentStorage(device);
                    drive.Storage.MountFileSystem();
                    drives.Add(drive); // Add drive to Array
                }
                catch (Exception)// e)
                {
                    //Debug.Print("couldn't mount!\n" + e.Message);
                }
            }
        }
Esempio n. 36
0
 private static void USBDevice_BadConnection(USBH_Device device)
 {
     if (USBDeviceBadConnection != null)
         USBDeviceBadConnection(device);
 }
Esempio n. 37
0
 private static void USBDevice_Disconnected(USBH_Device device)
 {
     if (USBDeviceRemoved != null)
         USBDeviceRemoved(device);
 }
Esempio n. 38
0
 private static void USBDevice_Connected(USBH_Device device)
 {
     if (USBDeviceInserted != null)
         USBDeviceInserted(device);
 }
Esempio n. 39
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);
            }
        }
Esempio n. 40
0
 private void USBDevice_Removed(USBH_Device device)
 {
     switch (device.TYPE)
     {
         case USBH_DeviceType.MassStorage:
             iconUSBMassSrorage.Visible = false;
             UpdateFileBrowser();
             break;
         case USBH_DeviceType.Keyboard:
             iconUSBKeyboard.Visible = false;
             //((USBH_Keyboard)Model.USBDevices.Keyboard[0]).KeyUp -= OnKeyUp;
             break;
         case USBH_DeviceType.Mouse:
             iconUSBMouse.Visible = false;
             //UnhandleMouse();
             break;
         default:
             break;
     }
 }
Esempio n. 41
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;
                    }
                }
            }
        }
Esempio n. 42
0
 static void DeviceDisconnectedEvent(USBH_Device device)
 {
     isReady = false;
     Debug.Print("isReady is false!");
 }
        long timerLEDRumble; // used to continuously set PS3 Move controller LED and rumble values

        #endregion Fields

        #region Constructors

        public Bluetooth(USBH_Device device)
        {
            if (device.VENDOR_ID != CSR_VENDOR_ID || device.PRODUCT_ID != CSR_PRODUCT_ID)//Check if the device is a Bluetooth dongle
                throw new InvalidOperationException();

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

            IntInPipe = raw.OpenPipe(cd.interfaces[0].endpoints[0]); // Interrupt In
            BulkInPipe = raw.OpenPipe(cd.interfaces[0].endpoints[1]); // Bulk In
            BulkOutPipe = raw.OpenPipe(cd.interfaces[0].endpoints[2]); // Bulk Out

            //Add transfer timeout for better stability
            IntInPipe.TransferTimeout = 5;
            BulkInPipe.TransferTimeout = 5;

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

            //Needed for PS3 Dualshock Controller to work
            for (int i = 0; i < PS3Controller.OUTPUT_REPORT_BUFFER.Length; i++)
                HIDBuffer[i + 2] = PS3Controller.OUTPUT_REPORT_BUFFER[i];//First two bytes reserved for report type and ID

            HIDBuffer[0] = 0x52;// HID BT Set_report (0x50) | Report Type (Output 0x02)
            HIDBuffer[1] = 0x01;// Report ID

            //Needed for PS3 Move Controller commands to work
            HIDMoveBuffer[0] = 0xA2;// HID BT DATA_request (0xA0) | Report Type (Output 0x02)
            HIDMoveBuffer[1] = 0x02;// Report ID

            IntInThread = new Thread(IntReadingThread);
            IntInThread.Start();

            BulkInThread = new Thread(BulkReadingThread);
            BulkInThread.Priority = ThreadPriority.Highest;
            BulkInThread.Start();

            WriteSerial("CSR Initialized");
        }
Esempio n. 44
0
        private static void SetupUSB()
        {
            Trace.TraceInformation("Setting up USB host...");

            USBHostController.DeviceBadConnectionEvent +=
                (device) =>
            {
                Trace.TraceInformation("USB device bad connection");
            };

            USBHostController.DeviceDisconnectedEvent +=
                (device) =>
            {
                Trace.TraceInformation("USB device disconnected");

                switch (device.TYPE)
                {
                case USBH_DeviceType.Serial_FTDI:
                    //webhost.Stop();
                    automationController.Dispose();
                    break;
                }
            };

            USBHostController.DeviceConnectedEvent +=
                (device) =>
            {
                Trace.TraceInformation("USB device connected");

                switch (device.TYPE)
                {
                case USBH_DeviceType.Serial_FTDI:
                    var usbSerial = new USBH_SerialUSB(device, 19200, Parity.None, 8, System.IO.Ports.StopBits.One);

                    // PowerLinc USB Dual-Band #2413U
                    if (device.VENDOR_ID == InsteonAutomationController.VendorID & device.PRODUCT_ID == InsteonAutomationController.ProductID)
                    {
                        Trace.TraceInformation("PowerLinc USB Dual-Band #2413U");

                        automationController = new InsteonAutomationController(settings, usbSerial);
                        automationController.Initalize();

                        //webhost.Start(settings, automationController);
                        //SetupTimers();
                    }
                    break;

                case USBH_DeviceType.Unknown:
                    // Aeon Labs Z-Stick2
                    if (device.VENDOR_ID == ZWaveAutomationController.VendorID & device.PRODUCT_ID == ZWaveAutomationController.ProductID)
                    {
                        Trace.TraceInformation("Aeon Labs Z-Stick2");

                        USBH_Device silabs = new USBH_Device(device.ID, device.INTERFACE_INDEX, USBH_DeviceType.Serial_SiLabs, device.VENDOR_ID, device.PRODUCT_ID, device.PORT_NUMBER);
                        usbSerial = new USBH_SerialUSB(silabs, 19200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
                        usbSerial.Open();

                        automationController = new ZWaveAutomationController(settings, usbSerial);
                        automationController.Initalize();
                    }
                    break;
                }
            };

            USBHostController.GetDevices();
        }
Esempio n. 45
0
        static void DeviceDisconnectedEvent(USBH_Device device)
        {
            //Check if device is a PS3 Controller
            if (device.VENDOR_ID != PS3Controller.PS3_VENDOR_ID || device.PRODUCT_ID != PS3Controller.PS3_PRODUCT_ID)
            {
                if (device.TYPE == USBH_DeviceType.Hub)
                {
                    WriteSerial("Hub Disconnected");
                    for (byte i = 0; i < PS3Connected; i++)//All controllers has to be stopped
                    {
                        runThread[i] = false;
                        PS3[i].Abort();
                        BT.Abort();
                    }
                }
                else if (device.PRODUCT_ID == Bluetooth.CSR_PRODUCT_ID && device.VENDOR_ID == Bluetooth.CSR_VENDOR_ID)
                {
                    WriteSerial("Bluetooth Dongle Disconnected");
                    PS3RumbleBT = false;
                    BT.Abort();
                }
                else if (device.VENDOR_ID == PS3Move.PS3MOVE_VENDOR_ID && device.PRODUCT_ID == PS3Move.PS3MOVE_PRODUCT_ID)
                {
                    WriteSerial("PS3 Move Controller Disconnected");
                    Move.Abort();
                }
                else if (device.VENDOR_ID == PS3Navigation.PS3NAVIGATION_VENDOR_ID && device.PRODUCT_ID == PS3Navigation.PS3NAVIGATION_PRODUCT_ID)
                {
                    WriteSerial("PS3 Navigation Disconnected");
                    Navigation.Abort();
                }
                else
                {
                    WriteSerial("Unknown Device Disconnected");
                }
                return;
            }

            PS3Connected--;

            if (device.ID == PS3Device[PS3Connected].ID) //Check if it is the last one
            {
                runThread[PS3Connected] = false;         //Stop the loop for the last controller
                PS3Rumble[PS3Connected] = false;         //Also stop the rumble thread if active
                PS3[PS3Connected].Abort();               //Abort the reading thread
                WriteSerial("PS3 Controller: " + (PS3Connected + 1) + " - Disconnected");
            }
            else
            {
                byte PS3number;
                for (PS3number = 0; PS3number < PS3Connected; PS3number++)//Check which number that was disconnected
                {
                    if (device.ID == PS3Device[PS3number].ID)
                    {
                        break;
                    }
                }

                runThread[PS3number] = false;
                PS3Rumble[PS3number] = false;//Also stop the rumble thread if active
                PS3[PS3number].Abort();
                WriteSerial("PS3 Controller: " + (PS3number + 1) + " - Disconnected");

                //Move all the controllers from that point one down
                for (byte i = PS3number; i < PS3Connected; i++)//Does not include the last one, as it is allways moved one down
                {
                    //Stop that thread including the next one
                    runThread[i] = false;
                    PS3[i].Abort();
                    runThread[i + 1] = false;
                    PS3[i + 1].Abort();

                    //Move one down
                    PS3[i]       = new PS3Controller(PS3Device[i + 1]);
                    PS3Device[i] = PS3Device[i + 1];
                    PS3SetLED(i);

                    runThread[i] = true;
                    WriteSerial("PS3 Controller: " + (i + 2) + " - Changed to " + (i + 1));
                }
            }
        }