public NintyControl(DeviceInfo deviceInfo) : this()
        {
            _assignments = new[] {
                new Dictionary <string, AssignmentCollection>(),
                new Dictionary <string, AssignmentCollection>(),
                new Dictionary <string, AssignmentCollection>(),
                new Dictionary <string, AssignmentCollection>()
            };

            _info = deviceInfo;
            _scp  = ScpDirector.Access;
        }
Esempio n. 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", VID = "057E", 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();
                    }
                }
            }
        }