internal void UpdateState(StateMapping mapping) { _controller.ResetReport(); _controller.SetButtonState(Xbox360Button.A, mapping.A); _controller.SetButtonState(Xbox360Button.B, mapping.B); _controller.SetButtonState(Xbox360Button.X, mapping.X); _controller.SetButtonState(Xbox360Button.Y, mapping.Y); _controller.SetButtonState(Xbox360Button.Back, mapping.Back); _controller.SetButtonState(Xbox360Button.Start, mapping.Start); _controller.SetButtonState(Xbox360Button.Guide, mapping.Guide); _controller.SetButtonState(Xbox360Button.LeftShoulder, mapping.LeftShoulder); _controller.SetButtonState(Xbox360Button.RightShoulder, mapping.RightShoulder); _controller.SetButtonState(Xbox360Button.LeftThumb, mapping.LeftThumb); _controller.SetButtonState(Xbox360Button.RightThumb, mapping.RightThumb); _controller.SetAxisValue(Xbox360Axis.LeftThumbX, mapping.LeftThumbX); _controller.SetAxisValue(Xbox360Axis.LeftThumbY, mapping.LeftThumbY); _controller.SetAxisValue(Xbox360Axis.RightThumbX, mapping.RightThumbX); _controller.SetAxisValue(Xbox360Axis.RightThumbY, mapping.RightThumbY); _controller.SetSliderValue(Xbox360Slider.LeftTrigger, mapping.LeftTrigger); _controller.SetSliderValue(Xbox360Slider.RightTrigger, mapping.RightTrigger); _controller.SetButtonState(Xbox360Button.Up, mapping.Up); _controller.SetButtonState(Xbox360Button.Down, mapping.Down); _controller.SetButtonState(Xbox360Button.Left, mapping.Left); _controller.SetButtonState(Xbox360Button.Right, mapping.Right); _controller.SubmitReport(); }
public override void ResetState(bool submit = true) { cont.ResetReport(); if (submit) { cont.SubmitReport(); } }
public void InputReportReceived(IDualShockDevice device, IInputReport report) { _target.ResetReport(); //This may be able to be optimized, look into later... // Convert report to DS3 format and store latest report for this device var ds3Report = (DualShock3InputReport)report; if (device.DeviceIndex == 0) { _Nav0Report = ds3Report; } if (device.DeviceIndex == 1) { _Nav1Report = ds3Report; } // Only combine reports and submit if we've seen input from each controller at least once if (_Nav0Report != null && _Nav1Report != null) { // Map buttons from Navigation #1 into input report _target.SetAxisValue(Xbox360Axis.LeftThumbX, Scale(_Nav0Report[DualShock3Axes.LeftThumbX], false)); _target.SetAxisValue(Xbox360Axis.LeftThumbY, Scale(_Nav0Report[DualShock3Axes.LeftThumbY], true)); _target.SetAxisValue(Xbox360Axis.RightThumbX, Scale(_Nav1Report[DualShock3Axes.LeftThumbX], false)); _target.SetAxisValue(Xbox360Axis.RightThumbY, Scale(_Nav1Report[DualShock3Axes.LeftThumbY], true)); _target.SetSliderValue(Xbox360Slider.LeftTrigger, _Nav0Report[DualShock3Axes.LeftTrigger]); _target.SetSliderValue(Xbox360Slider.RightTrigger, _Nav1Report[DualShock3Axes.LeftTrigger]); foreach (var button in _btnMap0.Where(m => _Nav0Report.EngagedButtons.Contains(m.Key)) .Select(m => m.Value)) { _target.SetButtonState(button, true); } foreach (var button in _btnMap1.Where(m => _Nav1Report.EngagedButtons.Contains(m.Key)) .Select(m => m.Value)) { _target.SetButtonState(button, true); } _target.SubmitReport(); } }
private void input_thread() { target360.Connect(); bool ss_button_pressed = false; bool ss_button_held = false; _stream.ReadTimeout = Timeout.Infinite; byte[] data = new byte[_device.GetMaxInputReportLength()]; while (running) { int read = 0; try { read = _stream.Read(data); } catch (TimeoutException e) { read = 0; } catch { unplug(joinInputThread: false); } if (read > 0) { if (data[0] == 0x03 && read == 10) { target360.ResetReport(); if ((data[3] & 64) != 0) { target360.SetButtonState(Xbox360Button.A, true); } if ((data[3] & 32) != 0) { target360.SetButtonState(Xbox360Button.B, true); } if ((data[3] & 16) != 0) { target360.SetButtonState(Xbox360Button.X, true); } if ((data[3] & 8) != 0) { target360.SetButtonState(Xbox360Button.Y, true); } if ((data[3] & 4) != 0) { target360.SetButtonState(Xbox360Button.LeftShoulder, true); } if ((data[3] & 2) != 0) { target360.SetButtonState(Xbox360Button.RightShoulder, true); } if ((data[3] & 1) != 0) { target360.SetButtonState(Xbox360Button.LeftThumb, true); } if ((data[2] & 128) != 0) { target360.SetButtonState(Xbox360Button.RightThumb, true); } ss_button_pressed = (data[2] & 1) != 0; //assistant_button_pressed = ( currentState[2] & 2 ) != 0; // [2] & 2 == Assistant, [2] & 1 == Screenshot switch (data[1]) { default: break; case 0: target360.SetButtonState(Xbox360Button.Up, true); break; case 1: target360.SetButtonState(Xbox360Button.Up, true); target360.SetButtonState(Xbox360Button.Right, true); break; case 2: target360.SetButtonState(Xbox360Button.Right, true); break; case 3: target360.SetButtonState(Xbox360Button.Down, true); target360.SetButtonState(Xbox360Button.Right, true); break; case 4: target360.SetButtonState(Xbox360Button.Down, true); break; case 5: target360.SetButtonState(Xbox360Button.Down, true); target360.SetButtonState(Xbox360Button.Left, true); break; case 6: target360.SetButtonState(Xbox360Button.Left, true); break; case 7: target360.SetButtonState(Xbox360Button.Up, true); target360.SetButtonState(Xbox360Button.Left, true); break; } if ((data[2] & 32) != 0) { target360.SetButtonState(Xbox360Button.Start, true); } if ((data[2] & 64) != 0) { target360.SetButtonState(Xbox360Button.Back, true); } if ((data[2] & 16) != 0) { target360.SetButtonState(Xbox360Button.Guide, true); } // Note: The HID reports do not allow stick values of 00. // This seems to make sense: 0x80 is center, so usable values are: // 0x01 to 0x7F and 0x81 to 0xFF. // For our purposes I believe this is undesirable. Subtract 1 from negative // values to allow maxing out the stick values. // TODO: Get an Xbox controller and verify this is standard behavior. for (int i = 4; i <= 7; ++i) { if (data[i] <= 0x7F && data[i] > 0x00) { data[i] -= 0x01; } } ushort LeftStickXunsigned = (ushort)(data[4] << 8 | (data[4] << 1 & 255)); if (LeftStickXunsigned == 0xFFFE) { LeftStickXunsigned = 0xFFFF; } short LeftStickX = (short)(LeftStickXunsigned - 0x8000); ushort LeftStickYunsigned = (ushort)(data[5] << 8 | (data[5] << 1 & 255)); if (LeftStickYunsigned == 0xFFFE) { LeftStickYunsigned = 0xFFFF; } short LeftStickY = (short)(-LeftStickYunsigned + 0x7FFF); if (LeftStickY == -1) { LeftStickY = 0; } ushort RightStickXunsigned = (ushort)(data[6] << 8 | (data[6] << 1 & 255)); if (RightStickXunsigned == 0xFFFE) { RightStickXunsigned = 0xFFFF; } short RightStickX = (short)(RightStickXunsigned - 0x8000); ushort RightStickYunsigned = (ushort)(data[7] << 8 | (data[7] << 1 & 255)); if (RightStickYunsigned == 0xFFFE) { RightStickYunsigned = 0xFFFF; } short RightStickY = (short)(-RightStickYunsigned + 0x7FFF); if (RightStickY == -1) { RightStickY = 0; } target360.SetAxisValue(Xbox360Axis.LeftThumbX, LeftStickX); target360.SetAxisValue(Xbox360Axis.LeftThumbY, LeftStickY); target360.SetAxisValue(Xbox360Axis.RightThumbX, RightStickX); target360.SetAxisValue(Xbox360Axis.RightThumbY, RightStickY); target360.SetSliderValue(Xbox360Slider.LeftTrigger, data[8]); target360.SetSliderValue(Xbox360Slider.RightTrigger, data[9]); target360.SubmitReport(); } } if (ss_button_pressed && !ss_button_held) { ss_button_held = true; try { // TODO: Allow configuring this keybind. ssThread = new Thread(() => System.Windows.Forms.SendKeys.SendWait("^+Z")); ssThread.Start(); } catch { } } else if (ss_button_held && !ss_button_pressed) { ss_button_held = false; } } target360.Disconnect(); }
public virtual bool Report(byte[] input, byte[] output) { byte id = (byte)(input[4] - 1); if (targets.Count <= id || targets[id] == null) { return(false); } IXbox360Controller controller = targets[id]; controller.ResetReport(); if ((input[10] & 32) != 0) { controller.SetButtonState(Xbox360Button.Back, true); } if ((input[10] & 64) != 0) { controller.SetButtonState(Xbox360Button.LeftThumb, true); } if ((input[10] & 128) != 0) { controller.SetButtonState(Xbox360Button.RightThumb, true); } if ((input[10] & 16) != 0) { controller.SetButtonState(Xbox360Button.Start, true); } if ((input[10] & 1) != 0) { controller.SetButtonState(Xbox360Button.Up, true); } if ((input[10] & 2) != 0) { controller.SetButtonState(Xbox360Button.Down, true); } if ((input[10] & 4) != 0) { controller.SetButtonState(Xbox360Button.Left, true); } if ((input[10] & 8) != 0) { controller.SetButtonState(Xbox360Button.Right, true); } if ((input[11] & 1) != 0) { controller.SetButtonState(Xbox360Button.LeftShoulder, true); } if ((input[11] & 2) != 0) { controller.SetButtonState(Xbox360Button.RightShoulder, true); } if ((input[11] & 128) != 0) { controller.SetButtonState(Xbox360Button.Y, true); } if ((input[11] & 32) != 0) { controller.SetButtonState(Xbox360Button.B, true); } if ((input[11] & 16) != 0) { controller.SetButtonState(Xbox360Button.A, true); } if ((input[11] & 64) != 0) { controller.SetButtonState(Xbox360Button.X, true); } if ((input[11] & 4) != 0) { controller.SetButtonState(Xbox360Button.Guide, true); } controller.SetSliderValue(Xbox360Slider.LeftTrigger, input[12]); controller.SetSliderValue(Xbox360Slider.RightTrigger, input[13]); controller.SetAxisValue(Xbox360Axis.LeftThumbX, BitConverter.ToInt16(input, 14)); controller.SetAxisValue(Xbox360Axis.LeftThumbY, BitConverter.ToInt16(input, 16)); controller.SetAxisValue(Xbox360Axis.RightThumbX, BitConverter.ToInt16(input, 18)); controller.SetAxisValue(Xbox360Axis.RightThumbY, BitConverter.ToInt16(input, 20)); controller.SubmitReport(); return(true); }
public override void ConvertandSendReport(DS4State state, int device) { if (!connected) { return; } cont.ResetReport(); ushort tempButtons = 0; unchecked { if (state.Share) { tempButtons |= Xbox360Button.Back.Value; } if (state.L3) { tempButtons |= Xbox360Button.LeftThumb.Value; } if (state.R3) { tempButtons |= Xbox360Button.RightThumb.Value; } if (state.Options) { tempButtons |= Xbox360Button.Start.Value; } if (state.DpadUp) { tempButtons |= Xbox360Button.Up.Value; } if (state.DpadRight) { tempButtons |= Xbox360Button.Right.Value; } if (state.DpadDown) { tempButtons |= Xbox360Button.Down.Value; } if (state.DpadLeft) { tempButtons |= Xbox360Button.Left.Value; } if (state.L1) { tempButtons |= Xbox360Button.LeftShoulder.Value; } if (state.R1) { tempButtons |= Xbox360Button.RightShoulder.Value; } if (state.Triangle) { tempButtons |= Xbox360Button.Y.Value; } if (state.Circle) { tempButtons |= Xbox360Button.B.Value; } if (state.Cross) { tempButtons |= Xbox360Button.A.Value; } if (state.Square) { tempButtons |= Xbox360Button.X.Value; } if (state.PS) { tempButtons |= Xbox360Button.Guide.Value; } cont.SetButtonsFull(tempButtons); } cont.LeftTrigger = state.L2; cont.RightTrigger = state.R2; SASteeringWheelEmulationAxisType steeringWheelMappedAxis = Global.GetSASteeringWheelEmulationAxis(device); switch (steeringWheelMappedAxis) { case SASteeringWheelEmulationAxisType.None: cont.LeftThumbX = AxisScale(state.LX, false); cont.LeftThumbY = AxisScale(state.LY, true); cont.RightThumbX = AxisScale(state.RX, false); cont.RightThumbY = AxisScale(state.RY, true); break; case SASteeringWheelEmulationAxisType.LX: cont.LeftThumbX = (short)state.SASteeringWheelEmulationUnit; cont.LeftThumbY = AxisScale(state.LY, true); cont.RightThumbX = AxisScale(state.RX, false); cont.RightThumbY = AxisScale(state.RY, true); break; case SASteeringWheelEmulationAxisType.LY: cont.LeftThumbX = AxisScale(state.LX, false); cont.LeftThumbY = (short)state.SASteeringWheelEmulationUnit; cont.RightThumbX = AxisScale(state.RX, false); cont.RightThumbY = AxisScale(state.RY, true); break; case SASteeringWheelEmulationAxisType.RX: cont.LeftThumbX = AxisScale(state.LX, false); cont.LeftThumbY = AxisScale(state.LY, true); cont.RightThumbX = (short)state.SASteeringWheelEmulationUnit; cont.RightThumbY = AxisScale(state.RY, true); break; case SASteeringWheelEmulationAxisType.RY: cont.LeftThumbX = AxisScale(state.LX, false); cont.LeftThumbY = AxisScale(state.LY, true); cont.RightThumbX = AxisScale(state.RX, false); cont.RightThumbY = (short)state.SASteeringWheelEmulationUnit; break; case SASteeringWheelEmulationAxisType.L2R2: cont.LeftTrigger = cont.RightTrigger = 0; if (state.SASteeringWheelEmulationUnit >= 0) { cont.LeftTrigger = (Byte)state.SASteeringWheelEmulationUnit; } else { cont.RightTrigger = (Byte)state.SASteeringWheelEmulationUnit; } goto case SASteeringWheelEmulationAxisType.None; case SASteeringWheelEmulationAxisType.VJoy1X: case SASteeringWheelEmulationAxisType.VJoy2X: DS4Windows.VJoyFeeder.vJoyFeeder.FeedAxisValue(state.SASteeringWheelEmulationUnit, ((((uint)steeringWheelMappedAxis) - ((uint)SASteeringWheelEmulationAxisType.VJoy1X)) / 3) + 1, DS4Windows.VJoyFeeder.HID_USAGES.HID_USAGE_X); goto case SASteeringWheelEmulationAxisType.None; case SASteeringWheelEmulationAxisType.VJoy1Y: case SASteeringWheelEmulationAxisType.VJoy2Y: DS4Windows.VJoyFeeder.vJoyFeeder.FeedAxisValue(state.SASteeringWheelEmulationUnit, ((((uint)steeringWheelMappedAxis) - ((uint)SASteeringWheelEmulationAxisType.VJoy1X)) / 3) + 1, DS4Windows.VJoyFeeder.HID_USAGES.HID_USAGE_Y); goto case SASteeringWheelEmulationAxisType.None; case SASteeringWheelEmulationAxisType.VJoy1Z: case SASteeringWheelEmulationAxisType.VJoy2Z: DS4Windows.VJoyFeeder.vJoyFeeder.FeedAxisValue(state.SASteeringWheelEmulationUnit, ((((uint)steeringWheelMappedAxis) - ((uint)SASteeringWheelEmulationAxisType.VJoy1X)) / 3) + 1, DS4Windows.VJoyFeeder.HID_USAGES.HID_USAGE_Z); goto case SASteeringWheelEmulationAxisType.None; default: // Should never come here but just in case use the NONE case as default handler.... goto case SASteeringWheelEmulationAxisType.None; } cont.SubmitReport(); }