示例#1
0
 public string getDS4Battery(int index)
 {
     if (DS4Controllers[index] != null)
     {
         DS4Device d = DS4Controllers[index];
         String    battery;
         if (!d.IsAlive())
         {
             battery = "...";
         }
         if (d.Charging)
         {
             if (d.Battery >= 100)
             {
                 battery = Properties.Resources.Full;
             }
             else
             {
                 battery = d.Battery + "%+";
             }
         }
         else
         {
             battery = d.Battery + "%";
         }
         return(battery);
     }
     else
     {
         return(Properties.Resources.NA);
     }
 }
示例#2
0
 public string getShortDS4ControllerInfo(int index)
 {
     if (DS4Controllers[index] != null)
     {
         DS4Device d = DS4Controllers[index];
         String    battery;
         if (!d.IsAlive())
         {
             battery = "...";
         }
         if (d.Charging)
         {
             if (d.Battery >= 100)
             {
                 battery = Properties.Resources.Full;
             }
             else
             {
                 battery = d.Battery + "%+";
             }
         }
         else
         {
             battery = d.Battery + "%";
         }
         return(d.ConnectionType + " " + battery);
     }
     else
     {
         return(Properties.Resources.NoneText);
     }
 }
示例#3
0
        public void TimeoutConnection(DS4Device d)
        {
            try
            {
                System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                sw.Start();
                while (!d.IsAlive())
                {
                    if (sw.ElapsedMilliseconds < 1000)
                    {
                        System.Threading.Thread.SpinWait(500);
                    }
                    //If weve been waiting less than 1 second let the thread keep its processing chunk
                    else
                    {
                        System.Threading.Thread.Sleep(500);
                    }
                    //If weve been waiting more than 1 second give up some resources

                    if (sw.ElapsedMilliseconds > 5000)
                    {
                        throw new TimeoutException();                                //Weve waited long enough
                    }
                }
                sw.Reset();
            }
            catch (TimeoutException)
            {
                Stop(false);
                Start(false);
            }
        }
示例#4
0
 public string getDS4MacAddress(int index)
 {
     if (DS4Controllers[index] != null)
     {
         DS4Device d = DS4Controllers[index];
         if (!d.IsAlive())
         //return "Connecting..."; // awaiting the first battery charge indication
         {
             var TimeoutThread = new System.Threading.Thread(() => TimeoutConnection(d));
             TimeoutThread.IsBackground = true;
             TimeoutThread.Name         = "TimeoutFor" + d.MacAddress.ToString();
             TimeoutThread.Start();
             return(Properties.Resources.Connecting);
         }
         return(d.MacAddress);
     }
     else
     {
         return(String.Empty);
     }
 }
示例#5
0
 public string getDS4ControllerInfo(int index)
 {
     if (DS4Controllers[index] != null)
     {
         DS4Device d = DS4Controllers[index];
         if (!d.IsAlive())
         //return "Connecting..."; // awaiting the first battery charge indication
         {
             var TimeoutThread = new System.Threading.Thread(() => TimeoutConnection(d));
             TimeoutThread.IsBackground = true;
             TimeoutThread.Name         = "TimeoutFor" + d.MacAddress.ToString();
             TimeoutThread.Start();
             return(Properties.Resources.Connecting);
         }
         String battery;
         if (d.Charging)
         {
             if (d.Battery >= 100)
             {
                 battery = Properties.Resources.Charged;
             }
             else
             {
                 battery = Properties.Resources.Charging.Replace("*number*", d.Battery.ToString());
             }
         }
         else
         {
             battery = Properties.Resources.Battery.Replace("*number*", d.Battery.ToString());
         }
         return(d.MacAddress + " (" + d.ConnectionType + "), " + battery);
         //return d.MacAddress + " (" + d.ConnectionType + "), Battery is " + battery + ", Touchpad in " + modeSwitcher[index].ToString();
     }
     else
     {
         return(String.Empty);
     }
 }