IsAlive() public method

public IsAlive ( ) : bool
return bool
        public string getShortDS4ControllerInfo(int index)
        {
            DS4Device d = DS4Controllers[index];

            if (d != null)
            {
                string battery;
                if (!d.IsAlive())
                {
                    battery = "...";
                }

                if (d.isCharging())
                {
                    if (d.getBattery() >= 100)
                    {
                        battery = Properties.Resources.Full;
                    }
                    else
                    {
                        battery = d.getBattery() + "%+";
                    }
                }
                else
                {
                    battery = d.getBattery() + "%";
                }

                return(d.getConnectionType() + " " + battery);
            }
            else
            {
                return(Properties.Resources.NoneText);
            }
        }
        public string getDS4Battery(int index)
        {
            DS4Device d = DS4Controllers[index];

            if (d != null)
            {
                string battery;
                if (!d.IsAlive())
                {
                    battery = "...";
                }

                if (d.isCharging())
                {
                    if (d.getBattery() >= 100)
                    {
                        battery = Properties.Resources.Full;
                    }
                    else
                    {
                        battery = d.getBattery() + "%+";
                    }
                }
                else
                {
                    battery = d.getBattery() + "%";
                }

                return(battery);
            }
            else
            {
                return(Properties.Resources.NA);
            }
        }
Ejemplo n.º 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);
            }
        }
        public string getDS4MacAddress(int index)
        {
            DS4Device d = DS4Controllers[index];

            if (d != null)
            {
                if (!d.IsAlive())
                {
                    return(Properties.Resources.Connecting);
                }

                return(d.getMacAddress());
            }
            else
            {
                return(string.Empty);
            }
        }
Ejemplo n.º 5
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);
     }
 }
Ejemplo n.º 6
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);
     }
 }
        public string getDS4ControllerInfo(int index)
        {
            DS4Device d = DS4Controllers[index];

            if (d != null)
            {
                if (!d.IsAlive())
                {
                    return(Properties.Resources.Connecting);
                }

                string battery;
                if (d.isCharging())
                {
                    if (d.getBattery() >= 100)
                    {
                        battery = Properties.Resources.Charged;
                    }
                    else
                    {
                        battery = Properties.Resources.Charging.Replace("*number*", d.getBattery().ToString());
                    }
                }
                else
                {
                    battery = Properties.Resources.Battery.Replace("*number*", d.getBattery().ToString());
                }

                return(d.getMacAddress() + " (" + d.getConnectionType() + "), " + battery);
                //return d.MacAddress + " (" + d.ConnectionType + "), Battery is " + battery + ", Touchpad in " + modeSwitcher[index].ToString();
            }
            else
            {
                return(string.Empty);
            }
        }
        // Called every time a new input report has arrived
        protected virtual void On_Report(object sender, EventArgs e)
        {
            DS4Device device = (DS4Device)sender;

            int ind = -1;

            for (int i = 0, arlength = DS4_CONTROLLER_COUNT; ind == -1 && i < arlength; i++)
            {
                DS4Device tempDev = DS4Controllers[i];
                if (tempDev != null && device == tempDev)
                {
                    ind = i;
                }
            }

            if (ind != -1)
            {
                if (getFlushHIDQueue(ind))
                {
                    device.FlushHID();
                }

                string devError = tempStrings[ind] = device.error;
                if (!string.IsNullOrEmpty(devError))
                {
                    device.getUiContext()?.Post(new SendOrPostCallback(delegate(object state)
                    {
                        LogDebug(devError);
                    }), null);
                }

                if (inWarnMonitor[ind])
                {
                    int flashWhenLateAt = getFlashWhenLateAt();
                    if (!lag[ind] && device.Latency >= flashWhenLateAt)
                    {
                        lag[ind] = true;
                        device.getUiContext()?.Post(new SendOrPostCallback(delegate(object state)
                        {
                            LagFlashWarning(ind, true);
                        }), null);
                    }
                    else if (lag[ind] && device.Latency < flashWhenLateAt)
                    {
                        lag[ind] = false;
                        device.getUiContext()?.Post(new SendOrPostCallback(delegate(object state)
                        {
                            LagFlashWarning(ind, false);
                        }), null);
                    }
                }
                else
                {
                    if (DateTime.UtcNow - device.firstActive > TimeSpan.FromSeconds(5))
                    {
                        inWarnMonitor[ind] = true;
                    }
                }

                device.getCurrentState(CurrentState[ind]);
                DS4State cState = CurrentState[ind];
                DS4State pState = device.getPreviousStateRef();
                //device.getPreviousState(PreviousState[ind]);
                //DS4State pState = PreviousState[ind];

                if (!device.firstReport && device.IsAlive())
                {
                    device.firstReport = true;
                    device.getUiContext()?.Post(new SendOrPostCallback(delegate(object state)
                    {
                        OnDeviceStatusChanged(this, ind);
                    }), null);
                }
                else if (pState.Battery != cState.Battery || device.oldCharging != device.isCharging())
                {
                    byte tempBattery  = currentBattery[ind] = cState.Battery;
                    bool tempCharging = charging[ind] = device.isCharging();
                    device.getUiContext()?.Post(new SendOrPostCallback(delegate(object state)
                    {
                        OnBatteryStatusChange(this, ind, tempBattery, tempCharging);
                    }), null);
                }

                if (getEnableTouchToggle(ind))
                {
                    CheckForTouchToggle(ind, cState, pState);
                }

                cState = Mapping.SetCurveAndDeadzone(ind, cState);

                if (!recordingMacro && (!string.IsNullOrEmpty(tempprofilename[ind]) ||
                                        containsCustomAction(ind) || containsCustomExtras(ind) ||
                                        getProfileActionCount(ind) > 0))
                {
                    Mapping.MapCustom(ind, cState, MappedState[ind], ExposedState[ind], touchPad[ind], this);
                    cState = MappedState[ind];
                }

                if (!useDInputOnly[ind])
                {
                    x360Bus.Parse(cState, processingData[ind].Report, ind);
                    // We push the translated Xinput state, and simultaneously we
                    // pull back any possible rumble data coming from Xinput consumers.
                    if (x360Bus.Report(processingData[ind].Report, processingData[ind].Rumble))
                    {
                        byte Big   = processingData[ind].Rumble[3];
                        byte Small = processingData[ind].Rumble[4];

                        if (processingData[ind].Rumble[1] == 0x08)
                        {
                            setRumble(Big, Small, ind);
                        }
                    }
                }

                if (_udpServer != null)
                {
                    _udpServer.NewReportIncoming(GetPadDetailForIdx(ind), CurrentState[ind]);
                }

                // Output any synthetic events.
                Mapping.Commit(ind);

                // Update the GUI/whatever.
                DS4LightBar.updateLightBar(device, ind, cState, ExposedState[ind], touchPad[ind]);
            }
        }