Example #1
0
        /// <summary>
        /// Resets a device to unfiltered
        /// </summary>
        /// <param name="device">The device you want reset</param>
        internal void Reset(InputDevice device)
        {
            IntPtr noiseFilterPtr = InputStateBuffers.s_NoiseFilterBuffer;

            if (noiseFilterPtr != IntPtr.Zero)
            {
                BitmaskHelpers.Whitelist(noiseFilterPtr, device);
            }
        }
Example #2
0
            /// <summary>
            /// Called when the NoiseFilter gets applied to a device, marks out any controls that can be wholly bitmasked.
            /// </summary>
            /// <param name="noiseFilterBuffer">The Noisefilter buffer for doing whole control filtering.</param>
            /// <param name="device">The device you want to apply filtering to.</param>
            public void Apply(IntPtr noiseFilterBuffer, InputDevice device)
            {
                if (controlIndex >= device.allControls.Count)
                {
                    throw new IndexOutOfRangeException("NoiseFilter has array index beyond total size of device's controls");
                }

                InputControl control = device.allControls[controlIndex];

                BitmaskHelpers.Blacklist(noiseFilterBuffer, control);
            }
Example #3
0
        /// <summary>
        /// Called when the NoiseFilter gets applied to a device, calls down to any individual FilteredElements that need to do any work.
        /// </summary>
        /// <param name="device">The device you want to apply filtering to.</param>
        internal void Apply(InputDevice device)
        {
            if (device == null)
            {
                throw new ArgumentException("No device supplied to apply NoiseFilter to.", "device");
            }

            IntPtr noiseFilterPtr = InputStateBuffers.s_NoiseFilterBuffer;

            if (noiseFilterPtr != IntPtr.Zero)
            {
                BitmaskHelpers.Whitelist(noiseFilterPtr, device);

                for (int i = 0; i < elements.Length; i++)
                {
                    elements[i].Apply(noiseFilterPtr, device);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Checks an Input Event for any significant changes that would be considered user activity.
        /// </summary>
        /// <param name="inputEvent">The input event being checked for changes</param>
        /// <param name="device">The input device being checked against </param>
        /// <param name="offset">The offset into the device that the event is placed</param>
        /// <param name="sizeInbytes">The size of the event in bytes</param>
        /// <returns>True if any changes exist in the event once the device has been filtered through for noise and non-significant changes.  False otherwise.</returns>
        public unsafe bool HasValidData(InputDevice device, InputEventPtr inputEvent, uint offset, uint sizeInbytes)
        {
            if (elements.Length == 0)
            {
                return(true);
            }

            if ((offset + sizeInbytes) * 8 > device.stateBlock.sizeInBits)
            {
                return(false);
            }

            bool result = false;

            IntPtr noiseFilterPtr = InputStateBuffers.s_NoiseFilterBuffer;

            if (noiseFilterPtr != IntPtr.Zero)
            {
                IntPtr ptrToEventState = IntPtr.Zero;
                if (inputEvent.IsA <StateEvent>())
                {
                    StateEvent *stateEvent = StateEvent.From(inputEvent);
                    ptrToEventState = stateEvent->state;
                }
                else if (inputEvent.IsA <DeltaStateEvent>())
                {
                    DeltaStateEvent *stateEvent = DeltaStateEvent.From(inputEvent);
                    ptrToEventState = stateEvent->deltaState;
                }

                if (ptrToEventState != IntPtr.Zero)
                {
                    result = BitmaskHelpers.CheckForMaskedValues(ptrToEventState, noiseFilterPtr, offset, sizeInbytes * 8);
                    for (int i = 0; i < elements.Length && !result; i++)
                    {
                        result = elements[i].HasValidData(inputEvent, device);
                    }
                }
            }

            return(result);
        }