示例#1
0
            public Vector3?GetPosition(HidInputReport report)
            {
                Vector3 result = new Vector3();

                if (_X != null &&
                    _Y != null &&
                    _Z != null &&
                    _usage != 0x0000)
                {
                    result.X = report.GetNumericControlByDescription(_X).Value;
                    result.Y = report.GetNumericControlByDescription(_Y).Value;
                    result.Z = report.GetNumericControlByDescription(_Z).Value;
                    return(result);
                }
                return(null);
            }
        /// <summary>
        /// Parses the rotation from the report.
        /// </summary>
        /// <param name="report">A <see cref="HidInputReport"/> object used on the parsing.</param>
        /// <returns>The parsed <see cref="GazeHidPosition"/> from the report.</returns>
        public GazeHidPosition GetRotation(HidInputReport report)
        {
            GazeHidPosition result = null;

            if (_x != null &&
                _y != null &&
                _z != null &&
                _usage != 0x0000)
            {
                var descX = report.GetNumericControlByDescription(_x);
                var descY = report.GetNumericControlByDescription(_y);
                var descZ = report.GetNumericControlByDescription(_z);

                var controlDescX = descX.ControlDescription;
                var controlDescY = descY.ControlDescription;
                var controlDescZ = descZ.ControlDescription;

                if ((controlDescX.LogicalMaximum < descX.ScaledValue || controlDescX.LogicalMinimum > descX.ScaledValue) ||
                    (controlDescY.LogicalMaximum < descY.ScaledValue || controlDescY.LogicalMinimum > descY.ScaledValue) ||
                    (controlDescZ.LogicalMaximum < descZ.ScaledValue || controlDescZ.LogicalMinimum > descZ.ScaledValue))
                {
                    // One of the values is outside of the valid range.
                }
                else
                {
                    result = new GazeHidPosition
                    {
                        X = descX.ScaledValue,
                        Y = descY.ScaledValue,
                        Z = descZ.ScaledValue
                    };
                }
            }

            return(result);
        }
示例#3
0
            public Vector3?GetRotation(HidInputReport report)
            {
                Vector3?result = null;

                if (_X != null &&
                    _Y != null &&
                    _Z != null &&
                    _usage != 0x0000)
                {
                    var descX = report.GetNumericControlByDescription(_X);
                    var descY = report.GetNumericControlByDescription(_Y);
                    var descZ = report.GetNumericControlByDescription(_Z);

                    var controlDescX = descX.ControlDescription;
                    var controlDescY = descX.ControlDescription;
                    var controlDescZ = descX.ControlDescription;

                    if ((controlDescX.LogicalMaximum < descX.Value || controlDescX.LogicalMinimum > descX.Value) ||
                        (controlDescY.LogicalMaximum < descY.Value || controlDescY.LogicalMinimum > descY.Value) ||
                        (controlDescZ.LogicalMaximum < descZ.Value || controlDescZ.LogicalMinimum > descZ.Value))
                    {
                        // One of the values is outside of the valid range.
                    }
                    else
                    {
                        result = new Vector3
                        {
                            X = descX.Value,
                            Y = descY.Value,
                            Z = descZ.Value
                        };
                    }
                }

                return(result);
            }
示例#4
0
        private void processReport(HidInputReport report)
        {
            if (this.lastReport != null)
            {
                if (this.SetupMode)
                {
                    foreach (var boolControl in report.ActivatedBooleanControls)
                    {
                        var lastControl = this.lastReport.GetBooleanControl(boolControl.UsagePage, boolControl.UsageId);
                        if (boolControl.IsActive && !lastControl.IsActive)
                        {
                            HIDMapping mapping = new HIDMapping()
                            {
                                DisplayName = String.Format(this.resources.GetString("hidButtonDescription"), boolControl.Id),
                                UsagePage   = boolControl.UsagePage,
                                UsageId     = boolControl.UsageId,
                                IsNumeric   = false
                            };

                            this.ControlChanged(mapping);
                        }
                    }

                    foreach (var numControlDesc in this.numControlDescs)
                    {
                        var numControl     = report.GetNumericControlByDescription(numControlDesc);
                        var lastNumControl = this.lastReport.GetNumericControlByDescription(numControlDesc);
                        if (numControl != null && lastNumControl != null && numControl.Value != lastNumControl.Value)
                        {
                            if (CheckDeadzone(numControlDesc, numControl) &&
                                !CheckDeadzone(lastNumControl.ControlDescription, lastNumControl))
                            {
                                ushort center   = NumericCenters[numControl.UsagePage];
                                short  axisSign = (short)Math.Sign((short)numControl.Value - (short)center);
                                String sign     = string.Empty;
                                if (center != 0)
                                {
                                    sign = axisSign < 0 ? "-" : "+";
                                }
                                String displayName = String.Format(this.axisString, sign, numControl.Id);

                                DPadDirection direction = default(DPadDirection);
                                if (numControlDesc.UsagePage == 0x01 && numControlDesc.UsageId == 0x39)
                                {
                                    switch (numControl.Value)
                                    {
                                    case 0:
                                        direction   = DPadDirection.Up;
                                        displayName = this.hidDPadUp;
                                        break;

                                    case 2:
                                        direction   = DPadDirection.Right;
                                        displayName = this.hidDPadRight;
                                        break;

                                    case 4:
                                        direction   = DPadDirection.Down;
                                        displayName = this.hidDPadDown;
                                        break;

                                    case 6:
                                        direction   = DPadDirection.Left;
                                        displayName = this.hidDPadLeft;
                                        break;
                                    }
                                }
                                HIDMapping mapping = new HIDMapping()
                                {
                                    DisplayName = displayName,
                                    UsagePage   = numControl.UsagePage,
                                    UsageId     = numControl.UsageId,
                                    Sign        = axisSign,
                                    Direction   = direction,
                                    IsNumeric   = true
                                };

                                this.ControlChanged(mapping);
                            }
                        }
                    }
                }
                else
                {
                    //ButtonStates newState = new ButtonStates();
                    //ProcessInputForMap(report, this.mapping, ref newState);
                    //ProcessInputForMap(report, this.mappingAlternative, ref newState);
                    //this.state.buttons = newState;
                }
            }
            this.lastReport = report;
        }