Exemple #1
0
        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("Unable to Connect Device", "Failed", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
Exemple #2
0
        public void Refresh()
        {
            // Prevent this method from being spammed
            if (DateTime.Now.Subtract(_lastRefreshTime).TotalSeconds < 1)
            {
                return;
            }
            _lastRefreshTime = DateTime.Now;

            // Bluetooth Devices
            var devices = WinBtStream.GetPaths();

            // Direct input Devices
            DInput = new SharpDX.DirectInput.DirectInput();
            var joys = DInput.GetDevices(SharpDX.DirectInput.DeviceClass.GameControl, SharpDX.DirectInput.DeviceEnumerationFlags.AllDevices);

            foreach (var j in joys)
            {
                string pid = j.ProductGuid.ToString().Substring(0, 4);
                string vid = j.ProductGuid.ToString().Substring(4, 4);

                // devices to ignore
                if (vid == "057e" && (pid == "0330" || pid == "0306" || pid == "0337"))
                {
                    continue;
                }
                else if (vid == "1234" && pid == "bead")
                {
                    continue;
                }

                devices.Add(new Shared.DeviceInfo()
                {
                    InstanceGUID = j.InstanceGuid,
                    PID          = pid,
                    VID          = vid
                });
            }

            // GCN Adapter
            WinUsbStream gcnStream = new WinUsbStream(new UsbDeviceFinder(0x057E, 0x0337));

            Shared.DeviceInfo gcnDevice = null;
            if (gcnStream.DeviceFound())
            {
                gcnDevice = new Shared.DeviceInfo()
                {
                    VID  = "057E",
                    PID  = "0337",
                    Type = NintrollerLib.ControllerType.Other
                };

                devices.Add(gcnDevice);
            }
#if DEBUG
            // Test GCN Device
            else
            {
                devices.Add(new Shared.DeviceInfo()
                {
                    DevicePath = "Dummy GCN", PID = "0337", Type = NintrollerLib.ControllerType.Other
                });
            }

            // Test Device
            devices.Add(new Shared.DeviceInfo()
            {
                DevicePath = "Dummy", Type = NintrollerLib.ControllerType.ProController
            });
            devices.Add(new Shared.DeviceInfo()
            {
                DevicePath = "Dummy Wiimote", Type = NintrollerLib.ControllerType.Wiimote
            });
#endif

            foreach (var info in devices)
            {
                // Check if we are already showing this one
                DeviceStatus existing = _availableDevices.Find((d) => d.Info.SameDevice(info.DeviceID));

                // If not add it
                if (existing == null)
                {
                    var status = new DeviceStatus(info, info == gcnDevice ? gcnStream : null);
                    status.ConnectClick = DoConnect;
                    status.TypeUpdated  = (s, t) =>
                    {
                        var    p     = AppPrefs.Instance.GetDevicePreferences(s.Info.DevicePath);
                        string title = "";

                        if (p != null && !string.IsNullOrWhiteSpace(p.nickname))
                        {
                            title = p.nickname;
                        }
                        else
                        {
                            title = t.ToString();
                        }

                        foreach (var tab in tabControl.Items)
                        {
                            if (tab is TabItem && (tab as TabItem).Content == s.Control)
                            {
                                ChangeIcon(tab as TabItem, t);
                                ChangeTitle(tab as TabItem, title);
                            }
                        }
                    };
                    status.CloseTab = (s) =>
                    {
                        // Find associated tab, skip first as it is home
                        for (int i = 1; i < tabControl.Items.Count; i++)
                        {
                            var tab = tabControl.Items[i];
                            if (tab is TabItem && (tab as TabItem).Content == s.Control)
                            {
                                tabControl.Items.RemoveAt(i);
                                break;
                            }
                        }
                    };
                    status.OnPrefsChange = (s, p) =>
                    {
                        if (!string.IsNullOrWhiteSpace(p.nickname))
                        {
                            foreach (var tab in tabControl.Items)
                            {
                                if (tab is TabItem && (tab as TabItem).Content == s.Control)
                                {
                                    ChangeTitle(tab as TabItem, p.nickname);
                                }
                            }
                        }
                    };
                    status.OnRumbleSubscriptionChange = RumbleSettingsChanged;
                    _availableDevices.Add(status);
                    statusStack.Children.Add(status);

                    DevicePrefs devicePrefs = AppPrefs.Instance.GetDevicePreferences(info.DeviceID);
                    if (devicePrefs.autoConnect)
                    {
                        status.AutoConnect();
                    }
                }
                else if (!existing.Connected)
                {
                    DevicePrefs existingPrefs = AppPrefs.Instance.GetDevicePreferences(info.DeviceID);
                    if (existingPrefs.autoConnect)
                    {
                        existing.AutoConnect();
                    }
                }
            }
        }
Exemple #3
0
        public void Refresh()
        {
            // Prevent this method from being spammed
            if (DateTime.Now.Subtract(_lastRefreshTime).TotalSeconds < 1)
            {
                return;
            }
            _lastRefreshTime = DateTime.Now;

            var devices = WinBtStream.GetPaths();

            // Direct input Devices
            DInput = new SharpDX.DirectInput.DirectInput();
            var joys = DInput.GetDevices(SharpDX.DirectInput.DeviceClass.GameControl, SharpDX.DirectInput.DeviceEnumerationFlags.AllDevices);

            foreach (var j in joys)
            {
                string pid = j.ProductGuid.ToString().Substring(0, 4);
                string vid = j.ProductGuid.ToString().Substring(4, 4);

                // devices to ignore
                if (vid == "057e" && (pid == "0330" || pid == "0306"))
                {
                    continue;
                }
                else if (vid == "1234" && pid == "bead")
                {
                    continue;
                }

                devices.Add(new Shared.DeviceInfo()
                {
                    InstanceGUID = j.InstanceGuid,
                    PID          = pid,
                    VID          = vid
                });
            }

            foreach (var info in devices)
            {
                // Check if we are already showing this one
                DeviceStatus existing = _availableDevices.Find((d) => d.Info.SameDevice(info.DeviceID));

                // If not add it
                if (existing == null)
                {
                    var status = new DeviceStatus(info);
                    status.ConnectClick = DoConnect;
                    status.TypeUpdated  = (s, t) =>
                    {
                        var    p     = AppPrefs.Instance.GetDevicePreferences(s.Info.DevicePath);
                        string title = "";

                        if (p != null && !string.IsNullOrWhiteSpace(p.nickname))
                        {
                            title = p.nickname;
                        }
                        else
                        {
                            title = t.ToString();
                        }

                        foreach (var tab in tabControl.Items)
                        {
                            if (tab is TabItem && (tab as TabItem).Content == s.Control)
                            {
                                ChangeIcon(tab as TabItem, t);
                                ChangeTitle(tab as TabItem, title);
                            }
                        }
                    };
                    status.CloseTab = (s) =>
                    {
                        // Find associated tab, skip first as it is home
                        for (int i = 1; i < tabControl.Items.Count; i++)
                        {
                            var tab = tabControl.Items[i];
                            if (tab is TabItem && (tab as TabItem).Content == s.Control)
                            {
                                tabControl.Items.RemoveAt(i);
                                break;
                            }
                        }
                    };
                    status.OnPrefsChange = (s, p) =>
                    {
                        if (!string.IsNullOrWhiteSpace(p.nickname))
                        {
                            foreach (var tab in tabControl.Items)
                            {
                                if (tab is TabItem && (tab as TabItem).Content == s.Control)
                                {
                                    ChangeTitle(tab as TabItem, p.nickname);
                                }
                            }
                        }
                    };

                    _availableDevices.Add(status);
                    statusStack.Children.Add(status);

                    DevicePrefs devicePrefs = AppPrefs.Instance.GetDevicePreferences(info.DeviceID);
                    if (devicePrefs.autoConnect)
                    {
                        status.AutoConnect();
                    }
                }
                else if (!existing.Connected)
                {
                    DevicePrefs existingPrefs = AppPrefs.Instance.GetDevicePreferences(info.DeviceID);
                    if (existingPrefs.autoConnect)
                    {
                        existing.AutoConnect();
                    }
                }
            }
        }