private void loadBtn_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog();
            dialog.FileName   = string.IsNullOrEmpty(FileName) ? "ir_Calibration" : FileName;
            dialog.DefaultExt = ".irc";
            dialog.Filter     = App.IR_CAL_FILTER;

            bool?         doLoad = dialog.ShowDialog();
            IRCalibration loadedConfig;

            if (doLoad == true && dialog.CheckFileExists)
            {
                if (App.LoadFromFile <IRCalibration>(dialog.FileName, out loadedConfig))
                {
                    FileName        = dialog.FileName;
                    _irCalibration  = loadedConfig;
                    boxWidth.Value  = _irCalibration.boundry.width;
                    boxHeight.Value = _irCalibration.boundry.height;
                    boxX.Value      = _irCalibration.boundry.center_x - _irCalibration.boundry.width / 2;
                    boxY.Value      = _irCalibration.boundry.center_y - _irCalibration.boundry.height / 2;
                }
                else
                {
                    MessageBox.Show(
                        Globalization.TranslateFormat("Calibration_Load_Error_Msg", dialog.FileName),
                        Globalization.Translate("Calibration_Load_Error"),
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }
        }
        private void SetXInputDeviceStatus(ScpDirector.XInput_Device device)
        {
            string status = Globalization.Translate("Status_Disconnected");

            if (ScpDirector.Access.IsConnected(device))
            {
                status = Globalization.Translate("Status_Connected");
            }

            status = Globalization.TranslateFormat("XInput_Device_Num", (int)device, status);

            switch (device)
            {
            case ScpDirector.XInput_Device.Device_A:
                xlabel1.Content = status;
                break;

            case ScpDirector.XInput_Device.Device_B:
                xlabel2.Content = status;
                break;

            case ScpDirector.XInput_Device.Device_C:
                xlabel3.Content = status;
                break;

            case ScpDirector.XInput_Device.Device_D:
                xlabel4.Content = status;
                break;
            }
        }
        private void loadBtn_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog();
            dialog.FileName   = string.IsNullOrEmpty(FileName) ? "axis_Calibration" : FileName;
            dialog.DefaultExt = ".axs";
            dialog.Filter     = App.AXIS_CAL_FILTER;

            bool?           doLoad = dialog.ShowDialog();
            AxisCalibration loadedConfig;

            if (doLoad == true && dialog.CheckFileExists)
            {
                if (App.LoadFromFile <AxisCalibration>(dialog.FileName, out loadedConfig))
                {
                    FileName      = dialog.FileName;
                    center.Value  = loadedConfig.center;
                    min.Value     = (int)Math.Round(100 - 100 * loadedConfig.min / 65535d);
                    max.Value     = (int)Math.Round(100 * loadedConfig.max / 65535d);
                    deadMax.Value = (int)Math.Round(100 * loadedConfig.deadPos / 65535d);
                    deadMin.Value = (int)Math.Round(-100 * loadedConfig.deadNeg / 65535d);
                }
                else
                {
                    MessageBox.Show(
                        Globalization.TranslateFormat("Calibration_Load_Error_Msg", dialog.FileName),
                        Globalization.Translate("Calibration_Load_Error"),
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }
        }
        public void ClearTooltips()
        {
            string unsetText = Globalization.Translate("Input_Unset");

            A.ToolTip         = unsetText;
            B.ToolTip         = unsetText;
            X.ToolTip         = unsetText;
            Y.ToolTip         = unsetText;
            Z.ToolTip         = unsetText;
            START.ToolTip     = unsetText;
            dpadUp.ToolTip    = unsetText;
            dpadLeft.ToolTip  = unsetText;
            dpadRight.ToolTip = unsetText;
            dpadDown.ToolTip  = unsetText;
            UpdateTooltipLine(L, unsetText, 0);
            UpdateTooltipLine(L, unsetText, 1);
            UpdateTooltipLine(R, unsetText, 0);
            UpdateTooltipLine(R, unsetText, 1);
            UpdateTooltipLine(joystick, unsetText, 0);
            UpdateTooltipLine(joystick, unsetText, 1);
            UpdateTooltipLine(joystick, unsetText, 2);
            UpdateTooltipLine(joystick, unsetText, 3);
            UpdateTooltipLine(cStick, unsetText, 0);
            UpdateTooltipLine(cStick, unsetText, 1);
            UpdateTooltipLine(cStick, unsetText, 2);
            UpdateTooltipLine(cStick, unsetText, 3);
            UpdateTooltipLine(dpadCenter, unsetText, 0);
            UpdateTooltipLine(dpadCenter, unsetText, 1);
            UpdateTooltipLine(dpadCenter, unsetText, 2);
            UpdateTooltipLine(dpadCenter, unsetText, 3);
        }
Exemple #5
0
        private void loadBtn_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog();
            dialog.FileName   = string.IsNullOrEmpty(FileName) ? "trigger_Calibration" : FileName;
            dialog.DefaultExt = ".trg";
            dialog.Filter     = App.TRIG_CAL_FILTER;

            bool?   doLoad = dialog.ShowDialog();
            Trigger loadedConfig;

            if (doLoad == true && dialog.CheckFileExists)
            {
                if (App.LoadFromFile <Trigger>(dialog.FileName, out loadedConfig))
                {
                    FileName  = dialog.FileName;
                    min.Value = loadedConfig.min;
                    max.Value = loadedConfig.max;
                }
                else
                {
                    System.Windows.MessageBox.Show(
                        Globalization.TranslateFormat("Calibration_Load_Error_Msg", dialog.FileName),
                        Globalization.Translate("Calibration_Load_Error"),
                        System.Windows.MessageBoxButton.OK,
                        System.Windows.MessageBoxImage.Error);
                }
            }
        }
        public void ClearTooltips()
        {
            string unsetText = Globalization.Translate("Input_Unset");

            bBtn.ToolTip     = unsetText;
            aBtn.ToolTip     = unsetText;
            yBtn.ToolTip     = unsetText;
            xBtn.ToolTip     = unsetText;
            lBtn.ToolTip     = unsetText;
            rBtn.ToolTip     = unsetText;
            zlBtn.ToolTip    = unsetText;
            zrBtn.ToolTip    = unsetText;
            minusBtn.ToolTip = unsetText;
            plusBtn.ToolTip  = unsetText;
            homeBtn.ToolTip  = unsetText;
            shareBtn.ToolTip = unsetText;
            upBtn.ToolTip    = unsetText;
            leftBtn.ToolTip  = unsetText;
            rightBtn.ToolTip = unsetText;
            downBtn.ToolTip  = unsetText;
            UpdateTooltipLine(leftStickButton, unsetText, 0);
            UpdateTooltipLine(leftStickButton, unsetText, 1);
            UpdateTooltipLine(leftStickButton, unsetText, 2);
            UpdateTooltipLine(leftStickButton, unsetText, 3);
            UpdateTooltipLine(leftStickButton, unsetText, 4);
            UpdateTooltipLine(leftStickButton, unsetText, 0);
            UpdateTooltipLine(leftStickButton, unsetText, 1);
            UpdateTooltipLine(leftStickButton, unsetText, 2);
            UpdateTooltipLine(leftStickButton, unsetText, 3);
            UpdateTooltipLine(leftStickButton, unsetText, 4);
            UpdateTooltipLine(center, unsetText, 0);
            UpdateTooltipLine(center, unsetText, 1);
            UpdateTooltipLine(center, unsetText, 2);
            UpdateTooltipLine(center, unsetText, 3);
        }
        private void connectBtn_Click(object sender, RoutedEventArgs e)
        {
            bool result = false;

            if (Ninty != null)
            {
                result = Ninty.Connect();
            }
            else if (Joy != null)
            {
                result = Joy.Connect();

                var prefs = AppPrefs.Instance.GetDevicePreferences(Info.DeviceID);
                if (prefs != null && !string.IsNullOrEmpty(prefs.defaultProfile))
                {
                    Joy.LoadProfile(prefs.defaultProfile);
                }
            }

            if (result)
            {
                connectBtn.IsEnabled = false;
                status.Content       = Globalization.Translate("Status_Connected");
            }

            ConnectClick?.Invoke(this, result);
        }
        private void loadBtn_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog();
            dialog.FileName   = string.IsNullOrEmpty(FileName) ? "joystick_calibration" : FileName;
            dialog.DefaultExt = ".joy";
            dialog.Filter     = App.JOY_CAL_FILTER;

            bool?    doLoad = dialog.ShowDialog();
            Joystick loadedConfig;

            if (doLoad == true && dialog.CheckFileExists)
            {
                if (App.LoadFromFile <Joystick>(dialog.FileName, out loadedConfig))
                {
                    FileName = dialog.FileName;
                    Set(loadedConfig);
                }
                else
                {
                    MessageBox.Show(
                        Globalization.TranslateFormat("Calibration_Load_Error_Msg", dialog.FileName),
                        Globalization.Translate("Calibration_Load_Error"),
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }
        }
        public void ClearTooltips()
        {
            string unsetText = Globalization.Translate("Input_Unset");

            aBtn.ToolTip      = unsetText;
            bBtn.ToolTip      = unsetText;
            xBtn.ToolTip      = unsetText;
            yBtn.ToolTip      = unsetText;
            lBtn.ToolTip      = unsetText;
            rBtn.ToolTip      = unsetText;
            zlBtn.ToolTip     = unsetText;
            zrBtn.ToolTip     = unsetText;
            homeBtn.ToolTip   = unsetText;
            plusBtn.ToolTip   = unsetText;
            minusBtn.ToolTip  = unsetText;
            dpadUp.ToolTip    = unsetText;
            dpadLeft.ToolTip  = unsetText;
            dpadRight.ToolTip = unsetText;
            dpadDown.ToolTip  = unsetText;
            UpdateTooltipLine(leftStickBtn, unsetText, 0);
            UpdateTooltipLine(leftStickBtn, unsetText, 1);
            UpdateTooltipLine(leftStickBtn, unsetText, 2);
            UpdateTooltipLine(leftStickBtn, unsetText, 3);
            UpdateTooltipLine(leftStickBtn, unsetText, 4);
            UpdateTooltipLine(rightStickBtn, unsetText, 0);
            UpdateTooltipLine(rightStickBtn, unsetText, 1);
            UpdateTooltipLine(rightStickBtn, unsetText, 2);
            UpdateTooltipLine(rightStickBtn, unsetText, 3);
            UpdateTooltipLine(rightStickBtn, unsetText, 4);
            UpdateTooltipLine(dpadCenter, unsetText, 0);
            UpdateTooltipLine(dpadCenter, unsetText, 1);
            UpdateTooltipLine(dpadCenter, unsetText, 2);
            UpdateTooltipLine(dpadCenter, unsetText, 3);
        }
        public GameCubeControl()
        {
            _inputPrefix        = "1_";
            _connectedStatus    = Globalization.Translate("Controller_Connected");
            _disconnectedStatus = Globalization.Translate("Controller_Disconnect");

            InitializeComponent();

            for (int i = 0; i < 4; ++i)
            {
                (portSelection.Items[i] as MenuItem).Header = Globalization.TranslateFormat("GCN_Port", i);
            }
        }
Exemple #11
0
        public void ClearTooltips()
        {
            string unsetText = Globalization.Translate("Input_Unset");

            aBtn.ToolTip    = unsetText;
            xBtn.ToolTip    = unsetText;
            bBtn.ToolTip    = unsetText;
            yBtn.ToolTip    = unsetText;
            slBtn.ToolTip   = unsetText;
            srBtn.ToolTip   = unsetText;
            plusBtn.ToolTip = unsetText;
            homeBtn.ToolTip = unsetText;
            UpdateTooltipLine(joyStickButton, unsetText, 0);
            UpdateTooltipLine(joyStickButton, unsetText, 1);
            UpdateTooltipLine(joyStickButton, unsetText, 2);
            UpdateTooltipLine(joyStickButton, unsetText, 3);
            UpdateTooltipLine(joyStickButton, unsetText, 4);
        }
        private void settingLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (AppPrefs.Instance.language != settingLanguage.SelectedIndex)
            {
                AppPrefs.Instance.language = settingLanguage.SelectedIndex;
                Globalization.SetSelectedLanguage(settingLanguage.SelectedIndex);

                // This will apply some translations but not all since some are created in code instead of being tagged on the xaml
                Globalization.ApplyTranslations(this);
                if (tabControl.Items.Count > 1)
                {
                    for (int i = 1; i < tabControl.Items.Count; ++i)
                    {
                        Globalization.ApplyTranslations(tabControl.Items[i] as DependencyObject);
                    }
                }

                MessageBox.Show(
                    Globalization.Translate("Restart_Msg"),
                    Globalization.Translate("Restart"),
                    MessageBoxButton.OK);
            }
        }
 private void btnRemoveXinput_Click(object sender, RoutedEventArgs e)
 {
     if (ScpDirector.Access.IsConnected(ScpDirector.XInput_Device.Device_D))
     {
         if (ScpDirector.Access.DisconnectDevice(ScpDirector.XInput_Device.Device_D))
         {
             btnAddXinput.IsEnabled = true;
             xlabel4.Content        = Globalization.TranslateFormat("XInput_Device_Num", "4", Globalization.Translate("Status_Disconnected"));
         }
     }
     else if (ScpDirector.Access.IsConnected(ScpDirector.XInput_Device.Device_C))
     {
         if (ScpDirector.Access.DisconnectDevice(ScpDirector.XInput_Device.Device_C))
         {
             xlabel3.Content = Globalization.TranslateFormat("XInput_Device_Num", "3", Globalization.Translate("Status_Disconnected"));
         }
     }
     else if (ScpDirector.Access.IsConnected(ScpDirector.XInput_Device.Device_B))
     {
         if (ScpDirector.Access.DisconnectDevice(ScpDirector.XInput_Device.Device_B))
         {
             xlabel2.Content = Globalization.TranslateFormat("XInput_Device_Num", "2", Globalization.Translate("Status_Disconnected"));
         }
     }
     else if (ScpDirector.Access.IsConnected(ScpDirector.XInput_Device.Device_A))
     {
         if (ScpDirector.Access.DisconnectDevice(ScpDirector.XInput_Device.Device_A))
         {
             btnRemoveXinput.IsEnabled = false;
             xlabel1.Content           = Globalization.TranslateFormat("XInput_Device_Num", "1", Globalization.Translate("Status_Disconnected"));
         }
     }
 }
Exemple #14
0
 private void cancel_Click(object sender, RoutedEventArgs e)
 {
     Prompt(Globalization.Translate("Sync_Cancel"));
     cancelled = true;
 }
Exemple #15
0
        public void Sync()
        {
            Guid          HIDServiceClass = Guid.Parse(NativeImports.HID_GUID);
            List <IntPtr> btRadios        = new List <IntPtr>();
            int           pairedCount     = 0;
            IntPtr        foundRadio;
            IntPtr        handle;

            NativeImports.BLUETOOTH_FIND_RADIO_PARAMS radioParams = new NativeImports.BLUETOOTH_FIND_RADIO_PARAMS();

            radioParams.Initialize();

            handle = NativeImports.BluetoothFindFirstRadio(ref radioParams, out foundRadio);
            bool next = handle != IntPtr.Zero;

            do
            {
                if (foundRadio != IntPtr.Zero)
                {
                    btRadios.Add(foundRadio);
                }

                next = NativeImports.BluetoothFindNextRadio(ref handle, out foundRadio);
            }while (next);

            if (btRadios.Count > 0)
            {
                Prompt(Globalization.Translate("Sync_Searching"));

                while (pairedCount == 0 && !cancelled)
                {
                    for (int r = 0; r < btRadios.Count; r++)
                    {
                        IntPtr found;
                        NativeImports.BLUETOOTH_RADIO_INFO           radioInfo    = new NativeImports.BLUETOOTH_RADIO_INFO();
                        NativeImports.BLUETOOTH_DEVICE_INFO          deviceInfo   = new NativeImports.BLUETOOTH_DEVICE_INFO();
                        NativeImports.BLUETOOTH_DEVICE_SEARCH_PARAMS searchParams = new NativeImports.BLUETOOTH_DEVICE_SEARCH_PARAMS();

                        radioInfo.Initialize();
                        deviceInfo.Initialize();
                        searchParams.Initialize();

                        uint getInfoError = NativeImports.BluetoothGetRadioInfo(btRadios[r], ref radioInfo);

                        // Success
                        if (getInfoError == 0)
                        {
                            searchParams.fReturnAuthenticated = false;
                            searchParams.fReturnRemembered    = false;
                            searchParams.fReturnConnected     = false;
                            searchParams.fReturnUnknown       = true;
                            searchParams.fIssueInquiry        = true;
                            searchParams.cTimeoutMultiplier   = 2;
                            searchParams.hRadio = btRadios[r];

                            found = NativeImports.BluetoothFindFirstDevice(ref searchParams, ref deviceInfo);

                            if (found != IntPtr.Zero)
                            {
                                do
                                {
                                    bool controller = SupportedDevice(deviceInfo.szName);
                                    bool wiiDevice  = deviceInfo.szName.StartsWith("Nintendo RVL");

                                    if (controller || wiiDevice)
                                    {
                                        Prompt(Globalization.TranslateFormat("Sync_Found", deviceInfo.szName));

                                        StringBuilder password  = new StringBuilder();
                                        uint          pcService = 16;
                                        Guid[]        guids     = new Guid[16];
                                        bool          success   = true;

                                        if (deviceInfo.fRemembered)
                                        {
                                            // Remove current pairing
                                            Prompt(Globalization.TranslateFormat("Sync_Unpairing"));
                                            uint errForget = NativeImports.BluetoothRemoveDevice(ref deviceInfo.Address);
                                            success = errForget == 0;
                                        }

                                        if (wiiDevice)
                                        {
                                            // use MAC address of BT radio as pin
                                            var bytes = BitConverter.GetBytes(radioInfo.address);
                                            for (int i = 0; i < 6; i++)
                                            {
                                                password.Append((char)bytes[i]);
                                            }

                                            if (success)
                                            {
                                                Prompt(Globalization.Translate("Sync_Pairing"));
                                                var errPair = NativeImports.BluetoothAuthenticateDevice(IntPtr.Zero, btRadios[r], ref deviceInfo, password.ToString(), 6);
                                                success = errPair == 0;
                                            }

                                            if (success)
                                            {
                                                Prompt(Globalization.Translate("Sync_Service"));
                                                var errService = NativeImports.BluetoothEnumerateInstalledServices(btRadios[r], ref deviceInfo, ref pcService, guids);
                                                success = errService == 0;
                                            }

                                            if (success)
                                            {
                                                Prompt(Globalization.Translate("Sync_HID"));
                                                var errActivate = NativeImports.BluetoothSetServiceState(btRadios[r], ref deviceInfo, ref HIDServiceClass, 0x01);
                                                success = errActivate == 0;
                                            }

                                            if (success)
                                            {
                                                Prompt(Globalization.Translate("Sync_Success"));
                                                pairedCount += 1;
                                            }
                                            else
                                            {
                                                Prompt(Globalization.Translate("Sync_Failure"));
                                            }
                                        }
                                        else
                                        {
                                            Prompt(Globalization.Translate("Sync_Finish"));
                                            var err = NativeImports.BluetoothAuthenticateDeviceEx(IntPtr.Zero, btRadios[r], ref deviceInfo, null, NativeImports.AUTHENTICATION_REQUIREMENTS.MITMProtectionNotRequired);

                                            if (err == 0)
                                            {
                                                Prompt(Globalization.Translate("Sync_Success"));
                                                pairedCount += 1;
                                            }
                                            else
                                            {
                                                Prompt(Globalization.Translate("Sync_Incomplete"));
                                            }
                                        }
                                    }
                                }while (NativeImports.BluetoothFindNextDevice(found, ref deviceInfo));
                            }
                        }
                        else
                        {
                            // Failed to get Bluetooth Radio Info
                            Prompt(Globalization.Translate("Sync_Bluetooth_Failed"));
                        }
                    }
                }

                // Close Opened Radios
                foreach (var openRadio in btRadios)
                {
                    NativeImports.CloseHandle(openRadio);
                }
            }
            else
            {
                // No Bluetooth Radios found
                Prompt(Globalization.Translate("Sync_No_Bluetooth"));
                System.Threading.Thread.Sleep(3000);
            }

            NativeImports.BluetoothFindRadioClose(handle);

            Dispatcher.BeginInvoke((Action)(() => Close()));
        }
        public DeviceStatus(DeviceInfo info, CommonStream stream = null)
        {
            InitializeComponent();

            connectBtn.Content = Globalization.Translate(connectBtn.Uid);
            status.Content     = Globalization.Translate("Status_Not_Connected");
            nickname.Content   = Globalization.Translate("Status_Unidentified");

            Info = info;

            if (info.InstanceGUID.Equals(Guid.Empty))
            {
                if (stream == null)
                {
                    Ninty = new NintyControl(Info);
                }
                else
                {
                    Ninty = new NintyControl(Info, stream);
                }

                Ninty.OnTypeChange  += Ninty_OnTypeChange;
                Ninty.OnDisconnect  += Ninty_OnDisconnect;
                Ninty.OnPrefsChange += Ninty_OnPrefsChange;
                Ninty.OnRumbleSubscriptionChange += Ninty_OnRumbleSubscriptionChange;

                // Use saved icon if there is one
                var prefs = AppPrefs.Instance.GetDevicePreferences(Info.DevicePath);
                if (prefs != null && !string.IsNullOrWhiteSpace(prefs.icon))
                {
                    icon.Source      = new BitmapImage(new Uri("../Images/Icons/" + prefs.icon, UriKind.Relative));
                    nickname.Content = string.IsNullOrWhiteSpace(prefs.nickname) ? info.Type.ToName() : prefs.nickname;
                }
                else
                {
                    UpdateType(info.Type);
                }
            }
            else
            {
                Joy = new JoyControl(Info);
                Joy.OnDisconnect  += Ninty_OnDisconnect;
                Joy.OnPrefsChange += Ninty_OnPrefsChange;
                nickname.Content   = JoyControl.ToName(Joy.Type);
                if (info.VID == "057e" && info.PID == "2006")
                {
                    icon.Source = new BitmapImage(new Uri("../Images/Icons/switch_jcl_black.png", UriKind.Relative));
                }
                else if (info.VID == "057e" && info.PID == "2007")
                {
                    icon.Source = new BitmapImage(new Uri("../Images/Icons/switch_jcr_black.png", UriKind.Relative));
                }
                else if (info.VID == "057e" && info.PID == "2009")
                {
                    icon.Source = new BitmapImage(new Uri("../Images/Icons/switch_pro_black.png", UriKind.Relative));
                }
                else
                {
                    icon.Source = new BitmapImage(new Uri("../Images/Icons/joystick_icon.png", UriKind.Relative));
                }
            }
        }
Exemple #17
0
        protected BaseControl()
        {
            _analogMenu = new ContextMenu();

            // Create menu items for assigning input directions.
            _analogMenu.Items.Add(new MenuItem {
                Header = Globalization.Translate("Context_Up"), Tag = "UP"
            });
            _analogMenu.Items.Add(new MenuItem {
                Header = Globalization.Translate("Context_Left"), Tag = "LEFT"
            });
            _analogMenu.Items.Add(new MenuItem {
                Header = Globalization.Translate("Context_Right"), Tag = "RIGHT"
            });
            _analogMenu.Items.Add(new MenuItem {
                Header = Globalization.Translate("Context_Down"), Tag = "DOWN"
            });
            _analogMenu.Items.Add(new MenuItem {
                Header = Globalization.Translate("Context_Joy_Button"), Tag = "S"
            });

            // Create menu items for analog triggers
            _analogMenu.Items.Add(new MenuItem {
                Header = Globalization.Translate("Context_Press"), Tag = "T"
            });
            _analogMenu.Items.Add(new MenuItem {
                Header = Globalization.Translate("Context_Press_Full"), Tag = "FULL"
            });

            foreach (var menuItem in _analogMenu.Items)
            {
                (menuItem as MenuItem).Click += OpenSelectedInput;
            }

            _analogMenu.Items.Add(new Separator());

            // Create menu items for quick assignment
            var quickAssign = new MenuItem {
                Header = Globalization.Translate("Context_Quick")
            };
            var quickMouse = new MenuItem {
                Header = Globalization.Translate("Context_Quick_Mouse")
            };

            {
                quickMouse.Items.Add(new MenuItem {
                    Header = Globalization.Translate("Context_Quick_Mouse_50"), Tag = "50"
                });
                quickMouse.Items.Add(new MenuItem {
                    Header = Globalization.Translate("Context_Quick_Mouse_100"), Tag = "100"
                });
                quickMouse.Items.Add(new MenuItem {
                    Header = Globalization.Translate("Context_Quick_Mouse_150"), Tag = "150"
                });
                quickMouse.Items.Add(new MenuItem {
                    Header = Globalization.Translate("Context_Quick_Mouse_200"), Tag = "200"
                });
                quickMouse.Items.Add(new MenuItem {
                    Header = Globalization.Translate("Context_Quick_Mouse_250"), Tag = "250"
                });
                quickMouse.Items.Add(new MenuItem {
                    Header = Globalization.Translate("Context_Quick_Mouse_300"), Tag = "300"
                });
            }
            foreach (var menuItem in quickMouse.Items)
            {
                (menuItem as MenuItem).Click += QuickAssignMouse_Click;
            }
            quickAssign.Items.Add(quickMouse);
            quickAssign.Items.Add(new MenuItem {
                Header = "WASD"
            });
            quickAssign.Items.Add(new MenuItem {
                Header = Globalization.Translate("Context_Quick_Arrows")
            });
            (quickAssign.Items[1] as MenuItem).Click += QuickAssign_Click;
            (quickAssign.Items[2] as MenuItem).Click += QuickAssign_Click;
            _analogMenu.Items.Add(quickAssign);

            _analogMenu.Items.Add(new Separator());

            // Create menu items for IR camera
            var irMode = new MenuItem {
                Header = Globalization.Translate("Context_IR_Mode")
            };

            {
                irMode.Items.Add(new MenuItem {
                    Header = Globalization.Translate("Context_IR_Basic")
                });
                irMode.Items.Add(new MenuItem {
                    Header = Globalization.Translate("Context_IR_Wide")
                });
                irMode.Items.Add(new MenuItem {
                    Header = Globalization.Translate("Context_IR_Full")
                });
                irMode.Items.Add(new MenuItem {
                    Header = Globalization.Translate("Context_IR_Off")
                });
            }
            foreach (var irModeItem in irMode.Items)
            {
                (irModeItem as MenuItem).Click += SetIRCamMode_Click;
            }
            var irLevel = new MenuItem {
                Header = Globalization.Translate("Context_IR_Level")
            };

            {
                irLevel.Items.Add(new MenuItem {
                    Header = Globalization.Translate("Context_IR_Level_1")
                });
                irLevel.Items.Add(new MenuItem {
                    Header = Globalization.Translate("Context_IR_Level_2")
                });
                irLevel.Items.Add(new MenuItem {
                    Header = Globalization.Translate("Context_IR_Level_3")
                });
                irLevel.Items.Add(new MenuItem {
                    Header = Globalization.Translate("Context_IR_Level_4")
                });
                irLevel.Items.Add(new MenuItem {
                    Header = Globalization.Translate("Context_IR_Level_5")
                });
            }
            foreach (var irLevelItem in irLevel.Items)
            {
                (irLevelItem as MenuItem).Click += SetIRCamSensitivity_Click;
            }
            _analogMenu.Items.Add(irMode);
            _analogMenu.Items.Add(irLevel);

            // Add Calibration menu item
            var calibrationItem = new MenuItem {
                Header = Globalization.Translate("Context_Calibrate")
            };

            calibrationItem.Click += CalibrateInput_Click;
            _analogMenu.Items.Add(calibrationItem);

            ContextMenu = _analogMenu;
            ContextMenuService.SetIsEnabled(this, false);
        }
        private void DoConnect(DeviceStatus status, bool result)
        {
            if (result && status.Control != null)
            {
                // Associate L & R Joy-Cons
                if (status.Joy != null)
                {
                    if (status.Joy.Type == JoyControl.JoystickType.LeftJoyCon || status.Joy.Type == JoyControl.JoystickType.RightJoyCon)
                    {
                        foreach (var item in tabControl.Items)
                        {
                            if (item is TabItem && ((TabItem)item).Content is JoyControl)
                            {
                                var jc = ((JoyControl)((TabItem)item).Content);
                                if (jc.associatedJoyCon == null)
                                {
                                    if ((jc.Type == JoyControl.JoystickType.LeftJoyCon || jc.Type == JoyControl.JoystickType.RightJoyCon) &&
                                        jc.Type != status.Joy.Type)
                                    {
                                        jc.AssociateJoyCon(status.Joy);
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }

                var prefs = AppPrefs.Instance.GetDevicePreferences(status.Info.DeviceID);

                // If connection to device succeeds add a tab
                TabItem    tab   = new TabItem();
                StackPanel stack = new StackPanel {
                    Orientation = Orientation.Horizontal
                };
                stack.Children.Add(new Image
                {
                    Source              = status.Icon,
                    Height              = 12,
                    Margin              = new Thickness(0, 0, 4, 0),
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Left
                });

                // Use the nickname if there is one
                if (prefs != null && !string.IsNullOrWhiteSpace(prefs.nickname))
                {
                    stack.Children.Add(new TextBlock {
                        Text = prefs.nickname
                    });
                }
                else
                {
                    stack.Children.Add(new TextBlock {
                        Text = status.nickname.Content.ToString()
                    });
                }

                tab.Header  = stack;
                tab.Content = status.Control;
                tabControl.Items.Add(tab);
            }
            else if (!AppPrefs.Instance.suppressConnectionLost)
            {
                // Display message
                MessageBox.Show(
                    Globalization.Translate("Error_Connection"),
                    Globalization.Translate("Error_Failed"),
                    MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
        public void RumbleSettingsChanged(DeviceStatus s, bool[] rumbleSubscriptions)
        {
            if (AppPrefs.Instance.autoAddXInputDevices)
            {
                int n = 3;
                for (; n > -1; n--)
                {
                    if (rumbleSubscriptions[n])
                    {
                        break;
                    }
                }

                if (n > -1 && !ScpDirector.Access.IsConnected(ScpDirector.XInput_Device.Device_A))
                {
                    bool connected = false;
                    for (int i = 0; i < 4; i++)
                    {
                        ScpDirector.Access.SetModifier(i);
                        connected = ScpDirector.Access.ConnectDevice(ScpDirector.XInput_Device.Device_A);
                        if (connected)
                        {
                            break;
                        }
                    }

                    if (connected)
                    {
                        btnRemoveXinput.IsEnabled = true;
                        xlabel1.Content           = Globalization.TranslateFormat("XInput_Device_Num", "1", Globalization.Translate("Status_Auto"));
                    }
                }
                if (n > 0 && !ScpDirector.Access.IsConnected(ScpDirector.XInput_Device.Device_B))
                {
                    if (ScpDirector.Access.ConnectDevice(ScpDirector.XInput_Device.Device_B))
                    {
                        xlabel2.Content = Globalization.TranslateFormat("XInput_Device_Num", "2", Globalization.Translate("Status_Auto"));
                    }
                }
                if (n > 1 && !ScpDirector.Access.IsConnected(ScpDirector.XInput_Device.Device_C))
                {
                    if (ScpDirector.Access.ConnectDevice(ScpDirector.XInput_Device.Device_C))
                    {
                        xlabel3.Content = Globalization.TranslateFormat("XInput_Device_Num", "3", Globalization.Translate("Status_Auto"));
                    }
                }
                if (n > 2 && !ScpDirector.Access.IsConnected(ScpDirector.XInput_Device.Device_D))
                {
                    if (ScpDirector.Access.ConnectDevice(ScpDirector.XInput_Device.Device_D))
                    {
                        btnAddXinput.IsEnabled = false;
                        xlabel4.Content        = Globalization.TranslateFormat("XInput_Device_Num", "4", Globalization.Translate("Status_Auto"));
                    }
                }
            }
        }
        private void btnAddXinput_Click(object sender, RoutedEventArgs e)
        {
            if (!ScpDirector.Access.IsConnected(ScpDirector.XInput_Device.Device_A))
            {
                bool connected = false;
                for (int i = 0; i < 4; i++)
                {
                    ScpDirector.Access.SetModifier(i);
                    connected = ScpDirector.Access.ConnectDevice(ScpDirector.XInput_Device.Device_A);
                    if (connected)
                    {
                        break;
                    }
                }

                if (connected)
                {
                    btnRemoveXinput.IsEnabled = true;
                    xlabel1.Content           = Globalization.TranslateFormat("XInput_Device_Num", "1", Globalization.Translate("Status_Connected"));
                }
            }
            else if (!ScpDirector.Access.IsConnected(ScpDirector.XInput_Device.Device_B))
            {
                if (ScpDirector.Access.ConnectDevice(ScpDirector.XInput_Device.Device_B))
                {
                    xlabel2.Content = Globalization.TranslateFormat("XInput_Device_Num", "2", Globalization.Translate("Status_Connected"));
                }
            }
            else if (!ScpDirector.Access.IsConnected(ScpDirector.XInput_Device.Device_C))
            {
                if (ScpDirector.Access.ConnectDevice(ScpDirector.XInput_Device.Device_C))
                {
                    xlabel3.Content = Globalization.TranslateFormat("XInput_Device_Num", "3", Globalization.Translate("Status_Connected"));
                }
            }
            else if (!ScpDirector.Access.IsConnected(ScpDirector.XInput_Device.Device_D))
            {
                if (ScpDirector.Access.ConnectDevice(ScpDirector.XInput_Device.Device_D))
                {
                    btnAddXinput.IsEnabled = false;
                    xlabel4.Content        = Globalization.TranslateFormat("XInput_Device_Num", "4", Globalization.Translate("Status_Connected"));
                }
            }
        }
 private void Ninty_OnDisconnect()
 {
     connectBtn.IsEnabled = true;
     status.Content       = Globalization.Translate("Status_Not_Connected");
     CloseTab?.Invoke(this);
 }