Ejemplo n.º 1
0
 private void ProcessInputForMap(HidInputReport report, HIDButtonMap buttonMap, ref ButtonStates newState)
 {
     foreach (var mappingItem in buttonMap)
     {
         HIDMapping mapping = mappingItem.Value;
         if (mapping.IsNumeric)
         {
             HidNumericControl control = report.GetNumericControl(mapping.UsagePage, mapping.UsageId);
             ushort            value   = (ushort)control.Value;
             if (!this.CheckDeadzone(control.ControlDescription, control))
             {
                 continue;
             }
             if (mapping.UsagePage == 0x01 && mapping.UsageId == 0x39)
             {
                 // dpad
                 if ((mapping.Direction == DPadDirection.Down && value >= 3 && value <= 5) ||
                     (mapping.Direction == DPadDirection.Left && value >= 5 && value <= 7) ||
                     (mapping.Direction == DPadDirection.Up && (value == 7 || value == 0 || value == 1)) ||
                     (mapping.Direction == DPadDirection.Right && value >= 1 && value <= 3)
                     )
                 {
                     this.setButtonState(mappingItem.Key, ref newState);
                 }
             }
             else
             {
                 // axis
                 ushort center = NumericCenters[mapping.UsagePage];
                 if ((value < center && mapping.Sign < 0) ||
                     (value > center && mapping.Sign > 0))
                 {
                     this.setButtonState(mappingItem.Key, ref newState);
                 }
             }
         }
         else
         {
             HidBooleanControl control = report.GetBooleanControl(mapping.UsagePage, mapping.UsageId);
             if (control.IsActive)
             {
                 this.setButtonState(mappingItem.Key, ref newState);
             }
         }
     }
 }
        public T GetDataFromHidInputReport(HidInputReport HidReport)
        {
            var outputData = new T();

            foreach (var data in DataMap)
            {
                PropertyInfo prop = data.Property;

                if (prop.PropertyType == typeof(bool))
                {
                    prop.SetValue(outputData, HidReport.GetBooleanControl(data.UsagePage, data.UsageId).IsActive);
                }
                else if (prop.PropertyType == typeof(float))
                {
                    prop.SetValue(outputData, HidReport.GetNumericControl(data.UsagePage, data.UsageId).ScaledValue);
                }
            }

            return(outputData);
        }