Beispiel #1
0
 private void restoreButtonMap(ApplicationDataContainer container, HIDButtonMap buttonMap)
 {
     foreach (var entry in container.Values)
     {
         ApplicationDataCompositeValue value = entry.Value as ApplicationDataCompositeValue;
         HIDMapping mapping = HIDMappingExtensions.FromCompositeValue(value);
         buttonMap[(Button)(int.Parse(entry.Key.ToString()))] = mapping;
     }
 }
Beispiel #2
0
        internal static HIDMapping FromCompositeValue(ApplicationDataCompositeValue value)
        {
            HIDMapping mapping = new HIDMapping();

            mapping.DisplayName = value["DisplayName"].ToString();
            mapping.UsagePage   = ushort.Parse(value["UsagePage"].ToString());
            mapping.UsageId     = ushort.Parse(value["UsageId"].ToString());
            mapping.Sign        = short.Parse(value["Sign"].ToString());
            mapping.Direction   = (DPadDirection)(int.Parse(value["Direction"].ToString()));
            mapping.IsNumeric   = bool.Parse(value["IsNumeric"].ToString());
            return(mapping);
        }
Beispiel #3
0
        internal static ApplicationDataCompositeValue ToCompositeValue(this HIDMapping mapping)
        {
            ApplicationDataCompositeValue value = new ApplicationDataCompositeValue();

            value["DisplayName"] = mapping.DisplayName;
            value["UsagePage"]   = mapping.UsagePage;
            value["UsageId"]     = mapping.UsageId;
            value["Sign"]        = mapping.Sign;
            value["Direction"]   = (int)mapping.Direction;
            value["IsNumeric"]   = mapping.IsNumeric;
            return(value);
        }
Beispiel #4
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);
             }
         }
     }
 }
Beispiel #5
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;
        }