Example #1
0
        public static bool IsDefinedHIDUsage(HIDElementDescriptor hidElement)
        {
            bool isKnown = false;

            if (PageId.IsDefined(typeof(PageId), hidElement.usagePageID))
            {
                switch ((PageId)hidElement.usagePageID)
                {
                case PageId.GenericDesktopPage:
                {
                    isKnown = GenericDesktopUsage.IsDefined(typeof(GenericDesktopUsage), hidElement.usageID);
                }
                break;

                case PageId.SimulationPage:
                {
                    isKnown = SimulationUsage.IsDefined(typeof(SimulationUsage), hidElement.usageID);
                }
                break;

                case PageId.ButtonPage:
                {
                    isKnown = hidElement.usageID > 0 && hidElement.usageID <= kMaxButtons;
                }
                break;
                }
            }
            return(isKnown);
        }
Example #2
0
        public static void AddHIDControl(ControlSetup controlSetup, HIDElementDescriptor hidElement)
        {
            switch (hidElement.reportType)
            {
            case "Input":
            {
                AddInputControl(controlSetup, hidElement);
            }
            break;

            case "Output":
            case "Feature":
                // Once we are ready to support these, control creation should be implemented here
                break;
            }
        }
Example #3
0
        static void AddInputControl(ControlSetup controlSetup, HIDElementDescriptor hidElement)
        {
            int    usageId     = hidElement.usageID;
            int    usagePageId = hidElement.usagePageID;
            string usageName   = HIDHelpers.GetUsageName(usagePageId, usageId);

            switch (hidElement.type)
            {
            case "Button":
            {
                SupportedControl buttonControl = SupportedControl.Get <ButtonControl>(usageName);
                controlSetup.AddControl(buttonControl);
                controlSetup.Mapping(hidElement.id, buttonControl);
            }
            break;

            case "Axis":
            case "Misc":     // OSX has a tendency to label axes as Misc from native
            {
                if (usageId == (int)GenericDesktopUsage.HatSwitch && usagePageId == (int)PageId.GenericDesktopPage)
                {
                    SupportedControl upControl    = SupportedControl.Get <ButtonControl>(usageName + " Up");
                    SupportedControl rightControl = SupportedControl.Get <ButtonControl>(usageName + " Right");
                    SupportedControl downControl  = SupportedControl.Get <ButtonControl>(usageName + " Down");
                    SupportedControl leftControl  = SupportedControl.Get <ButtonControl>(usageName + " Left");
                    controlSetup.AddControl(upControl);
                    controlSetup.AddControl(downControl);
                    controlSetup.AddControl(leftControl);
                    controlSetup.AddControl(rightControl);

                    int startingIndex = hidElement.logicalMin;
                    controlSetup.HatMapping(hidElement.id, leftControl, rightControl, downControl, upControl, startingIndex);
                }
                else
                {
                    SupportedControl axisControl = SupportedControl.Get <AxisControl>(usageName);
                    controlSetup.AddControl(axisControl);
                    controlSetup.Mapping(hidElement.id, axisControl);
                }
            }
            break;

            default:
                break;
            }
        }