示例#1
0
        private bool XOutputSetState(int UserIndex, Gamepad_state Gamepad)
        {
            bool OUT = false;

            if (UserIndex < 1 || UserIndex > 4)
            {
                return(OUT);
            }

            if (_hBus == new IntPtr(INVALID_HANDLE_VALUE))
            {
                _hBus = GetVXbusHandle();
            }
            if (_hBus == new IntPtr(INVALID_HANDLE_VALUE))
            {
                return(false);
            }

            int Transfered = 0;

            byte[] buffer = new byte[28];

            buffer[0] = 0x1C;

            // encode user index
            buffer[4] = (byte)((UserIndex >> 0) & 0xFF);
            buffer[5] = (byte)((UserIndex >> 8) & 0xFF);
            buffer[6] = (byte)((UserIndex >> 16) & 0xFF);
            buffer[7] = (byte)((UserIndex >> 24) & 0xFF);

            buffer[9] = 0x14;
            Array.Copy(Gamepad.Buffer, 0, buffer, 10, Gamepad.Buffer.Length);

            // vibration and LED info end up here
            byte[] output = new byte[FEEDBACK_BUFFER_LENGTH];

            // send report to bus, receive vibration and LED status
            if (!DeviceIoControl(_hBus, (int)MessageType.Report, buffer, (uint)buffer.Length, output, FEEDBACK_BUFFER_LENGTH, ref Transfered, IntPtr.Zero))
            {
                _Win32Error = 0;
                return(false);
            }

            return(true);
        }
示例#2
0
        /// <summary>
        /// Plug a virtual Controller on one of the user port.
        /// Port are from 1 to 4, and are not the same as Player ID of
        /// the gamepad (LED Number)
        /// </summary>
        /// <param name="UserIndex">Virtual port on which the GamePad should be plugged</param>
        /// <returns>
        /// True if succes.
        /// False if failed or port already used</returns>
        public bool PlugIn(int UserIndex)
        {
            bool OUT = false;

            if (UserIndex < 1 || UserIndex > 4)
            {
                return(OUT);
            }

            if (_hBus == new IntPtr(INVALID_HANDLE_VALUE))
            {
                _hBus = GetVXbusHandle();
            }
            if (_hBus == new IntPtr(INVALID_HANDLE_VALUE))
            {
                return(false);
            }

            int Transfered = 0;

            byte[] buffer = new byte[16];
            buffer[0] = 0x10;
            buffer[4] = (byte)((UserIndex >> 0) & 0xFF);
            buffer[5] = (byte)((UserIndex >> 8) & 0xFF);
            buffer[6] = (byte)((UserIndex >> 16) & 0xFF);
            buffer[8] = (byte)((UserIndex >> 24) & 0xFF);

            if (DeviceIoControl(_hBus, (int)MessageType.Plugin, buffer, 16, null, 0, ref Transfered, IntPtr.Zero))
            {
                _Gamepads[UserIndex - 1] = new Gamepad_state();
                OUT = true;
            }

            _Win32Error = 0;
            if (!OUT)
            {
                _Win32Error = Marshal.GetLastWin32Error();
            }

            return(OUT);
        }
示例#3
0
        private bool XOutputSetGetState(int UserIndex, Gamepad_state Gamepad, byte[] bVibrate, byte[] bLargeMotor, byte[] bSmallMotor, byte[] bLed)
        {
            bool OUT = false;

            if (UserIndex < 1 || UserIndex > 4)
            {
                return(OUT);
            }

            if (_Gamepads[UserIndex - 1] == null)
            {
                return(OUT);
            }

            int Transfered = 0;

            byte[] Buffer = new byte[28];

            Buffer[0] = 0x1C;

            // encode user index
            Buffer[4] = (byte)((UserIndex >> 0) & 0xFF);
            Buffer[5] = (byte)((UserIndex >> 8) & 0xFF);
            Buffer[6] = (byte)((UserIndex >> 16) & 0xFF);
            Buffer[7] = (byte)((UserIndex >> 24) & 0xFF);

            Buffer[9] = 0x14;

            // concat gamepad info to buffer
            Array.Copy(Gamepad.Buffer, 0, Buffer, 10, Gamepad.Buffer.Length);

            // vibration and LED info end up here
            byte[] Output = new byte[FEEDBACK_BUFFER_LENGTH];

            // send report to bus, receive vibration and LED status
            if (!DeviceIoControl(_hBus, (int)MessageType.Report, Buffer, (uint)Buffer.Length, Output, FEEDBACK_BUFFER_LENGTH, ref Transfered, IntPtr.Zero))
            {
                return(false);
            }

            // cache feedback

            /*if (bVibrate != null)
             * {
             * bVibrate = (output[1] == 0x08) ? 0x01 : 0x00;
             * }
             *
             * if (bLargeMotor != null)
             * {
             * bLargeMotor = output[3];
             * }
             *
             * if (bSmallMotor != null)
             * {
             * bSmallMotor = output[4];
             * }
             *
             * if (bLed != null)
             * {
             * bLed = output[8];
             * }*/

            return(true);
        }