Exemple #1
0
 public string getShortEAll4ControllerInfo(int index)
 {
     if (controllers[index] != null)
     {
         IEAll4Device d = controllers[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);
     }
 }
Exemple #2
0
        public void TimeoutConnection(IEAll4Device 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);
            }
        }
        //called when devices is diconnected, timed out or has input reading failure
        public static void On_Removal(object sender, EventArgs e)
        {
            lock (Devices)
            {
                IEAll4Device ieAll4Device = (IEAll4Device)sender;

                if (!ieAll4Device.IsAlive())
                {
                    ieAll4Device.HidDevice.CloseDevice();
                    Devices.Remove(ieAll4Device.MacAddress);
                    DevicePaths.Remove(ieAll4Device.HidDevice.DevicePath);
                }
            }
        }
Exemple #4
0
 public string getEAll4ControllerInfo(int index)
 {
     if (controllers[index] != null)
     {
         IEAll4Device d = controllers[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);
     }
 }