示例#1
0
 public bool Stop(bool showlog = true)
 {
     if (running)
     {
         running = false;
         if (showlog)
         {
             LogDebug(Properties.Resources.StoppingX360);
         }
         bool anyUnplugged = false;
         for (int i = 0; i < DS4Controllers.Length; i++)
         {
             if (DS4Controllers[i] != null)
             {
                 if (DCBTatStop && !DS4Controllers[i].Charging && showlog)
                 {
                     DS4Controllers[i].DisconnectBT();
                 }
                 else
                 {
                     DS4LightBar.forcelight[i]  = false;
                     DS4LightBar.forcedFlash[i] = 0;
                     DS4LightBar.defualtLight   = true;
                     DS4LightBar.updateLightBar(DS4Controllers[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;
                 DS4Controllers[i] = null;
                 touchPad[i]       = null;
             }
         }
         if (anyUnplugged)
         {
             System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);
         }
         x360Bus.UnplugAll();
         x360Bus.Stop();
         if (showlog)
         {
             LogDebug(Properties.Resources.StoppingDS4);
         }
         DS4Devices.stopControllers();
         if (showlog)
         {
             LogDebug(Properties.Resources.StoppedDS4Windows);
         }
         ControllerStatusChanged(this);
     }
     return(true);
 }
        // 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]);
            }
        }
        public bool Stop(bool showlog = true)
        {
            if (running)
            {
                running    = false;
                runHotPlug = false;

                if (showlog)
                {
                    LogDebug(Properties.Resources.StoppingX360);
                }

                bool anyUnplugged = false;
                for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++)
                {
                    DS4Device tempDevice = DS4Controllers[i];
                    if (tempDevice != null)
                    {
                        if (DCBTatStop && !tempDevice.isCharging())
                        {
                            if (tempDevice.getConnectionType() == ConnectionType.BT)
                            {
                                tempDevice.StopUpdate();
                                tempDevice.DisconnectBT(true);
                            }
                            else if (tempDevice.getConnectionType() == ConnectionType.SONYWA)
                            {
                                tempDevice.StopUpdate();
                                tempDevice.DisconnectDongle(true);
                            }
                        }
                        else
                        {
                            DS4LightBar.forcelight[i]  = false;
                            DS4LightBar.forcedFlash[i] = 0;
                            DS4LightBar.defaultLight   = true;
                            DS4LightBar.updateLightBar(DS4Controllers[i], i, CurrentState[i],
                                                       ExposedState[i], touchPad[i]);
                            tempDevice.IsRemoved = true;
                            Thread.Sleep(50);
                        }

                        CurrentState[i].Battery = PreviousState[i].Battery = 0; // Reset for the next connection's initial status change.
                        x360Bus.Unplug(i);
                        useDInputOnly[i]  = true;
                        anyUnplugged      = true;
                        DS4Controllers[i] = null;
                        touchPad[i]       = null;
                        lag[i]            = false;
                        inWarnMonitor[i]  = false;
                    }
                }

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

                x360Bus.UnplugAll();
                x360Bus.Stop();

                if (showlog)
                {
                    LogDebug(Properties.Resources.StoppingDS4);
                }

                DS4Devices.stopControllers();

                if (_udpServer != null)
                {
                    _udpServer.Stop();
                }

                if (showlog)
                {
                    LogDebug(Properties.Resources.StoppedDS4Windows);
                }
            }

            runHotPlug = false;
            return(true);
        }
示例#4
0
        //Called every time the 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; i < DS4Controllers.Length; i++)
            {
                if (device == DS4Controllers[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]);
                DS4State cState = CurrentState[ind];
                device.getPreviousState(PreviousState[ind]);
                DS4State 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))
                {
                    Byte Big   = (Byte)(processingData[ind].Rumble[3]);
                    Byte 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];
            }
        }