Esempio n. 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 < controllers.Length; i++)
         {
             if (controllers[i] != null)
             {
                 if (Global.DCBTatStop && !controllers[i].Charging && showlog)
                 {
                     controllers[i].DisconnectBT();
                 }
                 else
                 {
                     EAll4LightBar.forcelight[i]  = false;
                     EAll4LightBar.forcedFlash[i] = 0;
                     EAll4LightBar.defaultLight   = true;
                     EAll4LightBar.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(Properties.Resources.StoppingEAll4);
         }
         EAll4Devices.stopControllers();
         if (showlog)
         {
             LogDebug(Properties.Resources.StoppedEAll4Windows);
         }
         Global.ControllerStatusChanged(this);
     }
     return(true);
 }
Esempio n. 2
0
        //Called every time the new input report has arrived
        protected virtual void On_Report(object sender, EventArgs e)
        {
            var ieAll4Device = (IEAll4Device)sender;

            int ind = -1;

            for (int i = 0; i < controllers.Length; i++)
            {
                if (ieAll4Device == controllers[i])
                {
                    ind = i;
                }
            }

            if (ind != -1)
            {
                if (Global.FlushHIDQueue[ind])
                {
                    ieAll4Device.FlushHID();
                }
                if (!string.IsNullOrEmpty(ieAll4Device.error))
                {
                    LogDebug(ieAll4Device.error);
                }
                if (DateTime.UtcNow - ieAll4Device.firstActive > TimeSpan.FromSeconds(5))
                {
                    if (ieAll4Device.Latency >= 10 && !lag[ind])
                    {
                        LagFlashWarning(ind, true);
                    }
                    else if (ieAll4Device.Latency < 10 && lag[ind])
                    {
                        LagFlashWarning(ind, false);
                    }
                }
                ieAll4Device.getExposedState(ExposedState[ind], CurrentState[ind]);
                ControllerState cState = CurrentState[ind];
                ieAll4Device.getPreviousState(PreviousState[ind]);
                ControllerState pState = PreviousState[ind];
                if (pState.Battery != cState.Battery)
                {
                    Global.ControllerStatusChanged(this);
                }
                CheckForHotkeys(ind, cState, pState);
                if (eastertime)
                {
                    EasterTime(ind);
                }
                GetInputkeys(ind);
                if (Global.LSCurve[ind] != 0 || Global.RSCurve[ind] != 0 || Global.LSDeadzone[ind] != 0 || Global.RSDeadzone[ind] != 0 ||
                    Global.L2Deadzone[ind] != 0 || Global.R2Deadzone[ind] != 0) //if a curve or deadzone is in place
                {
                    cState = Mapping.SetCurveAndDeadzone(ind, cState);
                }
                if (!recordingMacro && (!string.IsNullOrEmpty(Global.tempprofilename[ind]) ||
                                        Global.getHasCustomKeysorButtons(ind) || Global.getHasShiftCustomKeysorButtons(ind) || Global.ProfileActions[ind].Count > 0))
                {
                    Mapping.MapCustom(ind, cState, MappedState[ind], ExposedState[ind], touchPad[ind], this);
                    cState = MappedState[ind];
                }
                if (Global.getHasCustomExtras(ind))
                {
                    DoExtras(ind);
                }

                // Update the GUI/whatever.
                EAll4LightBar.updateLightBar(ieAll4Device, 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.
                ieAll4Device.IdleTimeout = Global.IdleDisconnectTimeout[ind];
            }
        }