Esempio n. 1
0
        /// <summary>
        /// An update occurred in Bind Mode.
        /// We are passed a <see cref="BindingUpdate"/>, which only contains Index, SubIndex etc...
        /// ... however, the front end will need a <see cref="BindingReport"/>, so it can display the new binding to the user (ie it needs the Title)
        /// <see cref="GetInputBindingReport"/> is expected to perform this translation
        /// </summary>
        /// <param name="update"></param>
        private void OnBindModeUpdate(BindingUpdate update)
        {
            var bindModeUpdate = new BindModeUpdate {
                Device = DeviceDescriptor, Binding = GetInputBindingReport(update), Value = (short)update.Value
            };

            if (BindModeUpdate != null)
            {
                //ThreadPool.QueueUserWorkItem(cb => BindModeUpdate(this, bindModeUpdate));
                // Disabled, as does not seem to work while SubReq's Callback property is dynamic
                // Switching it to Action<int> breaks loads of stuff in UCR, so for now, just keep using ThreadPool
                Task.Factory.StartNew(() => BindModeUpdate(this, bindModeUpdate));
            }
        }
Esempio n. 2
0
        public BindingUpdate[] Process(BindingUpdate update)
        {
            var ret      = new List <BindingUpdate>();
            var newAngle = update.Value;

            if (_currentValue == newAngle)
            {
                return(ret.ToArray());
            }
            _currentValue = newAngle;
            for (var i = 0; i < 4; i++)
            {
                var currentDirectionState = _directionStates[i];
                var newDirectionState     =
                    newAngle == -1 ? 0
                        : PovHelper.StateFromAngle(newAngle, i * 9000);

                if (newDirectionState == currentDirectionState)
                {
                    continue;
                }

                _directionStates[i] = newDirectionState;
                ret.Add(new BindingUpdate
                {
                    Value   = newDirectionState,
                    Binding = new BindingDescriptor
                    {
                        Type     = BindingType.POV,
                        Index    = update.Binding.Index,
                        SubIndex = i
                    }
                });
            }

            return(ret.ToArray());
        }
Esempio n. 3
0
 public BindingUpdate[] Process(BindingUpdate update)
 {
     return(new[] { update });
 }
Esempio n. 4
0
        public ManagedWrapper.Stroke ProcessUpdate(ManagedWrapper.Stroke stroke)
        {
            // Process Mouse Buttons
            if (stroke.mouse.state > 0)
            {
                var buttonsAndStates = HelperFunctions.StrokeToMouseButtonAndState(stroke);

                foreach (var btnState in buttonsAndStates)
                {
                    var bindingUpdate = new BindingUpdate
                    {
                        Binding = new BindingDescriptor()
                        {
                            Type = BindingType.Button, Index = btnState.Button
                        },
                        Value = btnState.State
                    };
                    if (_detectionMode == DetectionMode.Subscription)
                    {
                        var blockingRequestedByUi = _subHandler.FireCallbacks(bindingUpdate.Binding, (short)bindingUpdate.Value);
                        if (_blockingEnabled)
                        {
                            // Block enabled
                            if (blockingRequestedByUi)
                            {
                                // Blocking controlled by UI and requested by UI, OR blocking not controlled by UI
                                // Remove the event for this button from the stroke, leaving other button events intact
                                stroke.mouse.state -= btnState.Flag;
                                // If we are removing a mouse wheel event, then set rolling to 0 if no mouse wheel event left
                                if (btnState.Flag == 0x400 || btnState.Flag == 0x800)
                                {
                                    if ((stroke.mouse.state & 0x400) != 0x400 && (stroke.mouse.state & 0x800) != 0x800)
                                    {
                                        //Debug.WriteLine("UCR| Removing rolling flag from stroke");
                                        stroke.mouse.rolling = 0;
                                    }
                                }
                                //Debug.WriteLine($"UCR| Removing flag {btnState.Flag} from stoke, leaving state {stroke.mouse.state}");
                            }
                        }
                    }
                    else
                    {
                        _bindModeHandler?.Invoke(this, new BindModeUpdate
                        {
                            Device  = _deviceDescriptor,
                            Binding = _deviceLibrary.GetInputBindingReport(_deviceDescriptor, bindingUpdate.Binding),
                            Value   = (short)bindingUpdate.Value
                        });
                    }
                }
            }

            // Process Relative Mouse Move
            if ((stroke.mouse.flags & (ushort)ManagedWrapper.MouseFlag.MouseMoveRelative) == (ushort)ManagedWrapper.MouseFlag.MouseMoveRelative)
            {
                var bindingUpdates = HelperFunctions.StrokeToMouseMove(stroke);

                if (bindingUpdates.Count > 0)
                {
                    foreach (var bindingUpdate in bindingUpdates)
                    {
                        if (_detectionMode == DetectionMode.Subscription)
                        {
                            var blockingRequestedByUi = _subHandler.FireCallbacks(bindingUpdate.Binding, (short)bindingUpdate.Value);
                            if (_blockingEnabled)
                            {
                                if (blockingRequestedByUi)
                                {
                                    if (bindingUpdate.Binding.Index == 0)
                                    {
                                        stroke.mouse.x = 0;
                                    }
                                    else
                                    {
                                        stroke.mouse.y = 0;
                                    }
                                }
                            }
                        }
                        else
                        {
                            _bindModeHandler?.Invoke(this, new BindModeUpdate
                            {
                                Device  = _deviceDescriptor,
                                Binding = _deviceLibrary.GetInputBindingReport(_deviceDescriptor, bindingUpdate.Binding),
                                Value   = (short)bindingUpdate.Value
                            });
                        }
                    }
                }
            }

            // Forward on the stroke if required
            if (stroke.mouse.x != 0 || stroke.mouse.y != 0 || stroke.mouse.state != 0)
            {
                return(stroke);
            }

            return(default(ManagedWrapper.Stroke));
        }
Esempio n. 5
0
 public BindingUpdate[] Process(BindingUpdate update)
 {
     update.Value = (update.Value * 257) - 32768;
     return(new[] { update });
 }
Esempio n. 6
0
 public BindingUpdate[] Process(BindingUpdate update)
 {
     update.Value = update.Value == 128 ? 1 : 0;
     //update.Binding.Index -= (int)JoystickOffset.Buttons0;
     return(new[] { update });
 }
Esempio n. 7
0
 public BindingUpdate[] Process(BindingUpdate update)
 {
     update.Value = UnsignedToSigned(update.Value);
     return(new[] { update });
 }
Esempio n. 8
0
 /// <summary>
 /// Assists in the <see cref="BindingUpdate"/> to <see cref="BindingReport"/> conversion performed by <see cref="OnBindModeUpdate"/>
 /// </summary>
 /// <param name="bindingUpdate"></param>
 /// <returns></returns>
 protected abstract BindingReport GetInputBindingReport(BindingUpdate bindingUpdate);