Ejemplo n.º 1
0
 public static ledColor loadColor(int device)
 {
     ledColor color = new ledColor();
     color.red = m_Config.m_Leds[device][0];
     color.green = m_Config.m_Leds[device][1];
     color.blue = m_Config.m_Leds[device][2];
     return color;
 }
Ejemplo n.º 2
0
        public static ledColor loadColor(int device)
        {
            ledColor color = new ledColor();

            color.red   = m_Config.m_Leds[device][0];
            color.green = m_Config.m_Leds[device][1];
            color.blue  = m_Config.m_Leds[device][2];
            return(color);
        }
Ejemplo n.º 3
0
        public static ledColor getTransitionedColor(ledColor c1, ledColor c2, uint ratio)
        {
            ledColor color = new ledColor();

            color.red   = applyRatio(c1.red, c2.red, ratio);
            color.green = applyRatio(c1.green, c2.green, ratio);
            color.blue  = applyRatio(c1.blue, c2.blue, ratio);
            return(color);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
 // 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());
         }
     }
 }
Ejemplo n.º 6
0
 public static ledColor getTransitionedColor(ledColor c1, ledColor c2, uint ratio)
 {
     ledColor color = new ledColor();
     color.red = applyRatio(c1.red, c2.red, ratio);
     color.green = applyRatio(c1.green, c2.green, ratio);
     color.blue = applyRatio(c1.blue, c2.blue, ratio);
     return color;
 }