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

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

            var inputReport = new HidReport.Core.HidReport();

            #region HID Report translation

            // no battery state since the Gamepad is Usb-powered
            inputReport.BatteryStatus = DsBattery.None;

            // packet counter
            inputReport.PacketCounter = PacketCounter;

            inputReport.Set(ButtonsEnum.Circle, IsBitSet(report[5], 5));
            inputReport.Set(ButtonsEnum.Cross, IsBitSet(report[5], 6));

            inputReport.Set(ButtonsEnum.Select, IsBitSet(report[6], 4));
            inputReport.Set(ButtonsEnum.Start, IsBitSet(report[6], 5));

            var dPad = (byte)(report[5] & ~0xF0);
            HidParsers.ParseDPad(dPad, inputReport);

            inputReport.Set(ButtonsEnum.Triangle, IsBitSet(report[5], 4));
            inputReport.Set(ButtonsEnum.Square, IsBitSet(report[5], 7));

            inputReport.Set(ButtonsEnum.L1, IsBitSet(report[6], 0));
            inputReport.Set(ButtonsEnum.R1, IsBitSet(report[6], 1));

            inputReport.Set(ButtonsEnum.L2, IsBitSet(report[6], 2));
            inputReport.Set(ButtonsEnum.R2, IsBitSet(report[6], 3));

            inputReport.Set(ButtonsEnum.L3, IsBitSet(report[6], 6));
            inputReport.Set(ButtonsEnum.R3, IsBitSet(report[6], 7));

            inputReport.Set(AxesEnum.Lx, report[3]);
            inputReport.Set(AxesEnum.Ly, report[4]);

            inputReport.Set(AxesEnum.Rx, report[1]);
            inputReport.Set(AxesEnum.Ry, report[2]);

            #endregion

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

            var inputReport = new HidReport.Core.HidReport();

            #region HID Report translation

            // no battery state since the Gamepad is Usb-powered
            inputReport.BatteryStatus = DsBattery.None;

            // packet counter
            inputReport.PacketCounter = ++PacketCounter;

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

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

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

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

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

            // Triangle
            inputReport.Set(ButtonsEnum.Triangle, IsBitSet(report[5], 4));

            // Circle
            inputReport.Set(ButtonsEnum.Circle, IsBitSet(report[5], 5));

            // Cross
            inputReport.Set(ButtonsEnum.Cross, IsBitSet(report[5], 6));

            // Square
            inputReport.Set(ButtonsEnum.Square, IsBitSet(report[5], 7));

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

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

            // D-Pad
            HidParsers.ParseDPad(dPad, inputReport);

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

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

            #endregion

            OnHidReportReceived(inputReport);
        }
Exemple #3
0
        protected override void ParseHidReport(byte[] report)
        {
            if (report[26] != 0x02)
            {
                return;
            }

            PacketCounter++;

            var inputReport = new HidReport.Core.HidReport();

            #region HID Report translation

            // battery
            inputReport.BatteryStatus = (DsBattery)report[30];

            // packet counter
            inputReport.PacketCounter = PacketCounter;

            // control buttons
            inputReport.Set(ButtonsEnum.Ps, IsBitSet(report[1], 4));
            inputReport.Set(ButtonsEnum.Select, IsBitSet(report[1], 0));
            inputReport.Set(ButtonsEnum.Start, IsBitSet(report[1], 1));

            // Left shoulder
            inputReport.Set(ButtonsEnum.L1, IsBitSet(report[0], 4));
            inputReport.Set(AxesEnum.L1, report[15]);

            // Right shoulder
            inputReport.Set(ButtonsEnum.R1, IsBitSet(report[0], 5));
            inputReport.Set(AxesEnum.R1, report[16]);

            // Left trigger
            inputReport.Set(ButtonsEnum.L2, IsBitSet(report[0], 6));
            inputReport.Set(AxesEnum.L2, report[17]);

            // Right trigger
            inputReport.Set(ButtonsEnum.R2, IsBitSet(report[0], 7));
            inputReport.Set(AxesEnum.R2, report[18]);

            // Triangle
            inputReport.Set(ButtonsEnum.Triangle, IsBitSet(report[0], 3));
            inputReport.Set(AxesEnum.Triangle, report[11]);

            // Circle
            inputReport.Set(ButtonsEnum.Circle, IsBitSet(report[0], 2));
            inputReport.Set(AxesEnum.Circle, report[12]);

            // Cross
            inputReport.Set(ButtonsEnum.Cross, IsBitSet(report[0], 1));
            inputReport.Set(AxesEnum.Cross, report[13]);

            // Square
            inputReport.Set(ButtonsEnum.Square, IsBitSet(report[0], 0));
            inputReport.Set(AxesEnum.Square, report[14]);

            // Left thumb
            inputReport.Set(ButtonsEnum.L3, IsBitSet(report[1], 2));
            // Right thumb
            inputReport.Set(ButtonsEnum.R3, IsBitSet(report[1], 3));

            // D-Pad
            if (report[2] != 0x0F)
            {
                HidParsers.ParseDPad(report[2], inputReport);
            }

            // Left thumb stick
            inputReport.Set(AxesEnum.Lx, report[3]);
            inputReport.Set(AxesEnum.Ly, report[4]);

            // Right thumb stick
            inputReport.Set(AxesEnum.Rx, report[5]);
            inputReport.Set(AxesEnum.Ry, report[6]);

            #endregion

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

            PacketCounter++;

            var inputReport = new HidReport.Core.HidReport();

            #region HID Report translation

            // no battery state since the Gamepad is Usb-powered
            inputReport.BatteryStatus = DsBattery.None;

            // packet counter
            inputReport.PacketCounter = PacketCounter;

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

            inputReport.Set(ButtonsEnum.Select, IsBitSet(report[7], 4));
            inputReport.Set(ButtonsEnum.Start, IsBitSet(report[7], 5));

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

            inputReport.Set(ButtonsEnum.L3, IsBitSet(report[7], 6));
            inputReport.Set(ButtonsEnum.R3, IsBitSet(report[7], 7));

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

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

            case 0x40:     // mode 2
            {
                var dPad = (byte)(report[6] & ~0xF0);
                HidParsers.ParseDPad(dPad, inputReport);
                inputReport.Set(AxesEnum.Lx, report[1]);
                inputReport.Set(AxesEnum.Ly, report[2]);

                inputReport.Set(AxesEnum.Rx, report[4]);
                inputReport.Set(AxesEnum.Ry, report[5]);
            }
            break;
            }

            #endregion

            OnHidReportReceived(inputReport);
        }