예제 #1
0
 public static void Mapping(this ControlSetup setup, int sourceIndex, SupportedControl control, Range fromRange, Range toRange)
 {
     setup.mappings[sourceIndex] = new ControlMapping(
         setup.GetControl(control).index,
         fromRange,
         toRange);
 }
예제 #2
0
        public override void AddStandardControls(ControlSetup setup)
        {
            position  = (Vector3Control)setup.AddControl(CommonControls.Position3d);
            positionX = (AxisControl)setup.AddControl(CommonControls.PositionX);
            positionY = (AxisControl)setup.AddControl(CommonControls.PositionY);
            positionZ = (AxisControl)setup.AddControl(CommonControls.PositionZ);

            delta  = (Vector3Control)setup.AddControl(CommonControls.Delta3d);
            deltaX = (AxisControl)setup.AddControl(CommonControls.DeltaX);
            deltaY = (AxisControl)setup.AddControl(CommonControls.DeltaY);
            deltaZ = (AxisControl)setup.AddControl(CommonControls.DeltaZ);

            pressure = (AxisControl)setup.AddControl(CommonControls.Pressure);
            twist    = (AxisControl)setup.AddControl(CommonControls.Twist);

            tilt  = (Vector2Control)setup.AddControl(CommonControls.Tilt2d);
            tiltX = (AxisControl)setup.AddControl(CommonControls.TiltX);
            tiltY = (AxisControl)setup.AddControl(CommonControls.TiltY);

            radius  = (Vector3Control)setup.AddControl(CommonControls.Radius3d);
            radiusX = (AxisControl)setup.AddControl(CommonControls.RadiusX);
            radiusY = (AxisControl)setup.AddControl(CommonControls.RadiusY);
            radiusZ = (AxisControl)setup.AddControl(CommonControls.RadiusZ);

            // For these, subclasses or profiles should assign better names.
            primaryAction   = (ButtonControl)setup.AddControl(CommonControls.Action1);
            secondaryAction = (ButtonControl)setup.AddControl(CommonControls.Action2);

            doubleClick = (EventControl)setup.AddControl(CommonControls.DoubleClick);
        }
예제 #3
0
        public static void AddDefaultControls(ControlSetup controlSetup)
        {
            System.Array usagesArray = GenericDesktopUsage.GetValues(typeof(GenericDesktopUsage));
            for (int i = 0; i < usagesArray.Length; i++)
            {
                GenericDesktopUsage usageId = (GenericDesktopUsage)usagesArray.GetValue(i);
                string usageType            = GetGenericDesktopUsageType(usageId);
                int    controlId            = GetControlId((int)PageId.GenericDesktopPage, (int)usageId);
                string usageName            = GetUsageName((int)PageId.GenericDesktopPage, (int)usageId);
                AddHIDControl(controlSetup, new HIDElementDescriptor(controlId, usageName, usageType, (int)usageId, (int)PageId.GenericDesktopPage));
            }

            usagesArray = SimulationUsage.GetValues(typeof(SimulationUsage));
            for (int i = 0; i < usagesArray.Length; i++)
            {
                SimulationUsage usageId   = (SimulationUsage)usagesArray.GetValue(i);
                string          usageType = GetSimulationUsageType(usageId);
                int             controlId = GetControlId((int)PageId.SimulationPage, (int)usageId);
                string          usageName = GetUsageName((int)PageId.SimulationPage, (int)usageId);
                AddHIDControl(controlSetup, new HIDElementDescriptor(controlId, usageName, usageType, (int)usageId, (int)PageId.SimulationPage));
            }

            // Usages are 1 based
            for (int i = 1; i <= kMaxButtons; i++)
            {
                string usageType = "Button";
                int    controlId = GetControlId((int)PageId.ButtonPage, i);
                string usageName = GetUsageName((int)PageId.ButtonPage, i);
                AddHIDControl(controlSetup, new HIDElementDescriptor(controlId, usageName, usageType, i, (int)PageId.ButtonPage));
            }
        }
예제 #4
0
        public override void AddStandardControls(ControlSetup setup)
        {
            base.AddStandardControls(setup);

            for (var i = 0; i < kMaxConcurrentTouches; ++i)
            {
                var controls = new TouchControls();
                m_TouchControls.Add(controls);

                var prefix = "Touch " + i;
                controls.isDown    = (ButtonControl)setup.AddControl(SupportedControl.Get <ButtonControl>(prefix));
                controls.fingerId  = (DiscreteStatesControl)setup.AddControl(SupportedControl.Get <DiscreteStatesControl>(prefix + " ID"));
                controls.position  = (Vector2Control)setup.AddControl(SupportedControl.Get <Vector2Control>(prefix + " Position"));
                controls.positionX = (AxisControl)setup.AddControl(SupportedControl.Get <AxisControl>(prefix + " Position X"));
                controls.positionY = (AxisControl)setup.AddControl(SupportedControl.Get <AxisControl>(prefix + " Position Y"));
                controls.delta     = (Vector2Control)setup.AddControl(SupportedControl.Get <Vector2Control>(prefix + " Delta"));
                controls.deltaX    = (DeltaAxisControl)setup.AddControl(SupportedControl.Get <DeltaAxisControl>(prefix + " Delta X"));
                controls.deltaY    = (DeltaAxisControl)setup.AddControl(SupportedControl.Get <DeltaAxisControl>(prefix + " Delta Y"));
                controls.radius    = (Vector2Control)setup.AddControl(SupportedControl.Get <Vector2Control>(prefix + " Radius"));
                controls.radiusX   = (AxisControl)setup.AddControl(SupportedControl.Get <AxisControl>(prefix + " Radius X"));
                controls.radiusY   = (AxisControl)setup.AddControl(SupportedControl.Get <AxisControl>(prefix + " Radius Y"));
                controls.pressure  = (AxisControl)setup.AddControl(SupportedControl.Get <AxisControl>(prefix + " Pressure"));
            }

            setup.GetControl(CommonControls.DoubleClick).name = "Double Tap";
            setup.GetControl(CommonControls.Action1).name     = "One Finger";
            setup.GetControl(CommonControls.Action2).name     = "Two Fingers";
        }
예제 #5
0
        public override void AddStandardControls(ControlSetup setup)
        {
            base.AddStandardControls(setup);

            setup.GetControl(CommonControls.Pose).name = "IMU Pose";

            devicePosition = (Vector3Control)setup.AddControl(SupportedControl.Get <Vector3Control>("Device Position"));
            deviceRotation = (QuaternionControl)setup.AddControl(SupportedControl.Get <QuaternionControl>("Device Rotation"));
            devicePose     = (PoseControl)setup.AddControl(SupportedControl.Get <PoseControl>("Device Pose"));

            displayPosition = (Vector3Control)setup.AddControl(SupportedControl.Get <Vector3Control>("Display Position"));
            displayRotation = (QuaternionControl)setup.AddControl(SupportedControl.Get <QuaternionControl>("Display Rotation"));
            displayPose     = (PoseControl)setup.AddControl(SupportedControl.Get <PoseControl>("Display Pose"));

            colorCameraPosition = (Vector3Control)setup.AddControl(SupportedControl.Get <Vector3Control>("Color Camera Position"));
            colorCameraRotation = (QuaternionControl)setup.AddControl(SupportedControl.Get <QuaternionControl>("Color Camera Rotation"));
            colorCameraPose     = (PoseControl)setup.AddControl(SupportedControl.Get <PoseControl>("Color Camera Pose"));

            depthCameraPosition = (Vector3Control)setup.AddControl(SupportedControl.Get <Vector3Control>("Depth Camera Position"));
            depthCameraRotation = (QuaternionControl)setup.AddControl(SupportedControl.Get <QuaternionControl>("Depth Camera Rotation"));
            depthCameraPose     = (PoseControl)setup.AddControl(SupportedControl.Get <PoseControl>("Depth Camera Pose"));

            fisheyeCameraPosition = (Vector3Control)setup.AddControl(SupportedControl.Get <Vector3Control>("Fisheye Camera Position"));
            fisheyeCameraRotation = (QuaternionControl)setup.AddControl(SupportedControl.Get <QuaternionControl>("Fisheye Camera Rotation"));
            fisheyeCameraPose     = (PoseControl)setup.AddControl(SupportedControl.Get <PoseControl>("Fisheye Camera Pose"));
        }
예제 #6
0
        public GenericHID(HIDDescriptor deviceDescriptor)
        {
            m_DeviceDescriptor = deviceDescriptor;
            ControlSetup defaultSetup = new ControlSetup(this);

            m_Mappings = defaultSetup.mappings;
        }
        public override void AddStandardControls(ControlSetup setup)
        {
            base.AddStandardControls(setup);

            velocity        = (Vector3Control)setup.AddControl(CommonControls.Velocity3d);
            angularVelocity = (Vector3Control)setup.AddControl(CommonControls.AngularVelocity3d);

            trigger = (ButtonControl)setup.AddControl(CommonControls.Trigger);
            grip    = (ButtonControl)setup.AddControl(CommonControls.Squeeze);

            triggerTouch = (ButtonControl)setup.AddControl(CommonControls.TriggerTouch);

            trackpadPress = (ButtonControl)setup.AddControl(CommonControls.LeftStickButton);
            trackpadTouch = (ButtonControl)setup.AddControl(CommonControls.LeftStickTouch);
            trackpadX     = (AxisControl)setup.AddControl(CommonControls.LeftStickX);
            trackpadY     = (AxisControl)setup.AddControl(CommonControls.LeftStickY);
            trackpadLeft  = (ButtonControl)setup.AddControl(CommonControls.LeftStickLeft);
            trackpadRight = (ButtonControl)setup.AddControl(CommonControls.LeftStickRight);
            trackpadUp    = (ButtonControl)setup.AddControl(CommonControls.LeftStickUp);
            trackpadDown  = (ButtonControl)setup.AddControl(CommonControls.LeftStickDown);
            trackpad      = (Vector2Control)setup.AddControl(CommonControls.LeftStick);

            // haptics rumble output axis
            rumble = (AxisOutput)setup.AddControl(CommonControls.Vibration);

            // Rename the common controls to their OpenVR equivalents
            action1.name       = "Menu";
            grip.name          = "Grip";
            trackpadPress.name = "Trackpad Press";
            trackpadTouch.name = "Trackpad Touch";
            trackpadX.name     = "Trackpad X";
            trackpadY.name     = "Trackpad Y";
            trackpadLeft.name  = "Trackpad Left";
            trackpadRight.name = "Trackpad Right";
            trackpadUp.name    = "Trackpad Up";
            trackpadDown.name  = "Trackpad Down";
            trackpad.name      = "Trackpad";

            setup.Mapping(k_MaxNumAxes + 0, action1.index);
            setup.Mapping(k_MaxNumAxes + 2, action1.index);

            setup.Mapping(k_MaxNumAxes + 8, trackpadPress.index);
            setup.Mapping(k_MaxNumAxes + 9, trackpadPress.index);
            setup.Mapping(10, grip.index);
            setup.Mapping(11, grip.index);

            setup.Mapping(0, trackpadX.index);
            setup.Mapping(1, trackpadY.index);
            setup.Mapping(3, trackpadX.index);
            setup.Mapping(4, trackpadY.index);

            setup.Mapping(k_MaxNumAxes + 16, trackpadTouch.index);
            setup.Mapping(k_MaxNumAxes + 17, trackpadTouch.index);

            setup.Mapping(8, trigger.index);
            setup.Mapping(9, trigger.index);
            setup.Mapping(k_MaxNumAxes + 14, triggerTouch.index);
            setup.Mapping(k_MaxNumAxes + 15, triggerTouch.index);
        }
예제 #8
0
 public void SetControls(ControlSetup setup)
 {
     SetControls(setup.controls);
     m_SupportedControlToControlIndex = setup.supportedControlIndices;
     m_SortedCachedUsedControlHashes  = new int[m_SupportedControlToControlIndex.Keys.Count];
     m_SupportedControlToControlIndex.Keys.CopyTo(m_SortedCachedUsedControlHashes, 0);
     Array.Sort(m_SortedCachedUsedControlHashes);
 }
예제 #9
0
 public static void HatMapping(this ControlSetup setup, int sourceIndex, SupportedControl left, SupportedControl right, SupportedControl down, SupportedControl up, int startingIndex = 0)
 {
     setup.mappings[sourceIndex] = new ControlHatMapping(
         setup.GetControl(left).index,
         setup.GetControl(right).index,
         setup.GetControl(down).index,
         setup.GetControl(up).index,
         startingIndex);
 }
예제 #10
0
        public override void AddStandardControls(ControlSetup setup)
        {
            base.AddStandardControls(setup);

            barrelButton = (ButtonControl)setup.AddControl(CommonControls.Action3);

            setup.GetControl(CommonControls.Action1).name = "Tip";
            setup.GetControl(CommonControls.Action2).name = "Eraser";
            setup.GetControl(CommonControls.Action3).name = "Barrel Button";
        }
예제 #11
0
        public override void AddStandardControls(ControlSetup setup)
        {
            int controlCount = EnumHelpers.GetValueCount <KeyCode>();

            for (var i = 0; i < controlCount; ++i)
            {
                setup.AddControl(SupportedControl.Get <ButtonControl>(((KeyCode)i).ToString()));
            }

            // Make sure any additional controls come *after* the keys as we map directly
            // from KeyCode indices to control indices.
        }
예제 #12
0
        public List<InputControl> BuildControlsList()
        {
            ControlSetup controlsSetup = new ControlSetup();
            for (int i = 0; i < actions.Count; i++)
            {
                var action = actions[i];
// This line is kept with 71 spaces.
                SupportedControl supportedControl = (SupportedControl)(typeof(SupportedControl)
                                                                       .GetMethod("Get")
                                                                       .MakeGenericMethod(actions[i].controlType)
                                                                       .Invoke(null, new object[] { actions[i].name }));
                action.controlIndex = controlsSetup.AddControl(supportedControl).index;
            }
            return controlsSetup.controls;
        }
예제 #13
0
 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]);
         }
     }
 }
예제 #14
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;
            }
        }
예제 #15
0
        ////REVIEW: It's odd that this method modifies both the state of ControlSetup and the state of the device.
        ////        Guess it should have at least a more precise name.
        public override void AddStandardControls(ControlSetup setup)
        {
            leftStickLeft   = (ButtonControl)setup.AddControl(CommonControls.LeftStickLeft);
            leftStickRight  = (ButtonControl)setup.AddControl(CommonControls.LeftStickRight);
            leftStickDown   = (ButtonControl)setup.AddControl(CommonControls.LeftStickDown);
            leftStickUp     = (ButtonControl)setup.AddControl(CommonControls.LeftStickUp);
            leftStickX      = (AxisControl)setup.AddControl(CommonControls.LeftStickX);
            leftStickY      = (AxisControl)setup.AddControl(CommonControls.LeftStickY);
            leftStick       = (Vector2Control)setup.AddControl(CommonControls.LeftStick);
            leftStickButton = (ButtonControl)setup.AddControl(CommonControls.LeftStickButton);

            rightStickLeft   = (ButtonControl)setup.AddControl(CommonControls.RightStickLeft);
            rightStickRight  = (ButtonControl)setup.AddControl(CommonControls.RightStickRight);
            rightStickDown   = (ButtonControl)setup.AddControl(CommonControls.RightStickDown);
            rightStickUp     = (ButtonControl)setup.AddControl(CommonControls.RightStickUp);
            rightStickX      = (AxisControl)setup.AddControl(CommonControls.RightStickX);
            rightStickY      = (AxisControl)setup.AddControl(CommonControls.RightStickY);
            rightStick       = (Vector2Control)setup.AddControl(CommonControls.RightStick);
            rightStickButton = (ButtonControl)setup.AddControl(CommonControls.RightStickButton);

            dPadLeft  = (ButtonControl)setup.AddControl(CommonControls.DPadLeft);
            dPadRight = (ButtonControl)setup.AddControl(CommonControls.DPadRight);
            dPadDown  = (ButtonControl)setup.AddControl(CommonControls.DPadDown);
            dPadUp    = (ButtonControl)setup.AddControl(CommonControls.DPadUp);
            dPadX     = (AxisControl)setup.AddControl(CommonControls.DPadX);
            dPadY     = (AxisControl)setup.AddControl(CommonControls.DPadY);
            dPad      = (Vector2Control)setup.AddControl(CommonControls.DPad);

            action1 = (ButtonControl)setup.AddControl(CommonControls.Action1);
            action2 = (ButtonControl)setup.AddControl(CommonControls.Action2);
            action3 = (ButtonControl)setup.AddControl(CommonControls.Action3);
            action4 = (ButtonControl)setup.AddControl(CommonControls.Action4);

            leftTrigger  = (ButtonControl)setup.AddControl(CommonControls.LeftTrigger);
            rightTrigger = (ButtonControl)setup.AddControl(CommonControls.RightTrigger);

            leftBumper  = (ButtonControl)setup.AddControl(CommonControls.LeftBumper);
            rightBumper = (ButtonControl)setup.AddControl(CommonControls.RightBumper);

            leftVibration = (AxisOutput)setup.AddControl(
                SupportedControl.Get <AxisOutput>("Left Vibration"),
                new AxisOutput("Left Vibration"));
            rightVibration = (AxisOutput)setup.AddControl(
                SupportedControl.Get <AxisOutput>("Right Vibration"),
                new AxisOutput("Right Vibration"));
        }
예제 #16
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;
            }
        }
예제 #17
0
        public override void AddStandardControls(ControlSetup setup)
        {
            base.AddStandardControls(setup);

            middleButton = (ButtonControl)setup.AddControl(CommonControls.Action3);

            scrollWheel  = (Vector2Control)setup.AddControl(CommonControls.ScrollWheel2d);
            scrollWheelX = (AxisControl)setup.AddControl(CommonControls.ScrollWheelX);
            scrollWheelY = (AxisControl)setup.AddControl(CommonControls.ScrollWheelY);

            setup.GetControl(CommonControls.Action1).name = "Left Button";
            setup.GetControl(CommonControls.Action2).name = "Right Button";
            setup.GetControl(CommonControls.Action3).name = "Middle Button";

            setup.GetControl(CommonControls.ScrollWheelX).name = "Scroll Horizontal";
            setup.GetControl(CommonControls.ScrollWheelY).name = "Scroll Vertical";
        }
예제 #18
0
        public override void AddStandardControls(ControlSetup setup)
        {
            start = (ButtonControl)setup.AddControl(CommonControls.Start);
            back  = (ButtonControl)setup.AddControl(CommonControls.Back);

            dPadLeft  = (ButtonControl)setup.AddControl(CommonControls.DPadLeft);
            dPadRight = (ButtonControl)setup.AddControl(CommonControls.DPadRight);
            dPadDown  = (ButtonControl)setup.AddControl(CommonControls.DPadDown);
            dPadUp    = (ButtonControl)setup.AddControl(CommonControls.DPadUp);
            dPadX     = (AxisControl)setup.AddControl(CommonControls.DPadX);
            dPadY     = (AxisControl)setup.AddControl(CommonControls.DPadY);
            dPad      = (Vector2Control)setup.AddControl(CommonControls.DPad);

            setup.Mapping(k_MaxNumAxes + 0, start.index);
            setup.Mapping(k_MaxNumAxes + 1, back.index);
            setup.Mapping(5, dPadX.index);
            setup.Mapping(6, dPadY.index);
        }
        public override void AddStandardControls(ControlSetup setup)
        {
            base.AddStandardControls(setup);

            setup.GetControl(CommonControls.Pose).name = "Head Pose";

            leftEyePosition = (Vector3Control)setup.AddControl(SupportedControl.Get <Vector3Control>("Left Eye Position"));
            leftEyeRotation = (QuaternionControl)setup.AddControl(SupportedControl.Get <QuaternionControl>("Left Eye Rotation"));
            leftEyePose     = (PoseControl)setup.AddControl(SupportedControl.Get <PoseControl>("Left Eye Pose"));

            rightEyePosition = (Vector3Control)setup.AddControl(SupportedControl.Get <Vector3Control>("Right Eye Position"));
            rightEyeRotation = (QuaternionControl)setup.AddControl(SupportedControl.Get <QuaternionControl>("Right Eye Rotation"));
            rightEyePose     = (PoseControl)setup.AddControl(SupportedControl.Get <PoseControl>("Right Eye Pose"));

            centerEyePosition = (Vector3Control)setup.AddControl(SupportedControl.Get <Vector3Control>("Center Eye Position"));
            centerEyeRotation = (QuaternionControl)setup.AddControl(SupportedControl.Get <QuaternionControl>("Center Eye Rotation"));
            centerEyePose     = (PoseControl)setup.AddControl(SupportedControl.Get <PoseControl>("Center Eye Pose"));
        }
        public override ControlSetup GetControlSetup(InputDevice device)
        {
            ControlSetup setup = new ControlSetup(device);

            setup.AddControl(CommonControls.Back);
            setup.AddControl(CommonControls.Start);

            // Add the two additional motors on the triggers.
            var leftTriggerMotor  = new AxisOutput("Left Trigger Vibration");
            var rightTriggerMotor = new AxisOutput("Right Trigger Vibration");

            setup.AddControl(SupportedControl.Get <AxisOutput>("Left Trigger Vibration"), leftTriggerMotor);
            setup.AddControl(SupportedControl.Get <AxisOutput>("Right Trigger Vibration"), rightTriggerMotor);

            // Section for control name overrides.
            setup.GetControl(CommonControls.Action1).name = "A";
            setup.GetControl(CommonControls.Action2).name = "B";
            setup.GetControl(CommonControls.Action3).name = "X";
            setup.GetControl(CommonControls.Action4).name = "Y";

            return(setup);
        }
 public override void AddStandardControls(ControlSetup setup)
 {
     position = (Vector3Control)setup.AddControl(CommonControls.Position3d);
     rotation = (QuaternionControl)setup.AddControl(CommonControls.Rotation3d);
     pose     = (PoseControl)setup.AddControl(CommonControls.Pose);
 }
예제 #22
0
        public void SetupWithoutProfile()
        {
            ControlSetup setup = new ControlSetup(this);

            SetControls(setup);
        }
예제 #23
0
 ////REVIEW: it's weird that we allow this method to retain references to controls; just from the name, you'd simply expect it to add something to the ControlSetup and do nothing else
 // AddStandardControls is meant to be used for hardcoded standardized controls.
 // Device profiles may then add additional controls that are not guaranteed to be on the device.
 //
 // AddStandardControls mainly exists for tree reasons:
 //  - To avoid code duplication for devices that have many different device profiles, by having
 //    the code for the standard controls once in the device rather than in every profile for it.
 //  - To have a way to assign standard controls to the readonly "shortcut" control properties in the device.
 //  - To make a clear distinction between which controls are standardized for a device
 //    (and almost guaranteed to be present) and which are not.
 //
 // Non-standardized controls appear differently in the UI when assigning bindings for ActionMaps.
 // All controls added inside AddStandardControls are marked as standardized while those added
 // by device profiles are not.
 public abstract void AddStandardControls(ControlSetup setup);
        public XboxHIDGamepadProfile()
        {
            name = "Xbox Controller";
            matchingDeviceRegexes = new List <string>()
            {
                // Windows (XInput devices rely on a common product format of 'Product:[Controller(...)]')
                "^(?=.*product:(?=.*Controller \\(.*\\)))(?=.*interface:.*\\[HID\\])(?=.*type:.*HID.*Page:0x1.*Id:0x5).*$",
                // OSX
                "^(?=.*product:(?=.*Controller)(?=.*Xbox))(?=.*interface:.*\\[HID\\])(?=.*type:.*HID.*Page:0x1.*Id:0x5).*$",
            };

            ControlSetup setup = GetControlSetup(new Gamepad());

            // Setup mapping.
            setup.SplitMapping(0x010030, CommonControls.LeftStickLeft, CommonControls.LeftStickRight);
            setup.SplitMapping(0x010031, CommonControls.LeftStickUp, CommonControls.LeftStickDown);

            setup.SplitMapping(0x010033, CommonControls.RightStickLeft, CommonControls.RightStickRight);
            setup.SplitMapping(0x010034, CommonControls.RightStickUp, CommonControls.RightStickDown);

            setup.Mapping(0x090001, CommonControls.Action1);
            setup.Mapping(0x090002, CommonControls.Action2);
            setup.Mapping(0x090003, CommonControls.Action3);
            setup.Mapping(0x090004, CommonControls.Action4);

            setup.Mapping(0x090005, CommonControls.LeftBumper);
            setup.Mapping(0x090006, CommonControls.RightBumper);

#if IS_WINDOWS
            // Triggers are combined into a single [-1..1] range. Left is positive, right is negative.
            // At the USB level, the controller properly splits the triggers. XInput is picking it up from there.
            // Unfortunately, the MS HID driver for Xbox controllers combines them.
            setup.SplitMapping(0x010032, CommonControls.RightTrigger, CommonControls.LeftTrigger);

            setup.Mapping(0x090009, CommonControls.LeftStickButton);
            setup.Mapping(0x09000A, CommonControls.RightStickButton);

            setup.Mapping(0x090007, CommonControls.Back);
            setup.Mapping(0x090008, CommonControls.Start);

            // The dpad is done as a HID hatswitch.  The Xbox Hat Switch data is 1-based as it's starting value
            setup.HatMapping(0x010039, CommonControls.DPadLeft, CommonControls.DPadRight, CommonControls.DPadDown, CommonControls.DPadUp, 1);
#else
            setup.Mapping(0x010032, CommonControls.LeftTrigger, Range.full, Range.positive);
            setup.Mapping(0x010035, CommonControls.RightTrigger, Range.full, Range.positive);

            setup.Mapping(0x090007, CommonControls.LeftStickButton);
            setup.Mapping(0x090008, CommonControls.RightStickButton);

            setup.Mapping(0x09000A, CommonControls.Back);
            setup.Mapping(0x090009, CommonControls.Start);

            setup.Mapping(0x09000C, CommonControls.DPadUp, Range.full, Range.positive);
            setup.Mapping(0x09000D, CommonControls.DPadDown, Range.full, Range.positive);
            setup.Mapping(0x09000E, CommonControls.DPadLeft, Range.full, Range.positive);
            setup.Mapping(0x09000F, CommonControls.DPadRight, Range.full, Range.positive);
#endif

            mappings = setup.FinishMappings();

            // Haptics right now only works on Windows, but we intend to extend that to OSX/Linux in the near term.
#if IS_WINDOWS
            hapticsProcessor = new XboxHIDHapticsProcessor(setup.GetControl(SupportedControl.Get <AxisOutput>("Left Vibration")).index,
                                                           setup.GetControl(SupportedControl.Get <AxisOutput>("Right Vibration")).index,
                                                           setup.GetControl(SupportedControl.Get <AxisOutput>("Left Trigger Vibration")).index,
                                                           setup.GetControl(SupportedControl.Get <AxisOutput>("Right Trigger Vibration")).index);
#endif
        }
예제 #25
0
 public static void Mapping(this ControlSetup setup, int sourceIndex, SupportedControl control)
 {
     setup.mappings[sourceIndex] = new ControlMapping(
         setup.GetControl(control).index);
 }
예제 #26
0
 public static void SplitMapping(this ControlSetup setup, int sourceIndex, SupportedControl negative, SupportedControl positive)
 {
     setup.mappings[sourceIndex] = new ControlSplitMapping(
         setup.GetControl(negative).index,
         setup.GetControl(positive).index);
 }
        public override void AddStandardControls(ControlSetup setup)
        {
            base.AddStandardControls(setup);

            acceleration        = (Vector3Control)setup.AddControl(CommonControls.Acceleration3d);
            angularAcceleration = (Vector3Control)setup.AddControl(CommonControls.AngularAcceleration3d);
            velocity            = (Vector3Control)setup.AddControl(CommonControls.Velocity3d);
            angularVelocity     = (Vector3Control)setup.AddControl(CommonControls.AngularVelocity3d);

            trigger     = (ButtonControl)setup.AddControl(CommonControls.Trigger);
            handTrigger = (ButtonControl)setup.AddControl(CommonControls.Squeeze);

            triggerTouch     = (ButtonControl)setup.AddControl(CommonControls.TriggerTouch);
            triggerNearTouch = (ButtonControl)setup.AddControl(SupportedControl.Get <ButtonControl>("Trigger Near Touch"));

            action1Touch = (ButtonControl)setup.AddControl(SupportedControl.Get <ButtonControl>("Action 1 Touch"));

            action2      = (ButtonControl)setup.AddControl(CommonControls.Action2);
            action2Touch = (ButtonControl)setup.AddControl(SupportedControl.Get <ButtonControl>("Action 2 Touch"));

            thumbRestTouch = (ButtonControl)setup.AddControl(SupportedControl.Get <ButtonControl>("Thumb Rest Touch"));
            thumbNearTouch = (ButtonControl)setup.AddControl(SupportedControl.Get <ButtonControl>("Thumb Near Touch"));

            start = (ButtonControl)setup.AddControl(CommonControls.Start);

            // Ideally we would be able to switch these to right stick based on handedness change
            stickPress = (ButtonControl)setup.AddControl(CommonControls.LeftStickButton);
            stickTouch = (ButtonControl)setup.AddControl(CommonControls.LeftStickTouch);
            stickX     = (AxisControl)setup.AddControl(CommonControls.LeftStickX);
            stickY     = (AxisControl)setup.AddControl(CommonControls.LeftStickY);
            stickLeft  = (ButtonControl)setup.AddControl(CommonControls.LeftStickLeft);
            stickRight = (ButtonControl)setup.AddControl(CommonControls.LeftStickRight);
            stickUp    = (ButtonControl)setup.AddControl(CommonControls.LeftStickUp);
            stickDown  = (ButtonControl)setup.AddControl(CommonControls.LeftStickDown);
            stick      = (Vector2Control)setup.AddControl(CommonControls.LeftStick);

            // haptics rumble output axis
            rumble = (AxisOutput)setup.AddControl(CommonControls.Vibration);

            handTrigger.name = "Hand Trigger";
            stickPress.name  = "Stick Press";
            stickTouch.name  = "Stick Touch";
            stickX.name      = "Stick X";
            stickY.name      = "Stick Y";
            stickLeft.name   = "Stick Left";
            stickRight.name  = "Stick Right";
            stickUp.name     = "Stick Up";
            stickDown.name   = "Stick Down";
            stick.name       = "Stick";

            setup.Mapping(k_MaxNumAxes + 0, action1.index);
            setup.Mapping(k_MaxNumAxes + 1, action2.index);
            setup.Mapping(k_MaxNumAxes + 2, action1.index);
            setup.Mapping(k_MaxNumAxes + 3, action2.index);
            setup.Mapping(k_MaxNumAxes + 10, action1Touch.index);
            setup.Mapping(k_MaxNumAxes + 11, action2Touch.index);
            setup.Mapping(k_MaxNumAxes + 12, action1Touch.index);
            setup.Mapping(k_MaxNumAxes + 13, action2Touch.index);

            setup.Mapping(k_MaxNumAxes + 7, start.index);
            setup.Mapping(k_MaxNumAxes + 8, stickPress.index);
            setup.Mapping(k_MaxNumAxes + 9, stickPress.index);
            setup.Mapping(k_MaxNumAxes + 16, handTrigger.index);
            setup.Mapping(k_MaxNumAxes + 17, handTrigger.index);

            setup.Mapping(0, stickX.index);
            setup.Mapping(1, stickY.index);
            setup.Mapping(3, stickX.index);
            setup.Mapping(4, stickY.index);

            setup.Mapping(k_MaxNumAxes + 16, stickTouch.index);
            setup.Mapping(k_MaxNumAxes + 17, stickTouch.index);

            setup.Mapping(8, trigger.index);
            setup.Mapping(9, trigger.index);
            setup.Mapping(k_MaxNumAxes + 14, triggerTouch.index);
            setup.Mapping(k_MaxNumAxes + 15, triggerTouch.index);
            setup.Mapping(12, triggerNearTouch.index);
            setup.Mapping(13, triggerNearTouch.index);

            setup.Mapping(10, handTrigger.index);
            setup.Mapping(11, handTrigger.index);

            setup.Mapping(14, thumbNearTouch.index);
            setup.Mapping(15, thumbNearTouch.index);
            setup.Mapping(k_MaxNumAxes + 18, thumbRestTouch.index);
            setup.Mapping(k_MaxNumAxes + 19, thumbRestTouch.index);
        }
예제 #28
0
 public static void Mapping(this ControlSetup setup, int sourceIndex, int destIndex)
 {
     setup.mappings[sourceIndex] = new ControlMapping(
         destIndex);
 }