Low-level representation of an Scp-compatible Usb device.
Пример #1
0
        public override Ds3PadId Notify(ScpDevice.Notified Notification, String Class, String Path)
        {
            LogDebug(String.Format("++ Notify [{0}] [{1}] [{2}]", Notification, Class, Path));

            switch (Notification)
            {
                case ScpDevice.Notified.Arrival:
                    {
                        UsbDevice Arrived = new UsbDevice();

                        if (Arrived.Open(Path))
                        {
                            LogDebug(String.Format("-- Device Arrival [{0}]", Arrived.Local, Path));

                            if (LogArrival(Arrived))
                            {
                                if (Device[(Byte) Arrived.PadId].IsShutdown)
                                {
                                    Device[(Byte) Arrived.PadId].IsShutdown = false;

                                    Device[(Byte) Arrived.PadId].Close();
                                    Device[(Byte) Arrived.PadId] = Arrived;

                                    return Arrived.PadId;
                                }
                                else
                                {
                                    Arrived.Debug  += new EventHandler<DebugEventArgs> (On_Debug );
                                    Arrived.Report += new EventHandler<ReportEventArgs>(On_Report);

                                    Device[(Byte) Arrived.PadId].Close();
                                    Device[(Byte) Arrived.PadId] = Arrived;

                                    if (m_Started) Arrived.Start();
                                    return Arrived.PadId;
                                }
                            }
                        }

                        Arrived.Close();
                    }
                    break;

                case ScpDevice.Notified.Removal:
                    {
                        for (Int32 Index = 0; Index < Device.Length; Index++)
                        {
                            if (Device[Index].State == DeviceState.Connected && Path == Device[Index].Path)
                            {
                                LogDebug(String.Format("-- Device Removal [{0}]", Device[Index].Local, Path));

                                Device[Index].Stop();
                            }
                        }
                    }
                    break;
            }

            return Ds3PadId.None;
        }
Пример #2
0
        public virtual bool Close()
        {
            if (m_Reference != IntPtr.Zero)
            {
                ScpDevice.UnregisterNotify(m_Reference);
            }

            return(!m_Started);
        }
Пример #3
0
        public virtual DsPadId Notify(ScpDevice.Notified notification, string Class, string Path)
        {
            switch (notification)
            {
                case ScpDevice.Notified.Arrival:
                    break;

                case ScpDevice.Notified.Removal:
                    break;
            }

            return DsPadId.None;
        }
Пример #4
0
        public override DsPadId Notify(ScpDevice.Notified notification, string Class, string Path)
        {
            Log.DebugFormat("++ Notify [{0}] [{1}] [{2}]", notification, Class, Path);

            switch (notification)
            {
                case ScpDevice.Notified.Arrival:
                {
                    if (_device.State != DsState.Connected)
                    {
                        var arrived = new BthDongle();

                        if (arrived.Open(Path))
                        {
                            Log.DebugFormat("-- Device Arrival [{0}]", arrived.Local);

                            _device.Close();
                            _device = arrived;

                            _device.Arrival += On_Arrival;
                            _device.Report += On_Report;

                            if (m_Started) _device.Start();
                            break;
                        }

                        arrived.Close();
                        arrived.Dispose();
                    }
                }
                    break;

                case ScpDevice.Notified.Removal:

                    if (_device.Path == Path)
                    {
                        Log.DebugFormat("-- Device Removal [{0}]", _device.Local);

                        _device.Stop();
                    }
                    break;
            }

            return DsPadId.None;
        }
Пример #5
0
        public override Ds3PadId Notify(ScpDevice.Notified Notification, String Class, String Path)
        {
            LogDebug(String.Format("++ Notify [{0}] [{1}] [{2}]", Notification, Class, Path));

            switch (Notification)
            {
                case ScpDevice.Notified.Arrival:
                    {
                        if (Device.State != DeviceState.Connected)
                        {
                            BthDevice Arrived = new BthDevice();

                            if (Arrived.Open(Path))
                            {
                                LogDebug(String.Format("-- Device Arrival [{0}]", Arrived.Local, Path));

                                Device.Close();
                                Device = Arrived;

                                Device.Arrival += new EventHandler<ArrivalEventArgs>(On_Arrival);
                                Device.Debug   += new EventHandler<DebugEventArgs>  (On_Debug  );
                                Device.Report  += new EventHandler<ReportEventArgs> (On_Report );

                                if (m_Started) Device.Start();
                                break;
                            }

                            Arrived.Close();
                        }
                    }
                    break;

                case ScpDevice.Notified.Removal:

                    if (Device.Path == Path)
                    {
                        LogDebug(String.Format("-- Device Removal [{0}]", Device.Local, Path));

                        Device.Stop();
                    }
                    break;
            }

            return Ds3PadId.None;
        }
Пример #6
0
        public override DsPadId Notify(ScpDevice.Notified notification, String Class, String Path)
        {
            Log.InfoFormat("++ Notify [{0}] [{1}] [{2}]", notification, Class, Path);

            switch (notification)
            {
                case ScpDevice.Notified.Arrival:
                    {
                        UsbDevice arrived = new UsbDevice();

                        if (string.Equals(Class, UsbDs3.USB_CLASS_GUID, StringComparison.CurrentCultureIgnoreCase))
                        {
                            arrived = new UsbDs3();
                            Log.Debug("-- DS3 Arrival Event");
                        }

                        if (string.Equals(Class, UsbDs4.USB_CLASS_GUID, StringComparison.CurrentCultureIgnoreCase))
                        {
                            arrived = new UsbDs4();
                            Log.Debug("-- DS4 Arrival Event");
                        }

                        Log.InfoFormat("Arrival event for GUID {0} received", Class);

                        if (arrived.Open(Path))
                        {
                            Log.InfoFormat("-- Device Arrival [{0}]", arrived.Local);

                            if (LogArrival(arrived))
                            {
                                if (_device[(Byte)arrived.PadId].IsShutdown)
                                {
                                    _device[(Byte)arrived.PadId].IsShutdown = false;

                                    _device[(Byte)arrived.PadId].Close();
                                    _device[(Byte)arrived.PadId] = arrived;

                                    return arrived.PadId;
                                }
                                else
                                {
                                    arrived.HidReportReceived += new EventHandler<ReportEventArgs>(On_Report);

                                    _device[(Byte)arrived.PadId].Close();
                                    _device[(Byte)arrived.PadId] = arrived;

                                    if (m_Started) arrived.Start();
                                    return arrived.PadId;
                                }
                            }
                        }

                        arrived.Close();
                    }
                    break;

                case ScpDevice.Notified.Removal:
                    {
                        for (Int32 index = 0; index < _device.Length; index++)
                        {
                            if (_device[index].State == DsState.Connected && Path == _device[index].Path)
                            {
                                Log.InfoFormat("-- Device Removal [{0}]", _device[index].Local);

                                _device[index].Stop();
                            }
                        }
                    }
                    break;
            }

            return DsPadId.None;
        }
Пример #7
0
        /// <summary>
        ///     Gets called when a device was plugged in.
        /// </summary>
        /// <param name="notification">The <see cref="ScpDevice.Notified"/> type.</param>
        /// <param name="Class">The device class of the currently affected device.</param>
        /// <param name="path">The device path of the currently affected device.</param>
        /// <returns></returns>
        public override DsPadId Notify(ScpDevice.Notified notification, string Class, string path)
        {
            // ignore while component is in sleep mode
            if (_mSuspended) return DsPadId.None;

            var classGuid = Guid.Parse(Class);

            // forward message for wired DS4 to usb hub
            if (classGuid == UsbDs4.DeviceClassGuid)
            {
                return _usbHub.Notify(notification, Class, path);
            }

            // forward message for wired DS3 to usb hub
            if (classGuid == UsbDs3.DeviceClassGuid)
            {
                return _usbHub.Notify(notification, Class, path);
            }

            // forward message for wired Generic Gamepad to usb hub
            if (classGuid == UsbGenericGamepad.DeviceClassGuid)
            {
                return _usbHub.Notify(notification, Class, path);
            }

            // forward message for any wireless device to bluetooth hub
            if (classGuid == BthDongle.DeviceClassGuid)
            {
                _bthHub.Notify(notification, Class, path);
            }

            return DsPadId.None;
        }
Пример #8
0
        public override DsPadId Notify(ScpDevice.Notified notification, string Class, string Path)
        {
            if (_mSuspended) return DsPadId.None;

            // forward message for wired DS4 to usb hub
            if (Class == UsbDs4.USB_CLASS_GUID)
            {
                return _usbHub.Notify(notification, Class, Path);
            }

            // forward message for wired DS3 to usb hub
            if (Class == UsbDs3.USB_CLASS_GUID)
            {
                return _usbHub.Notify(notification, Class, Path);
            }

            // forward message for any wireless device to bluetooth hub
            if (Class == BthDongle.BTH_CLASS_GUID)
            {
                _bthHub.Notify(notification, Class, Path);
            }

            return DsPadId.None;
        }