Esempio n. 1
0
        private void FindController()
        {
            new Thread(() =>
            {
                var canRun   = true;
                _game.OnEnd += () => canRun = false;
                while (canRun)
                {
                    if (device == null)
                    {
                        DS4Devices.findControllers();
                        device          = DS4Devices.getDS4Controllers().First();
                        device.Removal += (sender, args) =>
                        {
                            device = null;
                            DS4Devices.stopControllers();
                        };
                        device.Report += DeviceOnReport;
                        device.StartUpdate();
                        device.LightBarColor = new DS4Color(Color.DeepPink);
                        PrintInfo();
                    }

                    if (device != null && !_isAlive)
                    {
                        device = null;
                    }

                    Thread.Sleep(16);
                }
            }).Start();
        }
Esempio n. 2
0
        private void GetDS4()
        {
            DS4Devices.findControllers();              //Finds all DS4 using directInput --> look for xInput and directInput for more info
            var list = DS4Devices.getDS4Controllers(); // Get an enumerable with all devices encountered.

            ds4 = list.First();
            ds4.StartUpdate(); // Starts the updating process on selected device --> this will start another thread to process all the inputs recieved from controller.
        }
Esempio n. 3
0
 public void RefreshDevices()
 {
     DS4Devices.findControllers();
     DS4Device[] devs = DS4Devices.getDS4Controllers().ToArray();
     for (int i = 0; i < devs.Length; i++)
     {
         connectedControllers[i] = new DS4ControllerHandler(i, devs[i]);
     }
 }
Esempio n. 4
0
        public void RefreshDevices()
        {
            DS4Devices.findControllers();
            var devs = DS4Devices.getDS4Controllers().ToArray();

            for (var i = 0; i < devs.Length; i++)
            {
                var dev = new DS4ControllerHandler(i, devs[i]);
                connectedControllers.Add(dev);
            }
        }
Esempio n. 5
0
        private void CheckDeviceState()
        {
            DS4Devices.findControllers();
            IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers();

            Device = devices.FirstOrDefault();

            IsConnected = Device != null;

            if (!IsConnected)
            {
                return;
            }
        }
        public void Initialize()
        {
            InitializeLayout();

            try
            {
                DS4Devices.findControllers();
                IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers();
                device = devices.ElementAt(0);
                device.StartUpdate();
            }
            catch (System.Exception)
            {
                throw;
            }
        }
Esempio n. 7
0
        public bool Initialize()
        {
            newkey          = Global.Configuration.VarRegistry.GetVariable <DeviceKeys>($"{devicename}_devicekey");
            setRestoreColor = Color.Transparent;
            DS4Devices.findControllers();
            IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers();

            if (!devices.Any())
            {
                return(false);
            }

            device    = devices.ElementAt(0);
            initColor = device.LightBarColor;

            if (!isInitialized)
            {
                try
                {
                    device.Report += SendColor;
                    device.Report += UpdateProperties;
                    device.StartUpdate();
                    Global.logger.Info("Initialized Dualshock");
                }
                catch (Exception e)
                {
                    Global.logger.Error("Could not initialize Dualshock" + e);
                    isInitialized = false;
                }
                if (device != null)
                {
                    isInitialized = true;
                    if (Global.Configuration.dualshock_first_time)
                    {
                        App.Current.Dispatcher.Invoke(() =>
                        {
                            DualshockInstallInstructions instructions = new DualshockInstallInstructions();
                            instructions.ShowDialog();
                        });
                        Global.Configuration.dualshock_first_time = false;
                        Settings.ConfigManager.Save(Global.Configuration);
                    }
                }
            }

            return(isInitialized);
        }
Esempio n. 8
0
        public override bool Initialize()
        {
            if (isInitialized)
            {
                return(true);
            }

            key = GlobalVarRegistry.GetVariable <DeviceKeys>($"{DeviceName}_devicekey");
            DS4Devices.findControllers();
            var controllers = DS4Devices.getDS4Controllers();

            foreach (var controller in controllers)
            {
                Devices.Add(new DS4Container(controller));
            }

            return(isInitialized = Devices.Any());
        }
Esempio n. 9
0
        public override bool Initialize()
        {
            if (IsInitialized)
            {
                return(true);
            }

            key = Global.Configuration.VarRegistry.GetVariable <DeviceKeys>($"{DeviceName}_devicekey");
            DS4Devices.findControllers();

            var restore = Global.Configuration.VarRegistry.GetVariable <RealColor>($"{DeviceName}_restore_dualshock").GetDrawingColor();

            foreach (var controller in DS4Devices.getDS4Controllers())
            {
                devices.Add(new DS4Container(controller, restore));
            }

            return(IsInitialized = devices.Count > 0);
        }
Esempio n. 10
0
        public void Scan()
        {
            //Log.WriteLine("Searching for DS4 controllers...");
            // Update controller list
            DS4Devices.findControllers();

            // Check validity of connected controllers
            var deadControllers = new List <IController>();

            foreach (var controller in Controllers)
            {
                if (controller.IsAlive())
                {
                    continue;
                }

                Log.WriteLine($"DS4 device {controller.Name} was disconnected.");
                controller.Stop();
                deadControllers.Add(controller);
            }

            // Remove disconnected devices
            if (deadControllers.Count > 0)
            {
                Controllers.RemoveAll(c => deadControllers.Contains(c));
            }


            var ds4Devices = DS4Devices.getDS4Controllers().ToArray();

            for (var i = 0; i < ds4Devices.Length; i++)
            {
                if (ds4Devices[i] != null &&
                    Controllers.Count(controller => controller.UnderlyingController == ds4Devices[i]) == 0)
                {
                    var controller = new DS4Controller(ds4Devices[i]);
                    Controllers.Add(controller);
                    Log.WriteLine($"DS4 device {ds4Devices[i].MacAddress} was connected.");
                }
            }
        }
Esempio n. 11
0
        private void DeviceListChanged(object sender, HidSharp.DeviceListChangedEventArgs e)
        {
            if ((Global.Configuration?.DevicesDisabled?.Contains(typeof(DualshockDevice)) ?? false) ||
                (!Global.Configuration?.VarRegistry?.GetVariable <bool>($"{DeviceName}_auto_init") ?? false))
            {
                return;
            }


            if (isDisconnecting)
            {
                return;
            }

            LogInfo("Detected device list changed, rescanning for controllers...");
            DS4Devices.findControllers();
            if (DS4Devices.getDS4Controllers().Count() != devices.Count)
            {
                Reset();
            }
        }
Esempio n. 12
0
        public Form1()
        {
            InitializeComponent();

            // The array of picture boxes will make easier to manage them
            pbx[0] = b;
            pbx[1] = c;
            pbx[2] = d;
            pbx[3] = e;


            cor[0] = Color.Green;
            cor[1] = Color.Blue;
            cor[2] = Color.Purple;
            cor[3] = Color.Yellow;
            DS4Devices.findControllers();
            ds4 = DS4Devices.getDS4Controllers().FirstOrDefault();
            if (ds4 != null)
            {
                ds4.StartUpdate();
            }
        }
Esempio n. 13
0
 public bool Start(bool showlog = true)
 {
     if (x360Bus.Open() && x360Bus.Start())
     {
         if (showlog)
         {
             LogDebug(Properties.Resources.Starting);
         }
         DS4Devices.isExclusiveMode = Global.getUseExclusiveMode();
         if (showlog)
         {
             LogDebug(Properties.Resources.SearchingController);
             LogDebug(DS4Devices.isExclusiveMode ?  Properties.Resources.UsingExclusive: Properties.Resources.UsingShared);
         }
         try
         {
             DS4Devices.findControllers();
             IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers();
             int ind = 0;
             DS4LightBar.defualtLight = false;
             foreach (DS4Device device in devices)
             {
                 if (showlog)
                 {
                     LogDebug(Properties.Resources.FoundController + device.MacAddress + " (" + device.ConnectionType + ")");
                 }
                 WarnExclusiveModeFailure(device);
                 DS4Controllers[ind] = device;
                 device.Removal     -= DS4Devices.On_Removal;
                 device.Removal     += this.On_DS4Removal;
                 device.Removal     += DS4Devices.On_Removal;
                 touchPad[ind]       = new Mouse(ind, device);
                 DS4Color color = Global.loadColor(ind);
                 device.LightBarColor = color;
                 if (!Global.getDinputOnly(ind))
                 {
                     x360Bus.Plugin(ind);
                 }
                 device.Report += this.On_Report;
                 TouchPadOn(ind, device);
                 string filename = Path.GetFileName(Global.getAProfile(ind));
                 ind++;
                 if (showlog)
                 {
                     if (System.IO.File.Exists(Global.appdatapath + "\\Profiles\\" + filename))
                     {
                         string prolog = Properties.Resources.UsingProfile.Replace("*number*", ind.ToString()).Replace("*Profile name*", filename.Substring(0, filename.Length - 4));
                         LogDebug(prolog);
                         Log.LogToTray(prolog);
                     }
                     else
                     {
                         LogDebug("Controller " + ind + " is not using a profile");
                         Log.LogToTray("Controller " + ind + " is not using a profile");
                     }
                 }
                 if (ind >= 4) // out of Xinput devices!
                 {
                     break;
                 }
             }
         }
         catch (Exception e)
         {
             LogDebug(e.Message);
             Log.LogToTray(e.Message);
         }
         running = true;
     }
     return(true);
 }
Esempio n. 14
0
        public bool HotPlug()
        {
            if (running)
            {
                DS4Devices.findControllers();
                IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers();
                foreach (DS4Device device in devices)
                {
                    if (device.IsDisconnecting)
                    {
                        continue;
                    }
                    if (((Func <bool>) delegate
                    {
                        for (Int32 Index = 0; Index < DS4Controllers.Length; Index++)
                        {
                            if (DS4Controllers[Index] != null && DS4Controllers[Index].MacAddress == device.MacAddress)
                            {
                                return(true);
                            }
                        }
                        return(false);
                    })())
                    {
                        continue;
                    }
                    for (Int32 Index = 0; Index < DS4Controllers.Length; Index++)
                    {
                        if (DS4Controllers[Index] == null)
                        {
                            LogDebug(Properties.Resources.FoundController + device.MacAddress + " (" + device.ConnectionType + ")");
                            WarnExclusiveModeFailure(device);
                            DS4Controllers[Index] = device;
                            device.Removal       -= DS4Devices.On_Removal;
                            device.Removal       += this.On_DS4Removal;
                            device.Removal       += DS4Devices.On_Removal;
                            touchPad[Index]       = new Mouse(Index, device);
                            device.LightBarColor  = Global.loadColor(Index);
                            device.Report        += this.On_Report;
                            if (!Global.getDinputOnly(Index))
                            {
                                x360Bus.Plugin(Index);
                            }
                            TouchPadOn(Index, device);
                            string filename = Path.GetFileName(Global.getAProfile(Index));
                            if (System.IO.File.Exists(Global.appdatapath + "\\Profiles\\" + filename))
                            {
                                string prolog = Properties.Resources.UsingProfile.Replace("*number*", (Index + 1).ToString()).Replace("*Profile name*", filename.Substring(0, filename.Length - 4));
                                LogDebug(prolog);
                                Log.LogToTray(prolog);
                            }
                            else
                            {
                                LogDebug("Controller " + (Index + 1) + " is not using a profile");
                                Log.LogToTray("Controller " + (Index + 1) + " is not using a profile");
                            }

                            break;
                        }
                    }
                }
            }
            return(true);
        }
Esempio n. 15
0
        public bool HotPlug()
        {
            if (running)
            {
                DS4Devices.findControllers();
                IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers();
                foreach (DS4Device device in devices)
                {
                    if (device.IsDisconnecting)
                    {
                        continue;
                    }
                    if (((Func <bool>) delegate
                    {
                        for (Int32 Index = 0; Index < DS4Controllers.Length; Index++)
                        {
                            if (DS4Controllers[Index] != null && DS4Controllers[Index].MacAddress == device.MacAddress)
                            {
                                return(true);
                            }
                        }
                        return(false);
                    })())
                    {
                        continue;
                    }
                    for (Int32 Index = 0; Index < DS4Controllers.Length; Index++)
                    {
                        if (DS4Controllers[Index] == null)
                        {
                            LogDebug(Properties.Resources.FoundController + device.MacAddress + " (" + device.ConnectionType + ")");
                            WarnExclusiveModeFailure(device);
                            DS4Controllers[Index] = device;
                            device.Removal       -= DS4Devices.On_Removal;
                            device.Removal       += this.On_DS4Removal;
                            device.Removal       += DS4Devices.On_Removal;
                            touchPad[Index]       = new Mouse(Index, device);
                            //device.LightBarColor = MainColor[Index];
                            //device.Report += this.On_Report;
                            //if (!DinputOnly[Index])
                            //    x360Bus.Plugin(Index);
                            TouchPadOn(Index, device);
                            //string filename = Path.GetFileName(ProfilePath[Index]);
                            //if (System.IO.File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[Index] + ".xml"))
                            //{
                            //    string prolog = Properties.Resources.UsingProfile.Replace("*number*", (Index + 1).ToString()).Replace("*Profile name*", ProfilePath[Index]);
                            //    LogDebug(prolog);
                            //    Log.LogToTray(prolog);
                            //}
                            //else
                            //{
                            //    string prolog = Properties.Resources.NotUsingProfile.Replace("*number*", (Index + 1).ToString());
                            //    LogDebug(prolog);
                            //    Log.LogToTray(prolog);
                            //}

                            break;
                        }
                    }
                }
            }
            return(true);
        }
Esempio n. 16
0
 public bool Start(bool showlog = true)
 {
     if (x360Bus.Open() && x360Bus.Start())
     {
         if (showlog)
         {
             //LogDebug(Properties.Resources.Starting);
             //DS4Devices.isExclusiveMode = UseExclusiveMode;
             if (showlog)
             {
                 //LogDebug(Properties.Resources.SearchingController);
                 //LogDebug(DS4Devices.isExclusiveMode ?  Properties.Resources.UsingExclusive: Properties.Resources.UsingShared);
             }
         }
         try
         {
             DS4Devices.findControllers();
             IEnumerable <DS4Device> devices = DS4Devices.getDS4Controllers();
             int ind = 0;
             //DS4LightBar.defualtLight = false;
             foreach (DS4Device device in devices)
             {
                 if (showlog)
                 {
                     LogDebug(Properties.Resources.FoundController + device.MacAddress + " (" + device.ConnectionType + ")");
                 }
                 WarnExclusiveModeFailure(device);
                 DS4Controllers[ind] = device;
                 device.Removal     -= DS4Devices.On_Removal;
                 device.Removal     += this.On_DS4Removal;
                 device.Removal     += DS4Devices.On_Removal;
                 touchPad[ind]       = new Mouse(ind, device);
                 //device.LightBarColor = MainColor[ind];
                 //if (!DinputOnly[ind])
                 //    x360Bus.Plugin(ind);
                 //device.Report += this.On_Report;
                 TouchPadOn(ind, device);
                 //string filename = ProfilePath[ind];
                 ind++;
                 //if (showlog)
                 //    if (System.IO.File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[ind-1] + ".xml"))
                 //    {
                 //        string prolog = Properties.Resources.UsingProfile.Replace("*number*", ind.ToString()).Replace("*Profile name*", 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);
         }
         running = true;
     }
     return(true);
 }
Esempio n. 17
0
        public static void ScanDevices()
        {
            // Scan for devices
            lock (_allControllers)
            {
                if (Settings.Default.EnableDS4)
                {
                    try
                    {
                        DS4Devices.findControllers();

                        var listDS4 = DS4Devices.getDS4Controllers();

                        foreach (var controller in listDS4)
                        {
                            if (_allControllers.Count(c => c.UnderlyingDevice == controller.HidDevice) == 0)
                            {
                                Logger.Write("Found new DS4 device: {0}", controller.MacAddress);
                                _allControllers.Add(new DS4Input(controller.MacAddress));
                                ControllersUpdated?.Invoke();
                            }
                        }
                    }
                    catch (ThreadAbortException ex)
                    { }
                    catch (Exception ex)
                    {
                        Logger.Write("DS4 driver error: ", ex);
                        MessageBox.Show(string.Format(Resources.ErrorDriverDs4Disabled, ex.Message), Resources.ErrorDriverDisabledTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                        Settings.Default.EnableDS4 = false;
                        Settings.Default.Save();
                    }
                }

                if (Settings.Default.EnableXbox)
                {
                    // Scan for Xbox controllers
                    try
                    {
                        for (int i = XboxController.FIRST_CONTROLLER_INDEX; i < XboxController.MAX_CONTROLLER_COUNT; i++)
                        {
                            XInputState stateController = new XInputState();
                            int         result          = XInput.XInputGetState(i, ref stateController);
                            if (result == 0) // Controller found
                            {
                                var controller = XboxController.RetrieveController(i);
                                if (_allControllers.Count(c => c.UnderlyingDevice == controller) == 0)
                                {
                                    Logger.Write("Found new XInput device: {0}", i);
                                    _allControllers.Add(new XboxInput(i));
                                    ControllersUpdated?.Invoke();
                                }
                            }
                        }
                    }
                    catch (ThreadAbortException ex)
                    { }
                    catch (Exception ex)
                    {
                        Logger.Write("XInput driver error: ", ex);
                        MessageBox.Show(string.Format(Resources.ErrorDriverXboxDisabled, ex.Message), Resources.ErrorDriverDisabledTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                        Settings.Default.EnableXbox = false;
                        Settings.Default.Save();
                    }
                }
            }
        }