Ejemplo n.º 1
0
        protected override void WndProc(ref Message m)
        {
            try
            {
                if (m.Msg == ScpDevice.WM_DEVICECHANGE)
                {
                    String Path;
                    ScpDevice.DEV_BROADCAST_HDR hdr;
                    Int32 Type = m.WParam.ToInt32();

                    hdr = (ScpDevice.DEV_BROADCAST_HDR)Marshal.PtrToStructure(m.LParam, typeof(ScpDevice.DEV_BROADCAST_HDR));

                    if (hdr.dbch_devicetype == ScpDevice.DBT_DEVTYP_DEVICEINTERFACE)
                    {
                        ScpDevice.DEV_BROADCAST_DEVICEINTERFACE_M deviceInterface;

                        deviceInterface = (ScpDevice.DEV_BROADCAST_DEVICEINTERFACE_M)Marshal.PtrToStructure(m.LParam, typeof(ScpDevice.DEV_BROADCAST_DEVICEINTERFACE_M));

                        Path = new String(deviceInterface.dbcc_name);
                        Path = Path.Substring(0, Path.IndexOf('\0')).ToUpper();

                        switch (Type)
                        {
                            case ScpDevice.DBT_DEVICEARRIVAL:

                                if (usbDevice.State != DsState.Connected)
                                {
                                    usbDevice.Close();
                                    usbDevice = new UsbDs3();

                                    if (usbDevice.Open(Path)) usbDevice.Start();
                                }
                                break;

                            case ScpDevice.DBT_DEVICEREMOVECOMPLETE:

                                if (Path == usbDevice.Path && usbDevice.State == DsState.Connected)
                                {
                                    usbDevice.Close();
                                }

                                break;
                        }
                    }
                }
            }
            catch { }

            base.WndProc(ref m);
        }
Ejemplo n.º 2
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 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());
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
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());
        }
Ejemplo n.º 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.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);
        }
Ejemplo n.º 7
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 (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);
        }