コード例 #1
0
        public string RemoveDevice(string UniqueKey)
        {
            lock (Controllers)
            {
                //Console.WriteLine($"Removing {UniqueKey}");
                if (Controllers.ContainsKey(UniqueKey))
                {
                    FlydigiController ctrl = Controllers[UniqueKey];
                    string            UniqueControllerId = ctrl.ConnectionUniqueID;

                    ctrl.DeInitalize();
                    ctrl.Dispose();
                    Controllers.Remove(UniqueKey);

                    return(UniqueControllerId);
                }
            }
            return(null);
        }
コード例 #2
0
        public IController NewDevice(IDevice device)
        {
            HidDevice    _device  = device as HidDevice;
            XInputDevice _deviceX = device as XInputDevice;

            if (_device == null && _deviceX == null)
            {
                return(null);
            }

            // TODO this check system should only run if FullControl mode is enabled
            //      this is all irrelevent if we have a system where we can get the true ProductName, VID, and PID of the XInput controller
            //      if we ever gain access to that info, we will have to make sure the below logic is still present for if the XInput provider
            //      doesn't have that info (check presence of Properties perhapse?)
            //      It might be simpler to keep the XInputDevice handling as is if the VID/PID/ProductName are null but if they are known immediately rumble
            //      In this design, if we see a HID device for the controller and we want to correct it, we'd start a count-down and if we didn't see any XInput
            //      devices we could manually trigger within that time (inlcuding one that came through just ahead) we'd force run over all the memorized ones
            //      Note that for some reason this doesn't work properly for an APEX2 on USB, it switches right back to XInput again.
            if (_device != null)
            {
                if (device.VendorId == 0x045E && device.ProductId == 0x028E)
                {
                    if (this.AccessMode != AccessMode.FullControl)
                    {
                        return(null);
                    }

                    if (device.Properties["ProductName"] == "Controller (Flydigi 2.4G x360)" ||
                        device.Properties["ProductName"] == "Controller (Flydigi 2.4G Android)") // APEX2 on USB does this for some reason
                    {
                        lock (CandidateXInputLock)
                            SawCandidateHidDeviceForXInput = DateTime.UtcNow;
                        CheckXInputData();
                    }
                    return(null);
                }
            }
            else if (_deviceX != null)
            {
                if (this.AccessMode != AccessMode.FullControl)
                {
                    return(null);
                }

                lock (CandidateXInputLock)
                {
                    CandidateXInputDevicesX[(byte)_deviceX.UserIndex]        = new WeakReference <XInputDevice>(_deviceX);
                    CandidateXInputDevicesLastSeen[(byte)_deviceX.UserIndex] = DateTime.UtcNow;
                }
                CheckXInputData();
                return(null);
            }

            // if we are in full control mode, check for xbox here and if it is a flydigi controller send the command that changes the mode here and return null

            if (_device.VendorId == FlydigiController.VENDOR_FLYDIGI)
            {
                if (!new int[] {
                    FlydigiController.PRODUCT_FLYDIGI_DONGLE_1,
                    FlydigiController.PRODUCT_FLYDIGI_DONGLE_2,
                    FlydigiController.PRODUCT_FLYDIGI_DONGLE_3,
                    FlydigiController.PRODUCT_FLYDIGI_USB,
                }.Contains(_device.ProductId))
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }

            //string bt_hid_id = @"00001124-0000-1000-8000-00805f9b34fb";

            string devicePath = _device.DevicePath.ToString();

            uint[]          Usages  = device.Properties.ContainsKey("Usages") ? device.Properties["Usages"] as uint[] : null;
            EConnectionType ConType = EConnectionType.Unknown;

            switch (_device.VendorId)
            {
            case FlydigiController.VENDOR_FLYDIGI:
                if (_device.Properties.ContainsKey("ProductName") && (((_device.Properties["ProductName"] as string)?.ToLowerInvariant()?.Contains("flydigi") ?? false) || ((_device.Properties["ProductName"] as string)?.ToLowerInvariant()?.Contains("feizhi") ?? false)))
                {
                    //&& devicePath.Contains("mi_02")
                    if (Usages.Contains(0xffa00001u))
                    {
                    }
                    else
                    {
                        return(null);
                    }
                    //if (devicePath.Contains(bt_hid_id))
                    //{
                    //    ConType = EConnectionType.Bluetooth;
                    //}
                    //else
                    //{
                    //    ConType = EConnectionType.USB;
                    //}
                }
                //else if (_device.ProductId == FlydigiController.PRODUCT_FLYDIGI_USB && devicePath.Contains("mi_00"))
                //{
                //
                //}
                else
                {
                    return(null);
                }
                break;
            }

            lock (Controllers)
            {
                FlydigiController ctrl = new FlydigiController(_device, ConType);
                Controllers[_device.UniqueKey] = ctrl;
                //Console.WriteLine($"Controllers[\"{_device.UniqueKey}\"] = {ctrl};");
                return(ctrl);
            }
        }