Ejemplo n.º 1
0
        protected override bool Parse(byte[] ev)
        {
            // A B Z START
            _buttons[0] = (ev[1] & 0x10) != 0;
            _buttons[1] = (ev[1] & 0x20) != 0;
            _buttons[2] = (ev[1] & 0x40) != 0;
            _buttons[3] = (ev[1] & 0x80) != 0;

            // _ _ L R CUP CDOWN CLEFT CRIGHT
            _buttons[4] = (ev[2] & 0x01) != 0;
            _buttons[5] = (ev[2] & 0x02) != 0;
            _buttons[6] = (ev[2] & 0x04) != 0;
            _buttons[7] = (ev[2] & 0x08) != 0;
            _buttons[8] = (ev[2] & 0x10) != 0;
            _buttons[9] = (ev[2] & 0x20) != 0;

            // UP DOWN LEFT RIGHT
            Hat hat = ControllerState.HatLookup[(byte)(ev[1] & 0x0F)];

            _hats[0] = hat;

            _buttons[10] = hat.HasFlag(Hat.Up);
            _buttons[11] = hat.HasFlag(Hat.Down);
            _buttons[12] = hat.HasFlag(Hat.Left);
            _buttons[13] = hat.HasFlag(Hat.Right);

            _axes[0] = (ev[3] - 128) / 128.0;
            _axes[1] = (ev[4] - 128) / 128.0;

            return(true);
        }
Ejemplo n.º 2
0
        protected override bool Parse(byte[] ev)
        {
            // B Y SEL START
            int i = 0, mask = 0x10;

            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;

            // A X L R
            mask          = 0x10;
            _buttons[i++] = (ev[2] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[2] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[2] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[2] & mask) != 0; mask <<= 1;

            // UP DOWN LEFT RIGHT
            Hat hat = ControllerState.HatLookup[(byte)(ev[1] & 0x0F)];

            _hats[0] = hat;

            _buttons[i++] = hat.HasFlag(Hat.Up);
            _buttons[i++] = hat.HasFlag(Hat.Down);
            _buttons[i++] = hat.HasFlag(Hat.Left);
            _buttons[i++] = hat.HasFlag(Hat.Right);

            return(true);
        }
Ejemplo n.º 3
0
        protected override bool Parse(byte[] ev)
        {
            // 0 0 0 START Y X B A
            _buttons[0] = (ev[1] & 0x01) != 0;
            _buttons[1] = (ev[1] & 0x02) != 0;
            _buttons[2] = (ev[1] & 0x04) != 0;
            _buttons[3] = (ev[1] & 0x08) != 0;
            _buttons[4] = (ev[1] & 0x10) != 0;

            // L R Z
            _buttons[5] = (ev[2] & 0x10) != 0;
            _buttons[6] = (ev[2] & 0x20) != 0;
            _buttons[7] = (ev[2] & 0x40) != 0;

            // HAT, convert first
            Hat hat = ControllerState.HatLookup[(byte)(ev[2] & 0x0F)];

            _hats[0] = hat;

            // UP DOWN LEFT RIGHT
            _buttons[8]  = hat.HasFlag(Hat.Up);
            _buttons[9]  = hat.HasFlag(Hat.Down);
            _buttons[10] = hat.HasFlag(Hat.Left);
            _buttons[11] = hat.HasFlag(Hat.Right);

            _axes[0] = (ev[3] - 128) / 128.0;
            _axes[1] = (ev[4] - 128) / 128.0;
            _axes[2] = ev[7] / 256.0;
            _axes[3] = (ev[5] - 128) / 128.0;
            _axes[4] = (ev[6] - 128) / 128.0;
            _axes[5] = ev[8] / 256.0;

            return(true);
        }
Ejemplo n.º 4
0
        protected override bool Parse(List <byte> buffer)
        {
            if (buffer.Count != 64)
            {
                return(false);
            }
            var packet = Repack(buffer);

            // 0 0 0 START Y X B A
            _buttons[0] = (packet[0] & 0x01) != 0;
            _buttons[1] = (packet[0] & 0x02) != 0;
            _buttons[2] = (packet[0] & 0x04) != 0;
            _buttons[3] = (packet[0] & 0x08) != 0;
            _buttons[4] = (packet[0] & 0x10) != 0;

            // L R Z
            _buttons[5] = (packet[1] & 0x10) != 0;
            _buttons[6] = (packet[1] & 0x20) != 0;
            _buttons[7] = (packet[1] & 0x40) != 0;

            byte bhat = (byte)(packet[1] & 0x0F);
            Hat  hat  = Hat.None;

            if ((bhat & 0x01) != 0)
            {
                hat |= Hat.Left;
            }
            if ((bhat & 0x02) != 0)
            {
                hat |= Hat.Right;
            }
            if ((bhat & 0x04) != 0)
            {
                hat |= Hat.Down;
            }
            if ((bhat & 0x08) != 0)
            {
                hat |= Hat.Up;
            }
            _hats[0] = hat;

            _buttons[8]  = hat.HasFlag(Hat.Up);
            _buttons[9]  = hat.HasFlag(Hat.Down);
            _buttons[10] = hat.HasFlag(Hat.Left);
            _buttons[11] = hat.HasFlag(Hat.Right);

            _axes[0] = packet[2] - 128;
            _axes[1] = 128 - packet[3];
            _axes[2] = packet[6];
            _axes[3] = packet[7];
            _axes[4] = 128 - packet[5];
            _axes[5] = packet[4] - 128;

            return(true);
        }
Ejemplo n.º 5
0
        protected override bool Parse(List <byte> buffer)
        {
            if (buffer.Count != 32)
            {
                return(false);
            }
            var packet = Repack(buffer);

            // A B Z START
            _buttons[0] = (packet[0] & 0x10) != 0;
            _buttons[1] = (packet[0] & 0x20) != 0;
            _buttons[2] = (packet[0] & 0x40) != 0;
            _buttons[3] = (packet[0] & 0x80) != 0;

            // _ _ L R CUP CDOWN CLEFT CRIGHT
            _buttons[4] = (packet[1] & 0x01) != 0;
            _buttons[5] = (packet[1] & 0x02) != 0;
            _buttons[6] = (packet[1] & 0x04) != 0;
            _buttons[7] = (packet[1] & 0x08) != 0;
            _buttons[8] = (packet[1] & 0x10) != 0;
            _buttons[9] = (packet[1] & 0x20) != 0;

            byte bhat = (byte)(packet[0] & 0x0F);
            Hat  hat  = Hat.None;

            if ((bhat & 0x01) != 0)
            {
                hat |= Hat.Right;
            }
            if ((bhat & 0x02) != 0)
            {
                hat |= Hat.Left;
            }
            if ((bhat & 0x04) != 0)
            {
                hat |= Hat.Down;
            }
            if ((bhat & 0x08) != 0)
            {
                hat |= Hat.Up;
            }
            _hats[0] = hat;

            _buttons[10] = hat.HasFlag(Hat.Up);
            _buttons[11] = hat.HasFlag(Hat.Down);
            _buttons[12] = hat.HasFlag(Hat.Left);
            _buttons[13] = hat.HasFlag(Hat.Right);

            _axes[0] = (sbyte)packet[2];
            _axes[1] = -(sbyte)packet[3];

            return(true);
        }
Ejemplo n.º 6
0
        protected override bool Parse(byte[] ev)
        {
            byte reportId = ev[0];

            if (reportId > 1)
            {
                return(false);
            }

            // cross square circle triangle select start lstick rstick
            int i = 0, mask = 0x01;

            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;

            // l1, r1, l2, r2
            mask          = 0x01;
            _buttons[i++] = (ev[2] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[2] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[2] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[2] & mask) != 0; mask <<= 1;

            // UP DOWN LEFT RIGHT
            Hat hat = ControllerState.HatLookup[(byte)(ev[2] >> 4)];

            _hats[0] = hat;

            _buttons[i++] = hat.HasFlag(Hat.Up);
            _buttons[i++] = hat.HasFlag(Hat.Down);
            _buttons[i++] = hat.HasFlag(Hat.Left);
            _buttons[i++] = hat.HasFlag(Hat.Right);

            _axes[0] = (ev[3] - 128) / 128.0;
            _axes[1] = (ev[4] - 128) / 128.0;
            // axis 2 would be for trigger 1
            _axes[3] = (ev[5] - 128) / 128.0;
            _axes[4] = (ev[6] - 128) / 128.0;
            // axis 5 would be for trigger 2

            bool pressureValuesIncluded = ev.Length >= 18 && (ev[7] & 0x01) == 0x01;

            for (i = 6; i < 18; i++)
            {
                _axes[i] = pressureValuesIncluded ? (ev[i + 2] / 255.0) : 0.0;
            }
            return(true);
        }
Ejemplo n.º 7
0
        protected override bool Parse(List <byte> buffer)
        {
            if (buffer.Count != 16)
            {
                return(false);
            }
            var packet = Repack(buffer);

            // B Y SEL START
            int i = 0, mask = 0x10;

            _buttons[i++] = (packet[0] & mask) != 0; mask <<= 1;
            _buttons[i++] = (packet[0] & mask) != 0; mask <<= 1;
            _buttons[i++] = (packet[0] & mask) != 0; mask <<= 1;
            _buttons[i++] = (packet[0] & mask) != 0; mask <<= 1;

            // A X L R
            mask          = 0x10;
            _buttons[i++] = (packet[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (packet[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (packet[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (packet[1] & mask) != 0; mask <<= 1;

            byte bhat = (byte)(packet[0] & 0x0F);
            Hat  hat  = Hat.None;

            // inverted order UP DOWN LEFT RIGHT
            if ((bhat & 0x01) != 0)
            {
                hat |= Hat.Right;
            }
            if ((bhat & 0x02) != 0)
            {
                hat |= Hat.Left;
            }
            if ((bhat & 0x04) != 0)
            {
                hat |= Hat.Down;
            }
            if ((bhat & 0x08) != 0)
            {
                hat |= Hat.Up;
            }
            _hats[0] = hat;

            _buttons[i++] = hat.HasFlag(Hat.Up);
            _buttons[i++] = hat.HasFlag(Hat.Down);
            _buttons[i++] = hat.HasFlag(Hat.Left);
            _buttons[i++] = hat.HasFlag(Hat.Right);

            return(true);
        }
Ejemplo n.º 8
0
        protected override bool Parse(byte[] ev)
        {
            byte reportId = ev[0];

            if (reportId > 1)
            {
                return(false);
            }

            // cross square circle triangle select start lstick rstick
            int i = 0, mask = 0x01;

            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[1] & mask) != 0; mask <<= 1;

            // l1, r1, l2, r2
            mask          = 0x01;
            _buttons[i++] = (ev[2] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[2] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[2] & mask) != 0; mask <<= 1;
            _buttons[i++] = (ev[2] & mask) != 0; mask <<= 1;

            // UP DOWN LEFT RIGHT
            Hat hat = ControllerState.HatLookup[(byte)(ev[2] >> 4)];

            _hats[0] = hat;

            _buttons[i++] = hat.HasFlag(Hat.Up);
            _buttons[i++] = hat.HasFlag(Hat.Down);
            _buttons[i++] = hat.HasFlag(Hat.Left);
            _buttons[i++] = hat.HasFlag(Hat.Right);

            _axes[0] = (ev[3] - 128) / 128.0;
            _axes[1] = (ev[4] - 128) / 128.0;
            // axis 2 would be for trigger 1
            _axes[3] = (ev[5] - 128) / 128.0;
            _axes[4] = (ev[6] - 128) / 128.0;
            // axis 5 would be for trigger 2

            return(true);
        }