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 }