Example #1
0
        public static void SetController(IController controller)
        {
            if (ActiveController != null)
            {
                ActiveController.ButtonStateChanged -= ActiveControllerOnButtonStateChanged;
            }
            ActiveController = controller;

            if (controller != null)
            {
                ActiveController.ButtonStateChanged += ActiveControllerOnButtonStateChanged;
                Log.WriteLine("Selected controller: " + controller.Name);
                var device = ActiveController.UnderlyingController as DS4Device;
                if (device != null)
                {
                    var ds4 = device;
                    ds4.Touchpad.TouchesMoved    += DS4TouchpadMoved;
                    ds4.Touchpad.TouchButtonDown += DS4TouchpadButtonDown;
                    ds4.Touchpad.TouchButtonUp   += DS4TouchpadButtonUp;
                }
                App.Overlay.PopupNotification(new OverlayNotification()
                {
                    Header  = "Controller selected",
                    Content = $"Controller {controller.Name} is now the active controller.",
                });
            }

            if (ActiveControllerChanged != null)
            {
                Application.Current.Dispatcher.Invoke(() => { ActiveControllerChanged?.Invoke(controller); });
            }

            ConsolePort.BindWriter.WriteBinds();

            MainWindow.UpdateButtonStyle();
        }
Example #2
0
        private static void ControllerWatcher()
        {
            while (_threadRunning)
            {
                lock (Controllers)
                {
                    // Check validity of connected controllers
                    var deadControllers = Controllers.Where(controller => !controller.IsAlive()).ToList();

                    if (deadControllers.Contains(ActiveController))
                    {
                        SetController(null);
                        Application.Current.Dispatcher.Invoke(() => { ActiveControllerChanged?.Invoke(null); });
                    }

                    // Remove disconnected devices
                    for (int i = 0; i < deadControllers.Count; i++)
                    {
                        deadControllers[i].Stop();
                        Controllers.Remove(deadControllers[i]);
                        App.Overlay.PopupNotification(new OverlayNotification()
                        {
                            Header  = "Controller disconnected",
                            Content = $"Controller {deadControllers[i].Name} was disconnected.",
                        });
                        deadControllers[i] = null;
                    }

                    if (deadControllers.Count > 0)
                    {
                        if (ControllersChanged != null)
                        {
                            Application.Current.Dispatcher.Invoke(ControllersChanged);
                        }
                    }

                    if (ActiveController == null)
                    {
                        _lastBatteryWarn = 100;
                        RefreshControllers();
                        if (Controllers.Count > 0)
                        {
                            try
                            {
                                var firstActive = Controllers.First(device => device.IsAlive());
                                SetController(firstActive);
                            }
                            catch
                            {
                            }
                        }
                    }

                    if (Settings.Default.EnableOverlay && Settings.Default.EnableOverlayBattery && ActiveController != null)
                    {
                        var battery = ActiveController.BatteryLevel;
                        if (battery > _lastBatteryWarn)
                        {
                            _lastBatteryWarn = 100;
                            if (battery > 35)
                            {
                                _showedBatteryCritical = false;
                            }
                            if (battery > 45)
                            {
                                _showedBatteryLow = false;
                            }
                        }
                        else if (battery <= _lastBatteryWarn - 10) // If battery has dropped by 10%
                        {
                            if (battery <= 40 && !_showedBatteryLow)
                            {
                                App.Overlay.PopupNotification(new OverlayNotification()
                                {
                                    Content  = $"Your controller battery has reached {battery}%.",
                                    Header   = "Battery low",
                                    UniqueID = "LOW_BATTERY",
                                });
                                _showedBatteryLow = true;
                            }
                            else if (battery <= 30 && !_showedBatteryCritical)
                            {
                                App.Overlay.PopupNotification(new OverlayNotification()
                                {
                                    Content =
                                        $"Your controller battery has reached {battery}%. Plug in now to avoid unexpected interruption.",
                                    Header   = "Battery critically low",
                                    UniqueID = "LOW_BATTERY",
                                });
                                _showedBatteryCritical = true;
                            }
                            _lastBatteryWarn -= 10;
                        }
                    }
                }

                Thread.Sleep(2000);
            }
        }