Пример #1
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;
        }
Пример #2
0
        public override Boolean Start()
        {
            m_Started = true;

            Byte Index = 0;

            // enumerate DS4 devices
            for (Byte instance = 0; instance < _device.Length && Index < _device.Length; instance++)
            {
                try
                {
                    UsbDevice current = new UsbDs4();
                    current.PadId = (DsPadId)Index;

                    if (current.Open(instance))
                    {
                        if (LogArrival(current))
                        {
                            current.HidReportReceived += new EventHandler<ReportEventArgs>(On_Report);

                            _device[Index++] = current;
                        }
                        else current.Close();
                    }
                    else current.Close();
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Unexpected error: {0}", ex);
                    break;
                }
            }

            // enumerate DS3 devices
            for (Byte instance = 0; instance < _device.Length && Index < _device.Length; instance++)
            {
                try
                {
                    UsbDevice current = new UsbDs3();
                    current.PadId = (DsPadId)Index;

                    if (current.Open(instance))
                    {
                        if (LogArrival(current))
                        {
                            current.HidReportReceived += new EventHandler<ReportEventArgs>(On_Report);

                            _device[Index++] = current;
                        }
                        else current.Close();
                    }
                    else current.Close();
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Unexpected error: {0}", ex);
                    break;
                }
            }

            try
            {
                for (Index = 0; Index < _device.Length; Index++)
                {
                    if (_device[Index].State == DsState.Reserved)
                    {
                        _device[Index].Start();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("Unexpected error: {0}", ex);
            }

            return base.Start();
        }
Пример #3
0
        public override Boolean Start()
        {
            m_Started = true;

            Byte Index = 0;

            // enumerate DS4 devices
            for (Byte instance = 0; instance < _device.Length && Index < _device.Length; instance++)
            {
                try
                {
                    UsbDevice current = new UsbDs4();
                    current.PadId = (DsPadId)Index;

                    if (current.Open(instance))
                    {
                        if (LogArrival(current))
                        {
                            current.Report += new EventHandler <ReportEventArgs>(On_Report);

                            _device[Index++] = current;
                        }
                        else
                        {
                            current.Close();
                        }
                    }
                    else
                    {
                        current.Close();
                    }
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Unexpected error: {0}", ex);
                    break;
                }
            }

            // enumerate DS3 devices
            for (Byte instance = 0; instance < _device.Length && Index < _device.Length; instance++)
            {
                try
                {
                    UsbDevice current = new UsbDs3();
                    current.PadId = (DsPadId)Index;

                    if (current.Open(instance))
                    {
                        if (LogArrival(current))
                        {
                            current.Report += new EventHandler <ReportEventArgs>(On_Report);

                            _device[Index++] = current;
                        }
                        else
                        {
                            current.Close();
                        }
                    }
                    else
                    {
                        current.Close();
                    }
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Unexpected error: {0}", ex);
                    break;
                }
            }

            try
            {
                for (Index = 0; Index < _device.Length; Index++)
                {
                    if (_device[Index].State == DsState.Reserved)
                    {
                        _device[Index].Start();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("Unexpected error: {0}", ex);
            }

            return(base.Start());
        }
Пример #4
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.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 == DsState.Connected && Path == _device[index].Path)
                    {
                        Log.InfoFormat("-- Device Removal [{0}]", _device[index].Local);

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

            return(DsPadId.None);
        }
Пример #5
0
        public override Boolean Start()
        {
            m_Started = true;

            Byte Index = 0;

            for (Byte Instance = 0; Instance < Device.Length && Index < Device.Length; Instance++)
            {
                try
                {
                    UsbDevice Current = new UsbDs4();
                    Current.PadId = (DsPadId)Index;

                    if (Current.Open(Instance))
                    {
                        if (LogArrival(Current))
                        {
                            Current.Debug  += new EventHandler <DebugEventArgs> (On_Debug);
                            Current.Report += new EventHandler <ReportEventArgs>(On_Report);

                            Device[Index++] = Current;
                        }
                        else
                        {
                            Current.Close();
                        }
                    }
                    else
                    {
                        Current.Close();
                    }
                }
                catch { break; }
            }

            for (Byte Instance = 0; Instance < Device.Length && Index < Device.Length; Instance++)
            {
                try
                {
                    UsbDevice Current = new UsbDs3();
                    Current.PadId = (DsPadId)Index;

                    if (Current.Open(Instance))
                    {
                        if (LogArrival(Current))
                        {
                            Current.Debug  += new EventHandler <DebugEventArgs> (On_Debug);
                            Current.Report += new EventHandler <ReportEventArgs>(On_Report);

                            Device[Index++] = Current;
                        }
                        else
                        {
                            Current.Close();
                        }
                    }
                    else
                    {
                        Current.Close();
                    }
                }
                catch { break; }
            }

            try
            {
                for (Index = 0; Index < Device.Length; Index++)
                {
                    if (Device[Index].State == DsState.Reserved)
                    {
                        Device[Index].Start();
                    }
                }
            }
            catch { }

            return(base.Start());
        }
Пример #6
0
        public override DsPadId 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 (Class.ToUpper() == UsbDs3.USB_CLASS_GUID.ToUpper())
                {
                    Arrived = new UsbDs3(); LogDebug("-- DS3 Arrival Event");
                }
                if (Class.ToUpper() == UsbDs4.USB_CLASS_GUID.ToUpper())
                {
                    Arrived = new UsbDs4(); LogDebug("-- DS4 Arrival Event");
                }

                if (Arrived.Open(Path))
                {
                    LogDebug(String.Format("-- 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.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 == DsState.Connected && Path == Device[Index].Path)
                    {
                        LogDebug(String.Format("-- Device Removal [{0}]", Device[Index].Local));

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

            return(DsPadId.None);
        }