示例#1
0
        public bool Stop(bool showLog = true)
        {
            if (running)
            {
                running = false;

                if (showLog)
                {
                    LogDebug("Stopping X360 controllers");
                }

                var anyUnplugged = false;
                for (var i = 0; i < Controllers.Length; i++)
                {
                    if (Controllers[i] != null)
                    {
                        if (DCBTatStop && !Controllers[i].Charging && showLog)
                        {
                            Controllers[i].DisconnectBT();
                        }
                        else
                        {
                            DS4LightBar.forcelight[i]  = false;
                            DS4LightBar.forcedFlash[i] = 0;
                            DS4LightBar.defualtLight   = true;
                            DS4LightBar.updateLightBar(Controllers[i], i, CurrentState[i], ExposedState[i], touchPad[i]);
                            System.Threading.Thread.Sleep(50);
                        }
                        CurrentState[i].Battery = PreviousState[i].Battery = 0; // Reset for the next connection's initial status change.
                        X360Bus.Unplug(i);
                        anyUnplugged   = true;
                        Controllers[i] = null;
                        touchPad[i]    = null;
                    }
                }

                if (anyUnplugged)
                {
                    System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);
                }

                X360Bus.UnplugAll();
                X360Bus.Stop();

                if (showLog)
                {
                    LogDebug("Stopping DS4s");
                }

                Devices.StopControllers();

                if (showLog)
                {
                    LogDebug("Stopped DS4Windows");
                }

                ControllerStatusChanged(this);
            }
            return(true);
        }
示例#2
0
        //Called every time the new input report has arrived
        protected virtual void On_Report(object sender, EventArgs e)
        {
            var device = (Device)sender;

            var ind = -1;

            for (var i = 0; i < Controllers.Length; i++)
            {
                if (device == Controllers[i])
                {
                    ind = i;
                }
            }

            if (ind != -1)
            {
                if (FlushHIDQueue[ind])
                {
                    device.FlushHid();
                }
                if (!string.IsNullOrEmpty(device.error))
                {
                    LogDebug(device.error);
                }
                if (DateTime.UtcNow - device.FirstActive > TimeSpan.FromSeconds(5))
                {
                    if (device.Latency >= FlashWhenLateAt && !lag[ind])
                    {
                        LagFlashWarning(ind, true);
                    }
                    else if (device.Latency < FlashWhenLateAt && lag[ind])
                    {
                        LagFlashWarning(ind, false);
                    }
                }
                device.GetExposedState(ExposedState[ind], CurrentState[ind]);
                var cState = CurrentState[ind];
                device.GetPreviousState(PreviousState[ind]);
                var pState = PreviousState[ind];
                if (pState.Battery != cState.Battery)
                {
                    ControllerStatusChanged(this);
                }
                CheckForHotkeys(ind, cState, pState);
                if (eastertime)
                {
                    EasterTime(ind);
                }
                GetInputkeys(ind);
                if (LSCurve[ind] != 0 || RSCurve[ind] != 0 || LSDeadzone[ind] != 0 || RSDeadzone[ind] != 0 ||
                    L2Deadzone[ind] != 0 || R2Deadzone[ind] != 0 || LSSens[ind] != 0 || RSSens[ind] != 0 ||
                    L2Sens[ind] != 0 || R2Sens[ind] != 0) //if a curve or deadzone is in place
                {
                    cState = Mapping.SetCurveAndDeadzone(ind, cState);
                }
                if (!recordingMacro && (!string.IsNullOrEmpty(tempprofilename[ind]) ||
                                        HasCustomAction(ind) || HasCustomExtras(ind) || ProfileActions[ind].Count > 0))
                {
                    Mapping.MapCustom(ind, cState, MappedState[ind], ExposedState[ind], touchPad[ind], this);
                    cState = MappedState[ind];
                }
                //if (HasCustomExtras(ind))
                //  DoExtras(ind);

                // Update the GUI/whatever.
                DS4LightBar.updateLightBar(device, ind, cState, ExposedState[ind], touchPad[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))
                {
                    var Big   = (byte)_processingData[ind].Rumble[3];
                    var Small = (byte)_processingData[ind].Rumble[4];

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

                // Output any synthetic events.
                Mapping.Commit(ind);
                // Pull settings updates.
                device.IdleTimeout = IdleDisconnectTimeout[ind];
            }
        }