public void SetDPadDirection(DualShock4DPadDirection direction)
        {
            _nativeReport.wButtons &= unchecked ((ushort)~0xF);
            _nativeReport.wButtons |= direction.Value;

            if (AutoSubmitReport)
            {
                SubmitNativeReport(_nativeReport);
            }
        }
        // DualShockState from PS4RemotePlayInjection
        public static void ConvertandSendReport(IDualShock4Controller controller, DualShockState state)
        {
            // 2021.12.21 pancakeslp
            // ` controller.ResetReport(); `
            // it might make sense to reset the controller/report
            // but sometimes the report might auto submit, resulting in what looks like a twitch
            //
            // this is most easilly observed with having the ADS toggle on,
            // and then ADSing and taking your hand off the mouse

            //Left
            controller.SetButtonState(DualShock4Button.ShoulderLeft, state.L1);
            SetTriggerLeft(controller, state.L2);
            controller.SetButtonState(DualShock4Button.ThumbLeft, state.L3);

            DualShock4DPadDirection tempDPad = DualShock4DPadDirection.None;

            if (state.DPad_Up && state.DPad_Right)
            {
                tempDPad = DualShock4DPadDirection.Northeast;
            }
            else if (state.DPad_Up && state.DPad_Left)
            {
                tempDPad = DualShock4DPadDirection.Northwest;
            }
            else if (state.DPad_Up)
            {
                tempDPad = DualShock4DPadDirection.North;
            }
            else if (state.DPad_Right && state.DPad_Down)
            {
                tempDPad = DualShock4DPadDirection.Southeast;
            }
            else if (state.DPad_Right)
            {
                tempDPad = DualShock4DPadDirection.East;
            }
            else if (state.DPad_Down && state.DPad_Left)
            {
                tempDPad = DualShock4DPadDirection.Southwest;
            }
            else if (state.DPad_Down)
            {
                tempDPad = DualShock4DPadDirection.South;
            }
            else if (state.DPad_Left)
            {
                tempDPad = DualShock4DPadDirection.West;
            }
            controller.SetDPadDirection(tempDPad);

            controller.SetAxisValue(DualShock4Axis.LeftThumbX, state.LX);
            controller.SetAxisValue(DualShock4Axis.LeftThumbY, state.LY);


            //middle
            controller.SetButtonState(DualShock4Button.Options, state.Options);
            controller.SetButtonState(DualShock4Button.Share, state.Share);

            controller.SetButtonState(DualShock4SpecialButton.Ps, state.PS);
            controller.SetButtonState(DualShock4SpecialButton.Touchpad, state.TouchButton);


            //Right
            controller.SetButtonState(DualShock4Button.ShoulderRight, state.R1);
            SetTriggerRight(controller, state.R2);
            controller.SetButtonState(DualShock4Button.ThumbRight, state.R3);

            controller.SetButtonState(DualShock4Button.Circle, state.Circle);
            controller.SetButtonState(DualShock4Button.Cross, state.Cross);
            controller.SetButtonState(DualShock4Button.Square, state.Square);
            controller.SetButtonState(DualShock4Button.Triangle, state.Triangle);

            controller.SetAxisValue(DualShock4Axis.RightThumbX, state.RX);
            controller.SetAxisValue(DualShock4Axis.RightThumbY, state.RY);

            controller.SubmitReport();
        }
        // DS4State from Nefarius.ViGEm.Client.Targets
        public static void ConvertandSendReport(IDualShock4Controller controller, DS4State state)
        {
            // 2021.12.21 pancakeslp
            // ` controller.ResetReport(); `
            // it might make sense to reset the controller/report
            // but sometimes the report might auto submit, resulting in what looks like a twitch
            //
            // this is most easilly observed with having the ADS toggle on,
            // and then ADSing and taking your hand off the mouse

            ushort tempButtons = 0;
            DualShock4DPadDirection tempDPad = DualShock4DPadDirection.None;
            ushort tempSpecial = 0;

            unchecked
            {
                if (state.Share)
                {
                    tempButtons |= DualShock4Button.Share.Value;
                }
                if (state.L3)
                {
                    tempButtons |= DualShock4Button.ThumbLeft.Value;
                }
                if (state.R3)
                {
                    tempButtons |= DualShock4Button.ThumbRight.Value;
                }
                if (state.Options)
                {
                    tempButtons |= DualShock4Button.Options.Value;
                }

                if (state.DpadUp && state.DpadRight)
                {
                    tempDPad = DualShock4DPadDirection.Northeast;
                }
                else if (state.DpadUp && state.DpadLeft)
                {
                    tempDPad = DualShock4DPadDirection.Northwest;
                }
                else if (state.DpadUp)
                {
                    tempDPad = DualShock4DPadDirection.North;
                }
                else if (state.DpadRight && state.DpadDown)
                {
                    tempDPad = DualShock4DPadDirection.Southeast;
                }
                else if (state.DpadRight)
                {
                    tempDPad = DualShock4DPadDirection.East;
                }
                else if (state.DpadDown && state.DpadLeft)
                {
                    tempDPad = DualShock4DPadDirection.Southwest;
                }
                else if (state.DpadDown)
                {
                    tempDPad = DualShock4DPadDirection.South;
                }
                else if (state.DpadLeft)
                {
                    tempDPad = DualShock4DPadDirection.West;
                }

                if (state.L1)
                {
                    tempButtons |= DualShock4Button.ShoulderLeft.Value;
                }
                if (state.R1)
                {
                    tempButtons |= DualShock4Button.ShoulderRight.Value;
                }
                //if (state.L2Btn) tempButtons |= DualShock4Buttons.TriggerLeft;
                //if (state.R2Btn) tempButtons |= DualShock4Buttons.TriggerRight;
                if (state.L2 > 0)
                {
                    tempButtons |= DualShock4Button.TriggerLeft.Value;
                }
                if (state.R2 > 0)
                {
                    tempButtons |= DualShock4Button.TriggerRight.Value;
                }

                if (state.Triangle)
                {
                    tempButtons |= DualShock4Button.Triangle.Value;
                }
                if (state.Circle)
                {
                    tempButtons |= DualShock4Button.Circle.Value;
                }
                if (state.Cross)
                {
                    tempButtons |= DualShock4Button.Cross.Value;
                }
                if (state.Square)
                {
                    tempButtons |= DualShock4Button.Square.Value;
                }
                if (state.PS)
                {
                    tempSpecial |= DualShock4SpecialButton.Ps.Value;
                }
                if (state.TouchButton)
                {
                    tempSpecial |= DualShock4SpecialButton.Touchpad.Value;
                }

                controller.SetDPadDirection(tempDPad);
            }

            controller.SubmitReport();
        }
Beispiel #4
0
        public override unsafe void ConvertandSendReport(DS4State state, int device)
        {
            if (!connected)
            {
                return;
            }

            ushort tempButtons = 0;
            DualShock4DPadDirection tempDPad = DualShock4DPadDirection.None;
            ushort tempSpecial = 0;

            unchecked
            {
                if (state.Share)
                {
                    tempButtons |= DualShock4Button.Share.Value;
                }
                if (state.L3)
                {
                    tempButtons |= DualShock4Button.ThumbLeft.Value;
                }
                if (state.R3)
                {
                    tempButtons |= DualShock4Button.ThumbRight.Value;
                }
                if (state.Options)
                {
                    tempButtons |= DualShock4Button.Options.Value;
                }

                if (state.DpadUp && state.DpadRight)
                {
                    tempDPad = DualShock4DPadDirection.Northeast;
                }
                else if (state.DpadUp && state.DpadLeft)
                {
                    tempDPad = DualShock4DPadDirection.Northwest;
                }
                else if (state.DpadUp)
                {
                    tempDPad = DualShock4DPadDirection.North;
                }
                else if (state.DpadRight && state.DpadDown)
                {
                    tempDPad = DualShock4DPadDirection.Southeast;
                }
                else if (state.DpadRight)
                {
                    tempDPad = DualShock4DPadDirection.East;
                }
                else if (state.DpadDown && state.DpadLeft)
                {
                    tempDPad = DualShock4DPadDirection.Southwest;
                }
                else if (state.DpadDown)
                {
                    tempDPad = DualShock4DPadDirection.South;
                }
                else if (state.DpadLeft)
                {
                    tempDPad = DualShock4DPadDirection.West;
                }

                /*if (state.DpadUp) tempDPad = (state.DpadRight) ? DualShock4DPadValues.Northeast : DualShock4DPadValues.North;
                 * if (state.DpadRight) tempDPad = (state.DpadDown) ? DualShock4DPadValues.Southeast : DualShock4DPadValues.East;
                 * if (state.DpadDown) tempDPad = (state.DpadLeft) ? DualShock4DPadValues.Southwest : DualShock4DPadValues.South;
                 * if (state.DpadLeft) tempDPad = (state.DpadUp) ? DualShock4DPadValues.Northwest : DualShock4DPadValues.West;
                 */

                if (state.L1)
                {
                    tempButtons |= DualShock4Button.ShoulderLeft.Value;
                }
                if (state.R1)
                {
                    tempButtons |= DualShock4Button.ShoulderRight.Value;
                }
                //if (state.L2Btn) tempButtons |= DualShock4Buttons.TriggerLeft;
                //if (state.R2Btn) tempButtons |= DualShock4Buttons.TriggerRight;
                if (state.L2 > 0)
                {
                    tempButtons |= DualShock4Button.TriggerLeft.Value;
                }
                if (state.R2 > 0)
                {
                    tempButtons |= DualShock4Button.TriggerRight.Value;
                }

                if (state.Triangle)
                {
                    tempButtons |= DualShock4Button.Triangle.Value;
                }
                if (state.Circle)
                {
                    tempButtons |= DualShock4Button.Circle.Value;
                }
                if (state.Cross)
                {
                    tempButtons |= DualShock4Button.Cross.Value;
                }
                if (state.Square)
                {
                    tempButtons |= DualShock4Button.Square.Value;
                }
                if (state.PS)
                {
                    tempSpecial |= DualShock4SpecialButton.Ps.Value;
                }
                if (state.OutputTouchButton)
                {
                    tempSpecial |= DualShock4SpecialButton.Touchpad.Value;
                }

                outDS4Report.wButtons = tempButtons;
                // Frame counter is high 6 bits. Low 2 bits is for extra buttons (PS, TP Click)
                outDS4Report.bSpecial  = (byte)(tempSpecial | (state.FrameCounter << 2));
                outDS4Report.wButtons |= tempDPad.Value;
            }

            outDS4Report.bTriggerL = state.L2;
            outDS4Report.bTriggerR = state.R2;

            SASteeringWheelEmulationAxisType steeringWheelMappedAxis = Global.GetSASteeringWheelEmulationAxis(device);

            switch (steeringWheelMappedAxis)
            {
            case SASteeringWheelEmulationAxisType.None:
                outDS4Report.bThumbLX = state.LX;
                outDS4Report.bThumbLY = state.LY;
                outDS4Report.bThumbRX = state.RX;
                outDS4Report.bThumbRY = state.RY;
                break;

            case SASteeringWheelEmulationAxisType.LX:
                outDS4Report.bThumbLX = (byte)state.SASteeringWheelEmulationUnit;
                outDS4Report.bThumbLY = state.LY;
                outDS4Report.bThumbRX = state.RX;
                outDS4Report.bThumbRY = state.RY;
                break;

            case SASteeringWheelEmulationAxisType.LY:
                outDS4Report.bThumbLX = state.LX;
                outDS4Report.bThumbLY = (byte)state.SASteeringWheelEmulationUnit;
                outDS4Report.bThumbRX = state.RX;
                outDS4Report.bThumbRY = state.RY;
                break;

            case SASteeringWheelEmulationAxisType.RX:
                outDS4Report.bThumbLX = state.LX;
                outDS4Report.bThumbLY = state.LY;
                outDS4Report.bThumbRX = (byte)state.SASteeringWheelEmulationUnit;
                outDS4Report.bThumbRY = state.RY;
                break;

            case SASteeringWheelEmulationAxisType.RY:
                outDS4Report.bThumbLX = state.LX;
                outDS4Report.bThumbLY = state.LY;
                outDS4Report.bThumbRX = state.RX;
                outDS4Report.bThumbRY = (byte)state.SASteeringWheelEmulationUnit;
                break;

            case SASteeringWheelEmulationAxisType.L2R2:
                outDS4Report.bTriggerL = outDS4Report.bTriggerR = 0;
                if (state.SASteeringWheelEmulationUnit >= 0)
                {
                    outDS4Report.bTriggerL = (Byte)state.SASteeringWheelEmulationUnit;
                }
                else
                {
                    outDS4Report.bTriggerR = (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;
            }

            // Only worry about mapping 1 touch packet
            outDS4Report.bTouchPacketsN = 1;
            outDS4Report.sCurrentTouch.bPacketCounter    = state.TouchPacketCounter;
            outDS4Report.sCurrentTouch.bIsUpTrackingNum1 = state.TrackPadTouch0.RawTrackingNum;
            outDS4Report.sCurrentTouch.bTouchData1[0]    = (byte)(state.TrackPadTouch0.X & 0xFF);
            outDS4Report.sCurrentTouch.bTouchData1[1]    = (byte)((state.TrackPadTouch0.X >> 8) & 0x0F | (state.TrackPadTouch0.Y << 4) & 0xF0);
            outDS4Report.sCurrentTouch.bTouchData1[2]    = (byte)(state.TrackPadTouch0.Y >> 4);

            outDS4Report.sCurrentTouch.bIsUpTrackingNum2 = state.TrackPadTouch1.RawTrackingNum;
            outDS4Report.sCurrentTouch.bTouchData2[0]    = (byte)(state.TrackPadTouch1.X & 0xFF);
            outDS4Report.sCurrentTouch.bTouchData2[1]    = (byte)((state.TrackPadTouch1.X >> 8) & 0x0F | (state.TrackPadTouch1.Y << 4) & 0xF0);
            outDS4Report.sCurrentTouch.bTouchData2[2]    = (byte)(state.TrackPadTouch1.Y >> 4);

            // Flip some coordinates back to DS4 device coordinate system
            //outDS4Report.wGyroX = (short)-state.Motion.gyroYawFull;
            //outDS4Report.wGyroY = (short)state.Motion.gyroPitchFull;
            outDS4Report.wGyroX  = (short)state.Motion.gyroPitchFull;
            outDS4Report.wGyroY  = (short)-state.Motion.gyroYawFull;
            outDS4Report.wGyroZ  = (short)-state.Motion.gyroRollFull;
            outDS4Report.wAccelX = (short)-state.Motion.accelXFull;
            outDS4Report.wAccelY = (short)-state.Motion.accelYFull;
            outDS4Report.wAccelZ = (short)state.Motion.accelZFull;

            // USB DS4 v.1 battery level range is [0-11]
            outDS4Report.bBatteryLvlSpecial = (byte)(state.Battery / 11);

            outDS4Report.wTimestamp = state.ds4Timestamp;

            DS4OutDeviceExtras.CopyBytes(ref outDS4Report, rawOutReportEx);
            //Console.WriteLine("TEST: {0}, {1} {2}", outDS4Report.wGyroX, rawOutReportEx[12], rawOutReportEx[13]);
            //Console.WriteLine("OUTPUT: {0}", string.Join(", ", rawOutReportEx));
            cont.SubmitRawReport(rawOutReportEx);
        }
Beispiel #5
0
        public override void ConvertandSendReport(DS4State state, int device)
        {
            if (!connected)
            {
                return;
            }

            cont.ResetReport();
            ushort tempButtons = 0;
            DualShock4DPadDirection tempDPad = DualShock4DPadDirection.None;
            ushort tempSpecial = 0;

            unchecked
            {
                if (state.Share)
                {
                    tempButtons |= DualShock4Button.Share.Value;
                }
                if (state.L3)
                {
                    tempButtons |= DualShock4Button.ThumbLeft.Value;
                }
                if (state.R3)
                {
                    tempButtons |= DualShock4Button.ThumbRight.Value;
                }
                if (state.Options)
                {
                    tempButtons |= DualShock4Button.Options.Value;
                }

                if (state.DpadUp && state.DpadRight)
                {
                    tempDPad = DualShock4DPadDirection.Northeast;
                }
                else if (state.DpadUp && state.DpadLeft)
                {
                    tempDPad = DualShock4DPadDirection.Northwest;
                }
                else if (state.DpadUp)
                {
                    tempDPad = DualShock4DPadDirection.North;
                }
                else if (state.DpadRight && state.DpadDown)
                {
                    tempDPad = DualShock4DPadDirection.Southeast;
                }
                else if (state.DpadRight)
                {
                    tempDPad = DualShock4DPadDirection.East;
                }
                else if (state.DpadDown && state.DpadLeft)
                {
                    tempDPad = DualShock4DPadDirection.Southwest;
                }
                else if (state.DpadDown)
                {
                    tempDPad = DualShock4DPadDirection.South;
                }
                else if (state.DpadLeft)
                {
                    tempDPad = DualShock4DPadDirection.West;
                }

                /*if (state.DpadUp) tempDPad = (state.DpadRight) ? DualShock4DPadValues.Northeast : DualShock4DPadValues.North;
                 * if (state.DpadRight) tempDPad = (state.DpadDown) ? DualShock4DPadValues.Southeast : DualShock4DPadValues.East;
                 * if (state.DpadDown) tempDPad = (state.DpadLeft) ? DualShock4DPadValues.Southwest : DualShock4DPadValues.South;
                 * if (state.DpadLeft) tempDPad = (state.DpadUp) ? DualShock4DPadValues.Northwest : DualShock4DPadValues.West;
                 */

                if (state.L1)
                {
                    tempButtons |= DualShock4Button.ShoulderLeft.Value;
                }
                if (state.R1)
                {
                    tempButtons |= DualShock4Button.ShoulderRight.Value;
                }
                //if (state.L2Btn) tempButtons |= DualShock4Buttons.TriggerLeft;
                //if (state.R2Btn) tempButtons |= DualShock4Buttons.TriggerRight;
                if (state.L2 > 0)
                {
                    tempButtons |= DualShock4Button.TriggerLeft.Value;
                }
                if (state.R2 > 0)
                {
                    tempButtons |= DualShock4Button.TriggerRight.Value;
                }

                if (state.Triangle)
                {
                    tempButtons |= DualShock4Button.Triangle.Value;
                }
                if (state.Circle)
                {
                    tempButtons |= DualShock4Button.Circle.Value;
                }
                if (state.Cross)
                {
                    tempButtons |= DualShock4Button.Cross.Value;
                }
                if (state.Square)
                {
                    tempButtons |= DualShock4Button.Square.Value;
                }
                if (state.PS)
                {
                    tempSpecial |= DualShock4SpecialButton.Ps.Value;
                }
                if (state.TouchButton)
                {
                    tempSpecial |= DualShock4SpecialButton.Touchpad.Value;
                }
                cont.SetButtonsFull(tempButtons);
                cont.SetSpecialButtonsFull((byte)tempSpecial);
                cont.SetDPadDirection(tempDPad);
                //report.Buttons = (ushort)tempButtons;
                //report.SpecialButtons = (byte)tempSpecial;
            }

            cont.LeftTrigger  = state.L2;
            cont.RightTrigger = state.R2;

            SASteeringWheelEmulationAxisType steeringWheelMappedAxis = Global.GetSASteeringWheelEmulationAxis(device);

            switch (steeringWheelMappedAxis)
            {
            case SASteeringWheelEmulationAxisType.None:
                cont.LeftThumbX  = state.LX;
                cont.LeftThumbY  = state.LY;
                cont.RightThumbX = state.RX;
                cont.RightThumbY = state.RY;
                break;

            case SASteeringWheelEmulationAxisType.LX:
                cont.LeftThumbX  = (byte)state.SASteeringWheelEmulationUnit;
                cont.LeftThumbY  = state.LY;
                cont.RightThumbX = state.RX;
                cont.RightThumbY = state.RY;
                break;

            case SASteeringWheelEmulationAxisType.LY:
                cont.LeftThumbX  = state.LX;
                cont.LeftThumbY  = (byte)state.SASteeringWheelEmulationUnit;
                cont.RightThumbX = state.RX;
                cont.RightThumbY = state.RY;
                break;

            case SASteeringWheelEmulationAxisType.RX:
                cont.LeftThumbX  = state.LX;
                cont.LeftThumbY  = state.LY;
                cont.RightThumbX = (byte)state.SASteeringWheelEmulationUnit;
                cont.RightThumbY = state.RY;
                break;

            case SASteeringWheelEmulationAxisType.RY:
                cont.LeftThumbX  = state.LX;
                cont.LeftThumbY  = state.LY;
                cont.RightThumbX = state.RX;
                cont.RightThumbY = (byte)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();
        }