コード例 #1
0
ファイル: BusDevice.cs プロジェクト: wellblended88/ds4-tool
        public override Boolean Start()
        {
            if (IsActive)
            {
                int ind = 0;
                LogDebug("Starting....");
                LogDebug("Searching for controllers....");
                int[] pid = { 0x05C4 };
                try
                {
                    IEnumerable <HidDevice> devices = HidDevices.Enumerate(0x054C, pid);
                    foreach (HidDevice device in devices)
                    {
                        LogDebug("Found Controller: VID:" + device.Attributes.VendorHexId + " PID:" + device.Attributes.ProductHexId);
                        device.OpenDevice(Global.getUseExclusiveMode());
                        if (device.IsOpen)
                        {
                            bool alreadyAttached = false;
                            for (int i = 0; i < DS4Controllers.Length && !alreadyAttached; i++)
                            {
                                alreadyAttached = DS4Controllers[i] != null && DS4Controllers[i].MACAddress == device.readSerial();
                            }
                            if (alreadyAttached)
                            {
                                continue;
                            }

                            DS4Controllers[ind] = new DS4Device(device, ind);
                            ledColor color = Global.loadColor(ind);
                            DS4Controllers[ind].LedColor = color;
                            DS4Controllers[ind].sendOutputReport();
                            Plugin(ind + 1);
                            isWorkersShouldRun = true;
                            int t = ind;
                            if (workers
                                [ind].ThreadState == System.Threading.ThreadState.Aborted || workers[ind].ThreadState == System.Threading.ThreadState.Stopped)
                            {
                                workers[ind] = new Thread(() =>
                                                          { ProcessData(t); });
                            }
                            workers[ind].Start();
                            LogDebug("Controller " + (ind + 1) + " ready to use");
                        }
                        else
                        {
                            LogDebug("Could not open the controller " + (ind + 1) + " for exclusive access");
                            LogDebug("Try to quit any applications that can be using the controller");
                            LogDebug("Then press Stop and Start to try accessing device again");
                        }


                        ind++;
                    }

                    if (ind == 0 && DS4Controllers[0] == null)
                    {
                        LogDebug("No controllers found");
                    }
                }
                catch (Exception e)
                {
                    LogDebug(e.ToString());
                }
            }
            return(true);
        }
コード例 #2
0
ファイル: BusDevice.cs プロジェクト: Conist/ds4-tool
        public override Boolean Start()
        {
            if (IsActive)
            {
                int ind = 0;
                LogDebug("Starting....");
                LogDebug("Searching for controllers....");
                int[] pid = { 0x05C4 };
                try
                {
                    IEnumerable<HidDevice> devices = HidDevices.Enumerate(0x054C, pid);
                    foreach (HidDevice device in devices)
                    {
                        LogDebug("Found Controller: VID:" + device.Attributes.VendorHexId + " PID:" + device.Attributes.ProductHexId);
                        device.OpenDevice(Global.getUseExclusiveMode());
                        if (device.IsOpen)
                        {
                            bool alreadyAttached = false;
                            for (int i = 0; i < DS4Controllers.Length && !alreadyAttached; i++)
                                alreadyAttached = DS4Controllers[i] != null && DS4Controllers[i].MACAddress == device.readSerial();
                            if (alreadyAttached)
                                continue;

                            DS4Controllers[ind] = new DS4Device(device, ind);
                            ledColor color = Global.loadColor(ind);
                            DS4Controllers[ind].LedColor = color;
                            DS4Controllers[ind].sendOutputReport();
                            Plugin(ind + 1);
                            isWorkersShouldRun = true;
                            int t = ind;
                            if(workers
                                [ind].ThreadState == System.Threading.ThreadState.Aborted || workers[ind].ThreadState == System.Threading.ThreadState.Stopped)
                                workers[ind] = new Thread(() =>
                                { ProcessData(t); });
                            workers[ind].Start();
                            LogDebug("Controller " + (ind + 1) + " ready to use");
                        }
                        else
                        {
                            LogDebug("Could not open the controller " + (ind + 1) + " for exclusive access");
                            LogDebug("Try to quit any applications that can be using the controller");
                            LogDebug("Then press Stop and Start to try accessing device again");
                        }


                        ind++;
                    }

                    if (ind == 0 && DS4Controllers[0] == null)
                    {
                        LogDebug("No controllers found");
                    }
                }
                catch (Exception e)
                {
                    LogDebug(e.ToString());
                }

            }
            return true;
        }
コード例 #3
0
ファイル: BusDevice.cs プロジェクト: wellblended88/ds4-tool
 // Hot plug
 public void StartNewControllers()
 {
     if (IsActive)
     {
         int[] pid = { 0x05C4 };
         try
         {
             IEnumerable <HidDevice> devices = HidDevices.Enumerate(0x054C, pid);
             foreach (HidDevice device in devices)
             {
                 if (!device.IsOpen)
                 {
                     device.OpenDevice(Global.getUseExclusiveMode());
                 }
                 if (device.IsOpen)
                 {
                     if (((Func <bool>) delegate
                     {
                         for (Int32 Index = 0; Index < DS4Controllers.Length; Index++)
                         {
                             lock (ds4locks[Index])
                             {
                                 if (DS4Controllers[Index] != null &&
                                     DS4Controllers[Index].Device != null &&
                                     DS4Controllers[Index].MACAddress == device.readSerial())
                                 {
                                     return(true);
                                 }
                             }
                         }
                         return(false);
                     })())
                     {
                         continue;
                     }
                 }
                 else
                 {
                     continue;
                 }
                 for (Int32 Index = 0; Index < DS4Controllers.Length; Index++)
                 {
                     if (DS4Controllers[Index] == null || DS4Controllers[Index].Device == null)
                     {
                         LogDebug("New Controller Found: VID:"
                                  + device.Attributes.VendorHexId
                                  + " PID:" + device.Attributes.ProductHexId);
                         if (device.IsOpen)
                         {
                             DS4Controllers[Index] = new DS4Device(device, Index);
                             ledColor color = Global.loadColor(Index);
                             DS4Controllers[Index].sendOutputReport();
                             Plugin(Index + 1);
                             isWorkersShouldRun = true;
                             int t = Index;
                             if (workers
                                 [Index].ThreadState == System.Threading.ThreadState.Aborted || workers[Index].ThreadState == System.Threading.ThreadState.Stopped)
                             {
                                 workers[Index] = new Thread(() =>
                                                             { ProcessData(t); });
                             }
                             workers[Index].Start();
                             LogDebug("Controller " + (Index + 1) + " ready to use");
                             break;
                         }
                         else
                         {
                             LogDebug("Could not open the controller " + (Index + 1) + " for exclusive access");
                             LogDebug("Try to quit any applications that can be using the controller");
                             LogDebug("Then press Stop and Start to try accessing device again");
                         }
                     }
                 }
             }
         }
         catch (Exception e)
         {
             LogDebug(e.ToString());
         }
     }
 }
コード例 #4
0
ファイル: BusDevice.cs プロジェクト: Conist/ds4-tool
        // Hot plug
        public void StartNewControllers()
        {
            if (IsActive)
            {
                int[] pid = { 0x05C4 };
                try
                {
                    IEnumerable<HidDevice> devices = HidDevices.Enumerate(0x054C, pid);
                    foreach (HidDevice device in devices)
                    {
                        if (!device.IsOpen)
                            device.OpenDevice(Global.getUseExclusiveMode());
                        if (device.IsOpen)
                        {
                            if (((Func<bool>)delegate
                            {
                                for (Int32 Index = 0; Index < DS4Controllers.Length; Index++)
                                    lock (ds4locks[Index])
                                    {
                                        if (DS4Controllers[Index] != null
                                            && DS4Controllers[Index].Device != null &&
                                            DS4Controllers[Index].MACAddress == device.readSerial())
                                            return true;
                                    }
                                return false;
                            })())
                                continue;
                        }
                        else continue;
                        for (Int32 Index = 0; Index < DS4Controllers.Length; Index++)
                            if (DS4Controllers[Index] == null || DS4Controllers[Index].Device == null)
                            {
                                LogDebug("New Controller Found: VID:"
                                        + device.Attributes.VendorHexId
                                        + " PID:" + device.Attributes.ProductHexId);
                                if (device.IsOpen)
                                {
                                        DS4Controllers[Index] = new DS4Device(device, Index);
                                        ledColor color = Global.loadColor(Index);
                                        DS4Controllers[Index].sendOutputReport();
                                        Plugin(Index + 1);
                                        isWorkersShouldRun = true;
                                        int t = Index;
                                        if (workers
                                            [Index].ThreadState == System.Threading.ThreadState.Aborted || workers[Index].ThreadState == System.Threading.ThreadState.Stopped)
                                            workers[Index] = new Thread(() =>
                                            { ProcessData(t); });
                                        workers[Index].Start();
                                    LogDebug("Controller " + (Index + 1) + " ready to use");
                                    break;
                                }
                                else
                                {
                                    LogDebug("Could not open the controller " + (Index + 1) + " for exclusive access");
                                    LogDebug("Try to quit any applications that can be using the controller");
                                    LogDebug("Then press Stop and Start to try accessing device again");
                                    
                                   
                                }
                            }
                    }
                }
                catch (Exception e)
                {
                    LogDebug(e.ToString());
                }

            }
        }