public override void AddStandardControls(ControlSetup setup)
 {
     // If we have no device descriptor we just map to all available controls, since we can't be sure what we are getting.
     if (m_DeviceDescriptor == null)
     {
         HIDHelpers.AddDefaultControls(setup);
     }
     else
     {
         for (int i = 0; i < m_DeviceDescriptor.elements.Length; i++)
         {
             HIDHelpers.AddHIDControl(setup, m_DeviceDescriptor.elements[i]);
         }
     }
 }
Beispiel #2
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;
            }
        }
        bool IsDeviceValidAsGenericHID(HIDDescriptor descriptor)
        {
            bool isValid = false;

            // The Descriptor needs at least one known element
            if (descriptor.elements != null && descriptor.elements.Length != 0)
            {
                for (int i = 0; i < descriptor.elements.Length; i++)
                {
                    if (HIDHelpers.IsDefinedHIDUsage(descriptor.elements[i]))
                    {
                        isValid = true;
                        break;
                    }
                }
            }
            return(isValid);
        }
Beispiel #4
0
 public static void WriteOutputHeader(BinaryWriter writer, int usageId, int usagePageId, int length, int sizeInBytes)
 {
     writer.Write(HIDHelpers.GetControlId(usagePageId, usageId));
     writer.Write(length);
     writer.Write(sizeInBytes);
 }