예제 #1
0
        private void LoadDeviceInputs()
        {
            var devicelist = DeviceBinding.Profile.GetDeviceList(DeviceBinding);

            Devices = new ObservableCollection <ComboBoxItemViewModel>();
            foreach (var device in devicelist)
            {
                Devices.Add(new ComboBoxItemViewModel(device.Title, device.Guid));
            }

            ComboBoxItemViewModel selectedDevice = null;

            foreach (var comboBoxItem in Devices)
            {
                if (comboBoxItem.Value == DeviceBinding.DeviceGuid)
                {
                    selectedDevice = comboBoxItem;
                    break;
                }
            }

            if (Devices.Count == 0)
            {
                Devices.Add(new ComboBoxItemViewModel("No device group", Guid.Empty));
            }
            if (selectedDevice == null)
            {
                selectedDevice = Devices[0];
                DeviceBinding.SetDeviceGuid(selectedDevice.Value);
            }

            DeviceNumberBox.ItemsSource  = Devices;
            DeviceNumberBox.SelectedItem = selectedDevice;
        }
예제 #2
0
 public OutputSubscription(DeviceBinding deviceBinding, Guid subscriptionStateGuid, DeviceSubscription outputDeviceSubscription)
 {
     DeviceBinding            = deviceBinding;
     SubscriptionStateGuid    = subscriptionStateGuid;
     DeviceSubscription       = outputDeviceSubscription;
     deviceBinding.OutputSink = WriteOutput;
 }
예제 #3
0
 private static bool deviceBindingMatchesNode(DeviceBinding deviceBinding, DeviceBindingNode deviceBindingNode)
 {
     return(deviceBindingNode.IsBinding &&
            deviceBindingNode.DeviceBindingInfo.KeyType == deviceBinding.KeyType &&
            deviceBindingNode.DeviceBindingInfo.KeySubValue == deviceBinding.KeySubValue &&
            deviceBindingNode.DeviceBindingInfo.KeyValue == deviceBinding.KeyValue);
 }
예제 #4
0
        private ObservableCollection <ContextMenuItem> BuildMenu(List <DeviceBindingNode> deviceBindingNodes)
        {
            var menuList = new ObservableCollection <ContextMenuItem>();

            if (deviceBindingNodes == null)
            {
                return(menuList);
            }
            foreach (var deviceBindingNode in deviceBindingNodes)
            {
                RelayCommand cmd = null;
                if (deviceBindingNode.IsBinding)
                {
                    if (Category != null && deviceBindingNode.DeviceBinding.DeviceBindingCategory != Category)
                    {
                        continue;
                    }
                    cmd = new RelayCommand(c =>
                    {
                        DeviceBinding.SetDeviceGuid(GetSelectedDevice().Guid);
                        DeviceBinding.SetKeyTypeValue(deviceBindingNode.DeviceBinding.KeyType, deviceBindingNode.DeviceBinding.KeyValue, deviceBindingNode.DeviceBinding.KeySubValue);
                    });
                }
                var menu = new ContextMenuItem(deviceBindingNode.Title, BuildMenu(deviceBindingNode.ChildrenNodes), cmd);
                if (deviceBindingNode.IsBinding || !deviceBindingNode.IsBinding && menu.Children.Count > 0)
                {
                    menuList.Add(menu);
                }
            }
            return(menuList);
        }
예제 #5
0
 private static void SetDeviceBindingValues(DeviceBinding deviceBinding, int value)
 {
     deviceBinding.DeviceGuid  = Guid.NewGuid();
     deviceBinding.KeyType     = value;
     deviceBinding.KeyValue    = value;
     deviceBinding.KeySubValue = value;
 }
예제 #6
0
 public string GetBindingName(DeviceBinding deviceBinding)
 {
     if (!deviceBinding.IsBound)
     {
         return("Not bound");
     }
     return(GetBindingName(deviceBinding, GetDeviceBindingMenu(deviceBinding.Profile.Context, deviceBinding.DeviceIoType)) ?? "Unknown input");
 }
예제 #7
0
 public string GetBindingName(DeviceBinding deviceBinding)
 {
     if (!deviceBinding.IsBound)
     {
         return("Not bound");
     }
     return(GetBindingName(deviceBinding, DeviceBindingMenu) ?? "Unknown input");
 }
예제 #8
0
 public InputSubscription(DeviceBinding deviceBinding, Profile profile, Guid subscriptionStateGuid)
 {
     DeviceBinding                 = deviceBinding;
     Profile                       = profile;
     SubscriptionStateGuid         = subscriptionStateGuid;
     DeviceBindingSubscriptionGuid = Guid.NewGuid();
     IsOverwritten                 = false;
     DeviceSubscription            = new DeviceSubscription(GetDevice(), profile);
 }
예제 #9
0
 public static BindingDescriptor GetBindingDescriptor(DeviceBinding deviceBinding)
 {
     return(new BindingDescriptor()
     {
         Type = (BindingType)deviceBinding.KeyType,
         Index = deviceBinding.KeyValue,
         SubIndex = deviceBinding.KeySubValue
     });
 }
예제 #10
0
 private void LoadBindingName()
 {
     if (DeviceBinding.IsBound)
     {
         BindButton.Content = DeviceBinding.BoundName();
     }
     else
     {
         BindButton.Content = "Click to Bind";
     }
 }
예제 #11
0
 private void DeviceNumberBox_OnSelected(object sender, RoutedEventArgs e)
 {
     if (!HasLoaded)
     {
         return;
     }
     if (DeviceNumberBox.SelectedItem == null)
     {
         return;
     }
     DeviceBinding.SetDeviceGuid(((ComboBoxItemViewModel)DeviceNumberBox.SelectedItem).Value);
     LoadContextMenu();
 }
예제 #12
0
 private void DeviceNumberBox_OnSelected(object sender, RoutedEventArgs e)
 {
     if (!HasLoaded)
     {
         return;
     }
     if (DeviceSelectionBox.SelectedItem == null)
     {
         return;
     }
     DeviceBinding.SetDeviceGuid(GetSelectedDevice().Guid);
     LoadContextMenu();
 }
예제 #13
0
        public void GetDeviceList()
        {
            var deviceBinding = new DeviceBinding(null, null, DeviceIoType.Input)
            {
                IsBound = true
            };

            Assert.That(_profile.GetDeviceList(deviceBinding), Is.Empty);
            var guid = _context.DeviceGroupsManager.AddDeviceGroup("Test joysticks", DeviceIoType.Input);

            _profile.SetDeviceGroup(deviceBinding.DeviceIoType, guid);
            Assert.That(_profile.GetDeviceList(deviceBinding), Is.Not.Null.And.Empty);
            _context.DeviceGroupsManager.GetDeviceGroup(DeviceIoType.Input, guid).Devices = DeviceFactory.CreateDeviceList("Dummy", "Provider", 1);
            Assert.That(_profile.GetDeviceList(deviceBinding), Is.Not.Empty);
        }
예제 #14
0
        private void InputChanged(ProviderDescriptor providerDescriptor, DeviceDescriptor deviceDescriptor, BindingReport bindingReport, int value)
        {
            if (!DeviceBinding.MapCategory(bindingReport.Category).Equals(_deviceBinding.DeviceBindingCategory))
            {
                return;
            }
            if (!IsInputValid(bindingReport.Category, value))
            {
                return;
            }

            var device = FindDevice(providerDescriptor, deviceDescriptor);

            _deviceBinding.SetDeviceGuid(device.Guid);
            _deviceBinding.SetKeyTypeValue((int)bindingReport.BindingDescriptor.Type, bindingReport.BindingDescriptor.Index, bindingReport.BindingDescriptor.SubIndex);
            EndBindMode();
        }
예제 #15
0
        private static List <DeviceBindingNode> BuildDeviceBindingMenu(List <DeviceReportNode> deviceNodes, DeviceIoType type)
        {
            var result = new List <DeviceBindingNode>();

            if (deviceNodes == null)
            {
                return(result);
            }

            foreach (var deviceNode in deviceNodes)
            {
                var groupNode = new DeviceBindingNode()
                {
                    Title         = deviceNode.Title,
                    ChildrenNodes = BuildDeviceBindingMenu(deviceNode.Nodes, type),
                };

                if (groupNode.ChildrenNodes == null)
                {
                    groupNode.ChildrenNodes = new List <DeviceBindingNode>();
                }


                foreach (var bindingInfo in deviceNode.Bindings)
                {
                    var bindingNode = new DeviceBindingNode()
                    {
                        Title             = bindingInfo.Title,
                        DeviceBindingInfo = new DeviceBindingInfo()
                        {
                            KeyType               = (int)bindingInfo.BindingDescriptor.Type,
                            KeyValue              = bindingInfo.BindingDescriptor.Index,
                            KeySubValue           = bindingInfo.BindingDescriptor.SubIndex,
                            DeviceBindingCategory = DeviceBinding.MapCategory(bindingInfo.Category),
                            Blockable             = bindingInfo.Blockable
                        }
                    };


                    groupNode.ChildrenNodes.Add(bindingNode);
                }
                result.Add(groupNode);
            }
            return(result.Count != 0 ? result : null);
        }
예제 #16
0
        private static List <DeviceBindingNode> GetDeviceBindingMenu(List <DeviceReportNode> deviceNodes, DeviceIoType type)
        {
            var result = new List <DeviceBindingNode>();

            if (deviceNodes == null)
            {
                return(result);
            }

            foreach (var deviceNode in deviceNodes)
            {
                var groupNode = new DeviceBindingNode()
                {
                    Title         = deviceNode.Title,
                    IsBinding     = false,
                    ChildrenNodes = GetDeviceBindingMenu(deviceNode.Nodes, type),
                };

                foreach (var bindingInfo in deviceNode.Bindings)
                {
                    var bindingNode = new DeviceBindingNode()
                    {
                        Title         = bindingInfo.Title,
                        IsBinding     = true,
                        DeviceBinding = new DeviceBinding(null, null, type)
                        {
                            IsBound               = false,
                            KeyType               = (int)bindingInfo.BindingDescriptor.Type,
                            KeyValue              = bindingInfo.BindingDescriptor.Index,
                            KeySubValue           = bindingInfo.BindingDescriptor.SubIndex,
                            DeviceBindingCategory = DeviceBinding.MapCategory(bindingInfo.Category)
                                                    // TODO Extract to class instead of using DeviceBinding?
                        }
                    };
                    if (groupNode.ChildrenNodes == null)
                    {
                        groupNode.ChildrenNodes = new List <DeviceBindingNode>();
                    }

                    groupNode.ChildrenNodes.Add(bindingNode);
                }
                result.Add(groupNode);
            }
            return(result.Count != 0 ? result : null);
        }
예제 #17
0
        private bool IsInputValid(BindingCategory bindingCategory, int value)
        {
            switch (DeviceBinding.MapCategory(bindingCategory))
            {
            case DeviceBindingCategory.Delta:
            case DeviceBindingCategory.Event:
                return(true);

            case DeviceBindingCategory.Momentary:
                return(value != 0);

            case DeviceBindingCategory.Range:
                return(Constants.AxisMaxValue * 0.4 < Math.Abs(value) &&
                       Constants.AxisMaxValue * 0.6 > Math.Abs(value));

            default:
                return(false);
            }
        }
예제 #18
0
 private void BindButton_OnClick(object sender, RoutedEventArgs e)
 {
     if (DeviceBinding.DeviceIoType.Equals(DeviceIoType.Input))
     {
         if (DeviceBinding.IsInBindMode)
         {
             return;
         }
         if (Category.HasValue)
         {
             DeviceBinding.DeviceBindingCategory = Category.Value;
         }
         DeviceBinding.EnterBindMode();
     }
     else
     {
         OpenContextMenu();
     }
 }
예제 #19
0
        private bool IsInputValid(BindingCategory bindingCategory, short value)
        {
            switch (DeviceBinding.MapCategory(bindingCategory))
            {
            case DeviceBindingCategory.Delta:
            case DeviceBindingCategory.Event:
                return(true);

            case DeviceBindingCategory.Momentary:
                return(value != 0);

            case DeviceBindingCategory.Range:
                var wideVal = Functions.WideAbs(value);
                return(Constants.AxisMaxValue * 0.4 < wideVal &&
                       Constants.AxisMaxValue * 0.6 > wideVal);

            default:
                return(false);
            }
        }
예제 #20
0
 private static string GetBindingName(DeviceBinding deviceBinding, List <DeviceBindingNode> deviceBindingNodes)
 {
     if (deviceBindingNodes == null)
     {
         return(null);
     }
     foreach (var deviceBindingNode in deviceBindingNodes)
     {
         if (deviceBindingMatchesNode(deviceBinding, deviceBindingNode))
         {
             return(deviceBindingNode.Title);
         }
         var name = GetBindingName(deviceBinding, deviceBindingNode.ChildrenNodes);
         if (name != null)
         {
             return(deviceBindingNode.Title + ", " + name);
         }
     }
     return(null);
 }
예제 #21
0
        public void GetDevice()
        {
            var guid       = _context.DeviceGroupsManager.AddDeviceGroup("Test joysticks", DeviceIoType.Input);
            var deviceList = DeviceFactory.CreateDeviceList("Dummy", "Provider", 1);

            _context.DeviceGroupsManager.GetDeviceGroup(DeviceIoType.Input, guid).Devices = deviceList;
            var deviceBinding = new DeviceBinding(null, null, DeviceIoType.Input)
            {
                IsBound    = true,
                DeviceGuid = deviceList[0].Guid
            };

            Assert.That(_profile.GetDevice(deviceBinding), Is.Null);

            Assert.That(guid, Is.Not.EqualTo(Guid.Empty));
            _profile.SetDeviceGroup(deviceBinding.DeviceIoType, guid);
            Assert.That(_context.IsNotSaved, Is.True);
            Assert.That(_profile.GetDevice(deviceBinding), Is.Not.Null);
            Assert.That(_profile.GetDevice(deviceBinding).Guid, Is.EqualTo(_profile.GetDeviceList(deviceBinding)[0].Guid));
        }
예제 #22
0
        public void BeginBindMode(DeviceBinding deviceBinding)
        {
            if (_deviceList.Count > 0)
            {
                EndBindMode();
            }
            _deviceBinding = deviceBinding;
            foreach (var device in deviceBinding.Profile.GetDeviceList(deviceBinding))
            {
                _context.IOController.SetDetectionMode(DetectionMode.Bind, GetProviderDescriptor(device), GetDeviceDescriptor(device), InputChanged);
                _deviceList.Add(device);
            }

            BindingTimer          = new DispatcherTimer();
            BindingTimer.Tick    += BindingTimerOnTick;
            BindingTimer.Interval = TimeSpan.FromMilliseconds(BindModeTick);
            BindModeProgress      = BindModeTime;
            BindingTimer.Start();
            bindmodeActive = true;
        }
예제 #23
0
        public InputSubscription(Mapping mapping, DeviceBinding deviceBinding, Profile profile, Guid subscriptionStateGuid)
        {
            DeviceBinding                 = deviceBinding;
            Profile                       = profile;
            SubscriptionStateGuid         = subscriptionStateGuid;
            DeviceBindingSubscriptionGuid = Guid.NewGuid();
            IsOverwritten                 = false;

            var deviceConfiguration = GetDeviceConfiguration();

            if (deviceConfiguration == null)
            {
                return;
            }

            var device = mapping.IsShadowMapping
                ? deviceConfiguration.ShadowDevices[mapping.ShadowDeviceNumber]
                : deviceConfiguration.Device;

            DeviceSubscription = new DeviceSubscription(device);
        }
예제 #24
0
 private void BindButton_OnClick(object sender, RoutedEventArgs e)
 {
     if (e is KeyboardEventArgs && !((KeyEventArgs)e).Key.Equals(Key.Space))
     {
         e.Handled = true;
         return;
     }
     if (DeviceBinding.DeviceIoType.Equals(DeviceIoType.Input))
     {
         if (DeviceBinding.IsInBindMode)
         {
             return;
         }
         if (Category.HasValue)
         {
             DeviceBinding.DeviceBindingCategory = Category.Value;
         }
         DeviceBinding.EnterBindMode();
     }
     else
     {
         OpenContextMenu();
     }
 }
예제 #25
0
        private ContextMenuItem CreateClearCommandMenuItem()
        {
            var clearCommand = new RelayCommand(c => { DeviceBinding.ClearBinding(); });

            return(new ContextMenuItem("Clear binding", null, clearCommand));
        }
예제 #26
0
파일: Profile.cs 프로젝트: poutine70/UCR
        public Device GetDevice(DeviceBinding deviceBinding)
        {
            var deviceList = GetDeviceList(deviceBinding);

            return(deviceList.FirstOrDefault(d => d.Guid == deviceBinding.DeviceGuid));
        }
예제 #27
0
파일: Profile.cs 프로젝트: poutine70/UCR
 public List <Device> GetDeviceList(DeviceBinding deviceBinding)
 {
     return(GetDeviceList(deviceBinding.DeviceIoType));
 }