Beispiel #1
0
        protected override void ParseHidReport(byte[] report)
        {
            if (report[1] != 0x01)
            {
                return;
            }

            PacketCounter++;

            #region HID Report translation

            // no battery state since the Gamepad is USB-powered
            m_BatteryStatus = InputReport.SetBatteryStatus(DsBattery.None);

            // packet counter
            InputReport.PacketCounter = PacketCounter;

            // set fake MAC address
            InputReport.PadMacAddress = PhysicalAddress.Parse(m_Mac.Replace(":", string.Empty));

            // reset buttons
            InputReport.ZeroSelectStartButtonsState();
            InputReport.ZeroShoulderButtonsState();

            InputReport.Set(Ds3Button.Select, IsBitSet(report[7], 4));   // Select
            InputReport.Set(Ds3Button.Start, IsBitSet(report[7], 5));    // Start

            InputReport.Set(Ds3Button.L1, IsBitSet(report[7], 0));       // L1 (button)
            InputReport.Set(Ds3Button.R1, IsBitSet(report[7], 2));       // R1 (button)

            InputReport.Set(Ds3Button.Triangle, IsBitSet(report[6], 4)); // Triangle (button)
            InputReport.Set(Ds3Button.Circle, IsBitSet(report[6], 5));   // Circle (button)
            InputReport.Set(Ds3Button.Cross, IsBitSet(report[6], 6));    // Cross (button)
            InputReport.Set(Ds3Button.Square, IsBitSet(report[6], 7));   // Square (button)

            InputReport.Set(Ds3Button.Right, (report[4] == 0xFF));       // D-Pad right
            InputReport.Set(Ds3Button.Left, (report[4] == 0x00));        // D-Pad left
            InputReport.Set(Ds3Button.Up, (report[5] == 0x00));          // D-Pad up
            InputReport.Set(Ds3Button.Down, (report[5] == 0xFF));        // D-Pad down

            // This device has no thumb sticks, center axes
            InputReport.Set(Ds3Axis.Lx, 0x80);
            InputReport.Set(Ds3Axis.Ly, 0x80);
            InputReport.Set(Ds3Axis.Rx, 0x80);
            InputReport.Set(Ds3Axis.Ry, 0x80);

            #endregion

            OnHidReportReceived();
        }
Beispiel #2
0
        protected override void ParseHidReport(byte[] report)
        {
            if (report[5] != 0x00)
            {
                return;
            }

            PacketCounter++;

            #region HID Report translation

            // no battery state since the Gamepad is USB-powered
            m_BatteryStatus = InputReport.SetBatteryStatus(DsBattery.None);

            // packet counter
            InputReport.PacketCounter = PacketCounter;

            InputReport.Set(Ds3Button.Triangle, IsBitSet(report[6], 4));
            InputReport.Set(Ds3Button.Circle, IsBitSet(report[6], 5));
            InputReport.Set(Ds3Button.Cross, IsBitSet(report[6], 6));
            InputReport.Set(Ds3Button.Square, IsBitSet(report[6], 7));

            InputReport.Set(Ds3Button.Select, IsBitSet(report[7], 4));
            InputReport.Set(Ds3Button.Start, IsBitSet(report[7], 5));

            InputReport.Set(Ds3Button.Up, (report[4] == 0x00));
            InputReport.Set(Ds3Button.Right, (report[3] == 0xFF));
            InputReport.Set(Ds3Button.Down, (report[4] == 0xFF));
            InputReport.Set(Ds3Button.Left, (report[3] == 0x00));

            InputReport.Set(Ds3Button.L1, IsBitSet(report[7], 0));
            InputReport.Set(Ds3Button.R1, IsBitSet(report[7], 1));
            InputReport.Set(Ds3Button.L2, IsBitSet(report[7], 2));
            InputReport.Set(Ds3Button.R2, IsBitSet(report[7], 3));

            InputReport.Set(Ds3Button.L3, IsBitSet(report[7], 6));
            InputReport.Set(Ds3Button.R3, IsBitSet(report[7], 7));

            // TODO: the PS-button is dead according to the report:
            // http://forums.pcsx2.net/attachment.php?aid=57420

            #endregion

            OnHidReportReceived();
        }
        protected override void ParseHidReport(byte[] report)
        {
            if (report[2] != 0x00)
            {
                return;
            }

            if (PacketCounter++ + 1 < PacketCounter)
            {
                Log.WarnFormat("Packet counter rolled over ({0}), resetting to 0", PacketCounter);
                PacketCounter = 0;
            }

            #region HID Report translation

            // no battery state since the Gamepad is USB-powered
            m_BatteryStatus = InputReport.SetBatteryStatus(DsBattery.None);

            // packet counter
            InputReport.PacketCounter = PacketCounter;

            // set fake MAC address
            InputReport.PadMacAddress = PhysicalAddress.Parse(m_Mac.Replace(":", string.Empty));

            // null button states
            InputReport.ZeroPsButtonState();
            InputReport.ZeroSelectStartButtonsState();
            InputReport.ZeroShoulderButtonsState();

            // control buttons
            InputReport.Set(Ds3Button.Select, IsBitSet(report[6], 4));
            InputReport.Set(Ds3Button.Start, IsBitSet(report[6], 5));

            // Left shoulder
            InputReport.Set(Ds3Button.L1, IsBitSet(report[6], 0));

            // Right shoulder
            InputReport.Set(Ds3Button.R1, IsBitSet(report[6], 1));

            // Left trigger
            InputReport.Set(Ds3Button.L2, IsBitSet(report[6], 2));

            // Right trigger
            InputReport.Set(Ds3Button.R2, IsBitSet(report[6], 3));

            // Triangle
            InputReport.Set(Ds3Button.Triangle, IsBitSet(report[5], 4));

            // Circle
            InputReport.Set(Ds3Button.Circle, IsBitSet(report[5], 5));

            // Cross
            InputReport.Set(Ds3Button.Cross, IsBitSet(report[5], 6));

            // Square
            InputReport.Set(Ds3Button.Square, IsBitSet(report[5], 7));

            // Left thumb
            InputReport.Set(Ds3Button.L3, IsBitSet(report[6], 6));
            // Right thumb
            InputReport.Set(Ds3Button.R3, IsBitSet(report[6], 7));

            var dPad = (byte)(report[5] & ~0xF0);

            // D-Pad
            switch (dPad)
            {
            case 0:
                InputReport.Set(Ds3Button.Up);
                break;

            case 1:
                InputReport.Set(Ds3Button.Up);
                InputReport.Set(Ds3Button.Right);
                break;

            case 2:
                InputReport.Set(Ds3Button.Right);
                break;

            case 3:
                InputReport.Set(Ds3Button.Right);
                InputReport.Set(Ds3Button.Down);
                break;

            case 4:
                InputReport.Set(Ds3Button.Down);
                break;

            case 5:
                InputReport.Set(Ds3Button.Down);
                InputReport.Set(Ds3Button.Left);
                break;

            case 6:
                InputReport.Set(Ds3Button.Left);
                break;

            case 7:
                InputReport.Set(Ds3Button.Left);
                InputReport.Set(Ds3Button.Up);
                break;
            }

            // Left thumb stick
            InputReport.Set(Ds3Axis.Lx, report[0]);
            InputReport.Set(Ds3Axis.Ly, report[1]);

            // Right thumb stick
            InputReport.Set(Ds3Axis.Rx, report[3]);
            InputReport.Set(Ds3Axis.Ry, report[4]);

            #endregion

            OnHidReportReceived();
        }
        protected override void ParseHidReport(byte[] report)
        {
            if (report[8] != 0xC0 && report[8] != 0x40)
            {
                return;
            }

            PacketCounter++;

            #region HID Report translation

            // no battery state since the Gamepad is USB-powered
            m_BatteryStatus = InputReport.SetBatteryStatus(DsBattery.None);

            // packet counter
            InputReport.PacketCounter = PacketCounter;

            // set fake MAC address
            InputReport.PadMacAddress = PhysicalAddress.Parse(m_Mac.Replace(":", string.Empty));

            // reset buttons
            InputReport.ZeroSelectStartButtonsState();
            InputReport.ZeroShoulderButtonsState();

            // buttons equaly reported in both modes
            InputReport.Set(Ds3Button.Circle, IsBitSet(report[6], 5));
            InputReport.Set(Ds3Button.Cross, IsBitSet(report[6], 6));
            InputReport.Set(Ds3Button.Triangle, IsBitSet(report[6], 4));
            InputReport.Set(Ds3Button.Square, IsBitSet(report[6], 7));

            InputReport.Set(Ds3Button.Select, IsBitSet(report[7], 4));
            InputReport.Set(Ds3Button.Start, IsBitSet(report[7], 5));

            InputReport.Set(Ds3Button.L1, IsBitSet(report[7], 0));
            InputReport.Set(Ds3Button.R1, IsBitSet(report[7], 1));
            InputReport.Set(Ds3Button.L2, IsBitSet(report[7], 2));
            InputReport.Set(Ds3Button.R2, IsBitSet(report[7], 3));

            InputReport.Set(Ds3Button.L3, IsBitSet(report[7], 6));
            InputReport.Set(Ds3Button.R3, IsBitSet(report[7], 7));

            // detect mode it's running in
            switch (report[8])
            {
            case 0xC0:     // mode 1
            {
                InputReport.Set(Ds3Button.Up, (report[2] == 0x00));
                InputReport.Set(Ds3Button.Right, (report[1] == 0xFF));
                InputReport.Set(Ds3Button.Down, (report[2] == 0xFF));
                InputReport.Set(Ds3Button.Left, (report[1] == 0x00));

                // mode 1 doesn't report the thumb sticks
                InputReport.Set(Ds3Axis.Lx, 0x80);
                InputReport.Set(Ds3Axis.Ly, 0x80);
                InputReport.Set(Ds3Axis.Rx, 0x80);
                InputReport.Set(Ds3Axis.Ry, 0x80);
            }
            break;

            case 0x40:     // mode 2
            {
                var dPad = (byte)(report[6] & ~0xF0);

                switch (dPad)
                {
                case 0:
                    InputReport.Set(Ds3Button.Up);
                    break;

                case 1:
                    InputReport.Set(Ds3Button.Up);
                    InputReport.Set(Ds3Button.Right);
                    break;

                case 2:
                    InputReport.Set(Ds3Button.Right);
                    break;

                case 3:
                    InputReport.Set(Ds3Button.Right);
                    InputReport.Set(Ds3Button.Down);
                    break;

                case 4:
                    InputReport.Set(Ds3Button.Down);
                    break;

                case 5:
                    InputReport.Set(Ds3Button.Down);
                    InputReport.Set(Ds3Button.Left);
                    break;

                case 6:
                    InputReport.Set(Ds3Button.Left);
                    break;

                case 7:
                    InputReport.Set(Ds3Button.Left);
                    InputReport.Set(Ds3Button.Up);
                    break;
                }

                InputReport.Set(Ds3Axis.Lx, report[1]);
                InputReport.Set(Ds3Axis.Ly, report[2]);

                InputReport.Set(Ds3Axis.Rx, report[4]);
                InputReport.Set(Ds3Axis.Ry, report[5]);
            }
            break;
            }

            #endregion

            OnHidReportReceived();
        }
Beispiel #5
0
        /// <summary>
        ///     Interprets a HID report sent by a DualShock 4 device.
        /// </summary>
        /// <param name="report">The HID report as byte array.</param>
        protected override void ParseHidReport(byte[] report)
        {
            if (report[0] != 0x01)
            {
                return;
            }

            PacketCounter++;

            m_BatteryStatus = InputReport.SetBatteryStatus((DsBattery)MapBattery(report[30]));

            InputReport.PacketCounter = PacketCounter;

            var buttons = ((report[5] << 0) | (report[6] << 8) | (report[7] << 16));

            #region Convert HAT to DPAD

            report[5] &= 0xF0;

            switch ((uint)buttons & 0xF)
            {
            case 0:
                report[5] |= (byte)Ds4Button.Up.Offset;
                break;

            case 1:
                report[5] |= (byte)(Ds4Button.Up.Offset | Ds4Button.Right.Offset);
                break;

            case 2:
                report[5] |= (byte)Ds4Button.Right.Offset;
                break;

            case 3:
                report[5] |= (byte)(Ds4Button.Right.Offset | Ds4Button.Down.Offset);
                break;

            case 4:
                report[5] |= (byte)(Ds4Button.Down.Offset);
                break;

            case 5:
                report[5] |= (byte)(Ds4Button.Down.Offset | Ds4Button.Left.Offset);
                break;

            case 6:
                report[5] |= (byte)Ds4Button.Left.Offset;
                break;

            case 7:
                report[5] |= (byte)(Ds4Button.Left.Offset | Ds4Button.Up.Offset);
                break;
            }

            #endregion

            // copy controller data to report packet
            Buffer.BlockCopy(report, 0, InputReport.RawBytes, 8, 64);

            OnHidReportReceived();
        }