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; } }
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); 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); }
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 }
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); }