Beispiel #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);
 }
Beispiel #2
0
        public bool HotPlug()
        {
            if (running)
            {
                EAll4Devices.findControllers();
                IEnumerable <IEAll4Device> devices = EAll4Devices.getEAll4Controllers();
                foreach (var device in devices)
                {
                    if (device.IsDisconnecting)
                    {
                        continue;
                    }
                    if (((Func <bool>) delegate
                    {
                        for (Int32 Index = 0; Index < controllers.Length; Index++)
                        {
                            if (controllers[Index] != null && controllers[Index].MacAddress == device.MacAddress)
                            {
                                return(true);
                            }
                        }
                        return(false);
                    })())
                    {
                        continue;
                    }
                    for (Int32 Index = 0; Index < controllers.Length; Index++)
                    {
                        if (controllers[Index] == null)
                        {
                            LogDebug(Properties.Resources.FoundController + device.MacAddress + " (" + device.ConnectionType + ")");
                            WarnExclusiveModeFailure(device);
                            controllers[Index]   = device;
                            device.Removal      -= EAll4Devices.On_Removal;
                            device.Removal      += this.On_EAll4Removal;
                            device.Removal      += EAll4Devices.On_Removal;
                            touchPad[Index]      = new Mouse(Index, device);
                            device.LightBarColor = Global.MainColor[Index];
                            device.Report       += this.On_Report;
                            if (!Global.DinputOnly[Index])
                            {
                                x360Bus.Plugin(Index);
                            }
                            TouchPadOn(Index, device);
                            //string filename = Path.GetFileName(Global.ProfilePath[Index]);
                            if (System.IO.File.Exists(Global.appdatapath + "\\Profiles\\" + Global.ProfilePath[Index] + ".xml"))
                            {
                                string prolog = Properties.Resources.UsingProfile.Replace("*number*", (Index + 1).ToString()).Replace("*Profile name*", Global.ProfilePath[Index]);
                                LogDebug(prolog);
                                Log.LogToTray(prolog);
                            }
                            else
                            {
                                string prolog = Properties.Resources.NotUsingProfile.Replace("*number*", (Index + 1).ToString());
                                LogDebug(prolog);
                                Log.LogToTray(prolog);
                            }

                            Application.DoEvents();


                            break;
                        }
                    }
                }
            }
            Application.DoEvents();
            return(true);
        }
Beispiel #3
0
        public bool Start(bool showlog = true)
        {
            if (x360Bus.Open() && x360Bus.Start())
            {
                if (showlog)
                {
                    LogDebug(Properties.Resources.Starting);
                }
                EAll4Devices.isExclusiveMode = Global.UseExclusiveMode;
                if (showlog)
                {
                    LogDebug(Properties.Resources.SearchingController);
                    LogDebug(EAll4Devices.isExclusiveMode ? Properties.Resources.UsingExclusive : Properties.Resources.UsingShared);
                }
                try
                {
                    EAll4Devices.findControllers();
                    IEnumerable <IEAll4Device> devices = EAll4Devices.getEAll4Controllers();
                    int ind = 0;
                    EAll4LightBar.defaultLight = false;
                    foreach (var device in devices)
                    {
                        if (showlog)
                        {
                            LogDebug(Properties.Resources.FoundController + device.MacAddress + " (" + device.ConnectionType + ")");
                        }
                        WarnExclusiveModeFailure(device);
                        controllers[ind]     = device;
                        device.Removal      -= EAll4Devices.On_Removal;
                        device.Removal      += this.On_EAll4Removal;
                        device.Removal      += EAll4Devices.On_Removal;
                        touchPad[ind]        = new Mouse(ind, device);
                        device.LightBarColor = Global.MainColor[ind];
                        if (!Global.DinputOnly[ind])
                        {
                            x360Bus.Plugin(ind);
                        }
                        device.Report += this.On_Report;
                        TouchPadOn(ind, device);
                        //string filename = Global.ProfilePath[ind];
                        ind++;
                        if (showlog)
                        {
                            if (System.IO.File.Exists(Global.appdatapath + "\\Profiles\\" + Global.ProfilePath[ind - 1] + ".xml"))
                            {
                                string prolog = Properties.Resources.UsingProfile.Replace("*number*", ind.ToString()).Replace("*Profile name*", Global.ProfilePath[ind - 1]);
                                LogDebug(prolog);
                                Log.LogToTray(prolog);
                            }
                            else
                            {
                                string prolog = Properties.Resources.NotUsingProfile.Replace("*number*", (ind).ToString());
                                LogDebug(prolog);
                                Log.LogToTray(prolog);
                            }
                        }


                        if (ind >= 4) // out of Xinput devices!
                        {
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    LogDebug(e.Message);
                    Log.LogToTray(e.Message);
                }
                Application.DoEvents();
                running = true;
            }
            Application.DoEvents();
            return(true);
        }