コード例 #1
0
ファイル: GameCube.cs プロジェクト: DonnyCodes/NintendoSharp
        static public ControllerState ReadFromPacket(byte[] packet)
        {
            if (packet.Length < PACKET_SIZE)
            {
                return(null);
            }

            var state = new ControllerStateBuilder();

            for (int i = 0; i < BUTTONS.Length; ++i)
            {
                if (string.IsNullOrEmpty(BUTTONS [i]))
                {
                    continue;
                }
                state.SetButton(BUTTONS[i], packet[i] != 0x00);
            }

            state.SetAnalog("lstick_x", readStick(SignalTool.readByte(packet, BUTTONS.Length)));
            state.SetAnalog("lstick_y", readStick(SignalTool.readByte(packet, BUTTONS.Length + 8)));
            state.SetAnalog("cstick_x", readStick(SignalTool.readByte(packet, BUTTONS.Length + 16)));
            state.SetAnalog("cstick_y", readStick(SignalTool.readByte(packet, BUTTONS.Length + 24)));
            state.SetAnalog("trig_l", readTrigger(SignalTool.readByte(packet, BUTTONS.Length + 32)));
            state.SetAnalog("trig_r", readTrigger(SignalTool.readByte(packet, BUTTONS.Length + 40)));

            return(state.Build());
        }
コード例 #2
0
        static public ControllerState ReadFromPacket(byte[] packet)
        {
            if (packet.Length < PACKET_SIZE)
            {
                return(null);
            }

            byte[] data = new byte[PACKET_SIZE / 8];
            for (int i = 0; i < PACKET_SIZE / 8; i++)
            {
                data[i] = unencrypt(SignalTool.readByte(packet, i * 8));
            }

            var state = new ControllerStateBuilder();

            for (int i = 0; i < BUTTONS.Length; ++i)
            {
                if (string.IsNullOrEmpty(BUTTONS[i]))
                {
                    continue;
                }
                state.SetButton(BUTTONS[i], (data[4 + i / 8] & (0x01 << (i % 8))) == 0x00);
            }

            state.SetAnalog("lstick_x", readLeftStick(data[0] & 0x3F));
            state.SetAnalog("lstick_y", readLeftStick(data[1] & 0x3F));
            state.SetAnalog("rstick_x", readRightStick(((data[0] & 0xC0) >> 3) | ((data[1] & 0xC0) >> 5) | ((data[2] & 0x80) >> 7)));
            state.SetAnalog("rstick_y", readRightStick(data[2] & 0x1F));
            state.SetAnalog("trig_l", readTrigger(((data[2] & 0x60) >> 2) | ((data[3] & 0xE0) >> 5)));
            state.SetAnalog("trig_r", readTrigger(data[3] & 0x1F));

            return(state.Build());
        }
コード例 #3
0
        void tick(object sender, EventArgs e)
        {
            if (_joystick.Poll().IsFailure)
            {
                Finish();
                if (ControllerDisconnected != null)
                {
                    ControllerDisconnected(this, EventArgs.Empty);
                }
                return;
            }

            var outState = new ControllerStateBuilder();
            var state    = _joystick.GetCurrentState();

            for (int i = 0; i < _joystick.Capabilities.ButtonCount; ++i)
            {
                outState.SetButton("b" + i.ToString(), state.IsPressed(i));
            }

            int[] pov = state.GetPointOfViewControllers();

            outState.SetButton("up", false);
            outState.SetButton("right", false);
            outState.SetButton("down", false);
            outState.SetButton("left", false);

            if (pov != null && pov.Length > 0 && pov[0] >= 0)
            {
                outState.SetButton("up", pov[0] > octantAngle(6) || pov[0] < octantAngle(1));
                outState.SetButton("right", pov[0] > octantAngle(0) && pov[0] < octantAngle(3));
                outState.SetButton("down", pov[0] > octantAngle(2) && pov[0] < octantAngle(5));
                outState.SetButton("left", pov[0] > octantAngle(4) && pov[0] < octantAngle(7));
            }

            outState.SetAnalog("x", (float)state.X / RANGE);
            outState.SetAnalog("y", (float)state.Y / RANGE);
            outState.SetAnalog("z", (float)state.Z / RANGE);
            outState.SetAnalog("rx", (float)state.RotationX / RANGE);
            outState.SetAnalog("ry", (float)state.RotationY / RANGE);
            outState.SetAnalog("rz", (float)state.RotationZ / RANGE);

            if (ControllerStateChanged != null)
            {
                ControllerStateChanged(this, outState.Build());
            }
        }
コード例 #4
0
        void tick(object sender, EventArgs e)
        {
            var state = new XInputState();

            if (XInputDLL.XInputGetState(_id, ref state) > 0)
            {
                if (ControllerDisconnected != null)
                {
                    ControllerDisconnected(this, EventArgs.Empty);
                }
                Finish();
                return;
            }

            var outState = new ControllerStateBuilder();

            outState.SetButton("a", (state.wButtons & 0x1000) != 0);
            outState.SetButton("b", (state.wButtons & 0x2000) != 0);
            outState.SetButton("x", (state.wButtons & 0x4000) != 0);
            outState.SetButton("y", (state.wButtons & 0x8000) != 0);
            outState.SetButton("up", (state.wButtons & 0x0001) != 0);
            outState.SetButton("down", (state.wButtons & 0x0002) != 0);
            outState.SetButton("left", (state.wButtons & 0x0004) != 0);
            outState.SetButton("right", (state.wButtons & 0x0008) != 0);
            outState.SetButton("start", (state.wButtons & 0x0010) != 0);
            outState.SetButton("back", (state.wButtons & 0x0020) != 0);
            outState.SetButton("l3", (state.wButtons & 0x0040) != 0);
            outState.SetButton("r3", (state.wButtons & 0x0080) != 0);
            outState.SetButton("l", (state.wButtons & 0x0100) != 0);
            outState.SetButton("r", (state.wButtons & 0x0200) != 0);

            outState.SetAnalog("lstick_x", (float)state.sThumbLX / 32768);
            outState.SetAnalog("lstick_y", (float)state.sThumbLY / 32768);
            outState.SetAnalog("rstick_x", (float)state.sThumbRX / 32768);
            outState.SetAnalog("rstick_y", (float)state.sThumbRY / 32768);
            outState.SetAnalog("trig_l", (float)state.bLeftTrigger / 255);
            outState.SetAnalog("trig_r", (float)state.bRightTrigger / 255);

            if (ControllerStateChanged != null)
            {
                ControllerStateChanged(this, outState.Build());
            }
        }
コード例 #5
0
        static ControllerState readPacketButtons(byte[] packet, string[] buttons)
        {
            if (packet.Length < buttons.Length)
            {
                return(null);
            }

            var state = new ControllerStateBuilder();

            for (int i = 0; i < buttons.Length; ++i)
            {
                if (string.IsNullOrEmpty(buttons [i]))
                {
                    continue;
                }
                state.SetButton(buttons[i], packet[i] != 0x00);
            }

            return(state.Build());
        }