public void checkControllerInput()
        {
            if (_gcapi_Write == null)
            {
                return;
            }

            bool boolOverride = false;

            if (frmMain.boolIDE)
            {
                boolOverride = true;
            }

            if ((_gcapi_IsConnected() == 1) || (boolOverride == true))
            {
                //Update gamepad status
                _controls = GamePad.GetState(PlayerIndex.One);

                if (_XboxCount == 0)
                {
                    _XboxCount = Enum.GetNames(typeof(xbox)).Length;
                }
                byte[] output = new byte[_XboxCount];

                if (_controls.DPad.Left)
                {
                    output[(int)xbox.left] = Convert.ToByte(100);
                }
                if (_controls.DPad.Right)
                {
                    output[(int)xbox.right] = Convert.ToByte(100);
                }
                if (_controls.DPad.Up)
                {
                    output[(int)xbox.up] = Convert.ToByte(100);
                }
                if (_controls.DPad.Down)
                {
                    output[(int)xbox.down] = Convert.ToByte(100);
                }

                if (_controls.Buttons.A)
                {
                    output[(int)xbox.a] = Convert.ToByte(100);
                }
                if (_controls.Buttons.B)
                {
                    output[(int)xbox.b] = Convert.ToByte(100);
                }
                if (_controls.Buttons.X)
                {
                    output[(int)xbox.x] = Convert.ToByte(100);
                }
                if (_controls.Buttons.Y)
                {
                    output[(int)xbox.y] = Convert.ToByte(100);
                }

                if (_controls.Buttons.Start)
                {
                    output[(int)xbox.start] = Convert.ToByte(100);
                }
                if (_controls.Buttons.Guide)
                {
                    output[(int)xbox.home] = Convert.ToByte(100);
                }
                if (_controls.Buttons.Back)
                {
                    if (system.boolBlockMenuButton == false)
                    {
                        _MenuWait++;
                        if (system.boolMenu == false)
                        {
                            if (_MenuWait >= _MenuShow + 20)
                            {
                                openMenu();
                            }
                        }
                    }

                    //Remap back buton to touchpad
                    if (system.boolPS4ControllerMode)
                    {
                        output[(int)xbox.touch] = Convert.ToByte(100);
                    }
                    else
                    {
                        output[(int)xbox.back] = Convert.ToByte(100);
                    }
                }

                if (_controls.Buttons.LeftShoulder)
                {
                    output[(int)xbox.leftShoulder] = Convert.ToByte(100);
                }
                if (_controls.Buttons.RightShoulder)
                {
                    output[(int)xbox.rightShoulder] = Convert.ToByte(100);
                }
                if (_controls.Buttons.LeftStick)
                {
                    output[(int)xbox.leftStick] = Convert.ToByte(100);
                }
                if (_controls.Buttons.RightStick)
                {
                    output[(int)xbox.rightStick] = Convert.ToByte(100);
                }

                if (_controls.Triggers.Left > 0)
                {
                    output[(int)xbox.leftTrigger] = Convert.ToByte(_controls.Triggers.Left * 100);
                }
                if (_controls.Triggers.Right > 0)
                {
                    output[(int)xbox.rightTrigger] = Convert.ToByte(_controls.Triggers.Right * 100);
                }

                double dblLX = _controls.ThumbSticks.Left.X * 100;
                double dblLY = _controls.ThumbSticks.Left.Y * 100;
                double dblRX = _controls.ThumbSticks.Right.X * 100;
                double dblRY = _controls.ThumbSticks.Right.Y * 100;

                if (system.boolNormalizeControls == true)
                {
                    normalGamepad(ref dblLX, ref dblLY);
                    normalGamepad(ref dblRX, ref dblRY);
                }
                else
                {
                    dblLY = -dblLY;
                    dblRY = -dblRY;
                }

                if (dblLX != 0)
                {
                    output[(int)xbox.leftX] = (byte)Convert.ToSByte((int)(dblLX));
                }
                if (dblLY != 0)
                {
                    output[(int)xbox.leftY] = (byte)Convert.ToSByte((int)(dblLY));
                }
                if (dblRX != 0)
                {
                    output[(int)xbox.rightX] = (byte)Convert.ToSByte((int)(dblRX));
                }
                if (dblRY != 0)
                {
                    output[(int)xbox.rightY] = (byte)Convert.ToSByte((int)(dblRY));
                }

                if (CMHomeCount > 0)
                {
                    output[(int)xbox.home] = Convert.ToByte(100);
                    CMHomeCount--;
                }

                if (Ps4Touchpad == true)
                {
                    output[(int)xbox.touch] = Convert.ToByte(100);
                }


                if (_boolLoadShortcuts)
                {
                    output = checkKeys(output);
                }

                int intTarget = -1;
                if (system.boolPS4ControllerMode == false)
                {
                    intTarget = (int)xbox.back;
                }
                else
                {
                    intTarget = (int)xbox.touch;
                }

                /*
                 * //Back button. Wait until released as its also the menu button
                 * if (intTarget > -1)
                 * {
                 *  if (system.boolBlockMenuButton)
                 *  {
                 *      if (output[intTarget] == 100)
                 *      {
                 *          _boolHoldBack = true;
                 *          output[intTarget] = Convert.ToByte(0);
                 *          _MenuWait++;
                 *          if (!system.boolMenu)
                 *          {
                 *              if (_MenuWait >= _MenuShow)
                 *              {
                 *                  _boolHoldBack = false;
                 *                  openMenu();
                 *              }
                 *          }
                 *      }
                 *      else
                 *      {
                 *          if (_boolHoldBack == true)
                 *          {
                 *              _boolHoldBack = false;
                 *              output[intTarget] = Convert.ToByte(100);
                 *              _MenuWait = 0;
                 *          }
                 *          else
                 *              _MenuWait = 0;
                 *      }
                 *  }
                 * }
                 */
                if (keyboardInterface != null && keyboardInterface.output != null)
                {
                    for (int intCount = 0; intCount < _XboxCount; intCount++)
                    {
                        if (keyboardInterface.output[intCount] != 0)
                        {
                            output[intCount] = keyboardInterface.output[intCount];
                        }
                    }
                }

                //Block gamepad rumble
                //gcapi_WriteEX(uint8_t *outpacket, uint8_t size)

                /*
                 * [0xFF,0x01 : 2 byte, Packet Signature]
                 * [Update LED Command (0,1) : 1 byte]
                 * [LED 1 Status : 1 byte]
                 * [LED 2 Status : 1 byte]
                 * [LED 3 Status : 1 byte]
                 * [LED 4 Status : 1 byte]
                 * [Reset LEDs Command (0,1) : 1 byte]
                 * [Update Rumble Command (0,1) : 1 byte]
                 * [Rumble 1 Value : 1 byte]
                 * [Rumble 2 Value : 1 byte]
                 * [Rumble 3 Value : 1 byte]
                 * [Rumble 4 Value : 1 byte]
                 * [Reset Rumble Command (0,1) : 1 byte]
                 * [Block Rumble Command (0,1) : 1 byte]
                 * [Turn Off Controller Command (0,1) : 1 byte]
                 * [Button States : 36 bytes - same format as gcapi_Write]
                 * _gcapi_WriteEx(output);
                 */

                _gcapi_Write(output);

                if (system.boolUseRumble == true)
                {
                    if (_devId == DevPID.TitanOne)
                    {
                        GCAPI_REPORT_TITANONE report = new GCAPI_REPORT_TITANONE();
                        if (_gcapi_Read_TO(ref report) != IntPtr.Zero)
                        {
                            GamePad.SetState(PlayerIndex.One, report.rumble[0], report.rumble[1]);
                        }
                    }
                    else
                    {
                        GCAPI_REPORT_CONTROLLERMAX report = new GCAPI_REPORT_CONTROLLERMAX();
                        if (_gcapi_Read_CM(ref report) != IntPtr.Zero)
                        {
                            GamePad.SetState(PlayerIndex.One, report.rumble[0], report.rumble[1]);
                        }
                    }
                }
            }
            else
            {
                //If device just disconnected open up notice to tell user
                if (_boolNoticeTODisconnected == false)
                {
                    system.debug("titanOne.log", "[NOTE] " + _strTODevice + " is disconnected");
                    _boolNoticeTODisconnected = true;
                }

                //Keep alive for opening the menu
                _controls = GamePad.GetState(PlayerIndex.One);
                if (_controls.Buttons.Back)
                {
                    if (system.boolBlockMenuButton == false)
                    {
                        _MenuWait++;
                        if (!system.boolMenu)
                        {
                            if (_MenuWait >= _MenuShow + 20)
                            {
                                frmMain.openMenu();
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        public void checkControllerInput()
        {
            if (!_boolGCAPILoaded)
            {
                return;
            }
            if (_gcapi_IsConnected() == 1)
            {
                byte[] output = new byte[36];

                if (_controls.DPad.Left)
                {
                    output[(int)xbox.left] = Convert.ToByte(100);
                }
                if (_controls.DPad.Right)
                {
                    output[(int)xbox.right] = Convert.ToByte(100);
                }
                if (_controls.DPad.Up)
                {
                    output[(int)xbox.up] = Convert.ToByte(100);
                }
                if (_controls.DPad.Down)
                {
                    output[(int)xbox.down] = Convert.ToByte(100);
                }

                if (_controls.Buttons.A)
                {
                    output[(int)xbox.a] = Convert.ToByte(100);
                }
                if (_controls.Buttons.B)
                {
                    output[(int)xbox.b] = Convert.ToByte(100);
                }
                if (_controls.Buttons.X)
                {
                    output[(int)xbox.x] = Convert.ToByte(100);
                }
                if (_controls.Buttons.Y)
                {
                    output[(int)xbox.y] = Convert.ToByte(100);
                }

                if (_controls.Buttons.Start)
                {
                    output[(int)xbox.start] = Convert.ToByte(100);
                }
                if (_controls.Buttons.Guide)
                {
                    output[(int)xbox.home] = Convert.ToByte(100);
                }
                if (_controls.Buttons.Back)
                {
                    output[(int)xbox.back] = Convert.ToByte(100);
                }

                if (_controls.Buttons.LeftShoulder)
                {
                    output[(int)xbox.leftShoulder] = Convert.ToByte(100);
                }
                if (_controls.Buttons.RightShoulder)
                {
                    output[(int)xbox.rightShoulder] = Convert.ToByte(100);
                }
                if (_controls.Buttons.LeftStick)
                {
                    output[(int)xbox.leftStick] = Convert.ToByte(100);
                }
                if (_controls.Buttons.RightStick)
                {
                    output[(int)xbox.rightStick] = Convert.ToByte(100);
                }

                if (_controls.Triggers.Left > 0)
                {
                    output[(int)xbox.leftTrigger] = Convert.ToByte(_controls.Triggers.Left * 100);
                }
                if (_controls.Triggers.Right > 0)
                {
                    output[(int)xbox.rightTrigger] = Convert.ToByte(_controls.Triggers.Right * 100);
                }

                double dblLX = _controls.ThumbSticks.Left.X * 100;
                double dblLY = _controls.ThumbSticks.Left.Y * -100;
                double dblRX = _controls.ThumbSticks.Right.X * 100;
                double dblRY = _controls.ThumbSticks.Right.Y * -100;


                if (dblLX != 0)
                {
                    output[(int)xbox.leftX] = (byte)Convert.ToSByte((int)(dblLX));
                }
                if (dblLY != 0)
                {
                    output[(int)xbox.leftY] = (byte)Convert.ToSByte((int)(dblLY));
                }
                if (dblRX != 0)
                {
                    output[(int)xbox.rightX] = (byte)Convert.ToSByte((int)(dblRX));
                }
                if (dblRY != 0)
                {
                    output[(int)xbox.rightY] = (byte)Convert.ToSByte((int)(dblRY));
                }


                if (Ps4Touchpad == true)
                {
                    output[(int)xbox.touch] = Convert.ToByte(100);
                }

                _gcapi_Write(output);


                if (system.UseRumble == true)
                {
                    GCAPI_REPORT_TITANONE report = new GCAPI_REPORT_TITANONE();
                    if (_gcapi_Read_TO(ref report) != IntPtr.Zero)
                    {
                        GamePad.SetState(PlayerIndex.One, report.rumble[0], report.rumble[1]);
                    }
                }
            }
        }
        public void checkControllerInput()
        {
            if (!_boolGCAPILoaded)
                return;
            if (_gcapi_IsConnected() == 1)
            {
                byte[] output = new byte[36];

                if (_controls.DPad.Left) { output[(int)xbox.left] = Convert.ToByte(100); }
                if (_controls.DPad.Right) { output[(int)xbox.right] = Convert.ToByte(100); }
                if (_controls.DPad.Up) { output[(int)xbox.up] = Convert.ToByte(100); }
                if (_controls.DPad.Down) { output[(int)xbox.down] = Convert.ToByte(100); }

                if (_controls.Buttons.A) { output[(int)xbox.a] = Convert.ToByte(100); }
                if (_controls.Buttons.B) { output[(int)xbox.b] = Convert.ToByte(100); }
                if (_controls.Buttons.X) { output[(int)xbox.x] = Convert.ToByte(100); }
                if (_controls.Buttons.Y) { output[(int)xbox.y] = Convert.ToByte(100); }

                if (_controls.Buttons.Start) { output[(int)xbox.start] = Convert.ToByte(100); }
                if (_controls.Buttons.Guide) { output[(int)xbox.home] = Convert.ToByte(100); }
                if (_controls.Buttons.Back) { output[(int)xbox.back] = Convert.ToByte(100); }

                if (_controls.Buttons.LeftShoulder) { output[(int)xbox.leftShoulder] = Convert.ToByte(100); }
                if (_controls.Buttons.RightShoulder) { output[(int)xbox.rightShoulder] = Convert.ToByte(100); }
                if (_controls.Buttons.LeftStick) { output[(int)xbox.leftStick] = Convert.ToByte(100); }
                if (_controls.Buttons.RightStick) { output[(int)xbox.rightStick] = Convert.ToByte(100); }

                if (_controls.Triggers.Left > 0) { output[(int)xbox.leftTrigger] = Convert.ToByte(_controls.Triggers.Left * 100); }
                if (_controls.Triggers.Right > 0) { output[(int)xbox.rightTrigger] = Convert.ToByte(_controls.Triggers.Right * 100); }

                double dblLX = _controls.ThumbSticks.Left.X * 100;
                double dblLY = _controls.ThumbSticks.Left.Y * -100;
                double dblRX = _controls.ThumbSticks.Right.X * 100;
                double dblRY = _controls.ThumbSticks.Right.Y * -100;

                if (dblLX != 0) { output[(int)xbox.leftX] = (byte)Convert.ToSByte((int)(dblLX)); }
                if (dblLY != 0) { output[(int)xbox.leftY] = (byte)Convert.ToSByte((int)(dblLY)); }
                if (dblRX != 0) { output[(int)xbox.rightX] = (byte)Convert.ToSByte((int)(dblRX)); }
                if (dblRY != 0) { output[(int)xbox.rightY] = (byte)Convert.ToSByte((int)(dblRY)); }

                if (Ps4Touchpad == true)
                    output[(int)xbox.touch] = Convert.ToByte(100);

                _gcapi_Write(output);

                if (system.UseRumble == true)
                {
                    GCAPI_REPORT_TITANONE report = new GCAPI_REPORT_TITANONE();
                    if (_gcapi_Read_TO(ref report) != IntPtr.Zero)
                    {
                        GamePad.SetState(PlayerIndex.One, report.rumble[0], report.rumble[1]);
                    }
                }
            }
        }
        public void checkControllerInput()
        {
            if (_gcapi_Write == null)
                return;

            bool boolOverride = false;

            if (frmMain.boolIDE)
                boolOverride = true;

            if ((_gcapi_IsConnected() == 1) || (boolOverride == true))
            {
                //Update gamepad status
                _controls = GamePad.GetState(PlayerIndex.One);

                if (_XboxCount == 0) { _XboxCount = Enum.GetNames(typeof(xbox)).Length; }
                byte[] output = new byte[_XboxCount];

                if (_controls.DPad.Left) { output[(int)xbox.left] = Convert.ToByte(100); }
                if (_controls.DPad.Right) { output[(int)xbox.right] = Convert.ToByte(100); }
                if (_controls.DPad.Up) { output[(int)xbox.up] = Convert.ToByte(100); }
                if (_controls.DPad.Down) { output[(int)xbox.down] = Convert.ToByte(100); }

                if (_controls.Buttons.A) { output[(int)xbox.a] = Convert.ToByte(100); }
                if (_controls.Buttons.B) { output[(int)xbox.b] = Convert.ToByte(100); }
                if (_controls.Buttons.X) { output[(int)xbox.x] = Convert.ToByte(100); }
                if (_controls.Buttons.Y) { output[(int)xbox.y] = Convert.ToByte(100); }

                if (_controls.Buttons.Start) { output[(int)xbox.start] = Convert.ToByte(100); }
                if (_controls.Buttons.Guide) { output[(int)xbox.home] = Convert.ToByte(100); }
                if (_controls.Buttons.Back)
                {
                    if (system.boolBlockMenuButton == false)
                    {
                        _MenuWait++;
                        if (system.boolMenu == false)
                            if (_MenuWait >= _MenuShow + 20)
                                openMenu();
                    }

                    //Remap back buton to touchpad
                    if (system.boolPS4ControllerMode)
                        output[(int)xbox.touch] = Convert.ToByte(100);
                    else
                        output[(int)xbox.back] = Convert.ToByte(100);
                }

                if (_controls.Buttons.LeftShoulder) { output[(int)xbox.leftShoulder] = Convert.ToByte(100); }
                if (_controls.Buttons.RightShoulder) { output[(int)xbox.rightShoulder] = Convert.ToByte(100); }
                if (_controls.Buttons.LeftStick) { output[(int)xbox.leftStick] = Convert.ToByte(100); }
                if (_controls.Buttons.RightStick) { output[(int)xbox.rightStick] = Convert.ToByte(100); }

                if (_controls.Triggers.Left > 0) { output[(int)xbox.leftTrigger] = Convert.ToByte(_controls.Triggers.Left * 100); }
                if (_controls.Triggers.Right > 0) { output[(int)xbox.rightTrigger] = Convert.ToByte(_controls.Triggers.Right * 100); }

                double dblLX = _controls.ThumbSticks.Left.X * 100;
                double dblLY = _controls.ThumbSticks.Left.Y * 100;
                double dblRX = _controls.ThumbSticks.Right.X * 100;
                double dblRY = _controls.ThumbSticks.Right.Y * 100;

                if (system.boolNormalizeControls == true)
                {
                    normalGamepad(ref dblLX, ref dblLY);
                    normalGamepad(ref dblRX, ref dblRY);
                }
                else
                {
                    dblLY = -dblLY;
                    dblRY = -dblRY;
                }

                if (dblLX != 0) { output[(int)xbox.leftX] = (byte)Convert.ToSByte((int)(dblLX)); }
                if (dblLY != 0) { output[(int)xbox.leftY] = (byte)Convert.ToSByte((int)(dblLY)); }
                if (dblRX != 0) { output[(int)xbox.rightX] = (byte)Convert.ToSByte((int)(dblRX)); }
                if (dblRY != 0) { output[(int)xbox.rightY] = (byte)Convert.ToSByte((int)(dblRY)); }

                if (CMHomeCount > 0)
                {
                    output[(int)xbox.home] = Convert.ToByte(100);
                    CMHomeCount--;
                }

                if (Ps4Touchpad == true)
                    output[(int)xbox.touch] = Convert.ToByte(100);

                if (_boolLoadShortcuts)
                    output = checkKeys(output);

                int intTarget = -1;
                if (system.boolPS4ControllerMode == false) { intTarget = (int)xbox.back; } else { intTarget = (int)xbox.touch; }
                /*
                //Back button. Wait until released as its also the menu button
                if (intTarget > -1)
                {
                    if (system.boolBlockMenuButton)
                    {
                        if (output[intTarget] == 100)
                        {
                            _boolHoldBack = true;
                            output[intTarget] = Convert.ToByte(0);
                            _MenuWait++;
                            if (!system.boolMenu)
                            {
                                if (_MenuWait >= _MenuShow)
                                {
                                    _boolHoldBack = false;
                                    openMenu();
                                }
                            }
                        }
                        else
                        {
                            if (_boolHoldBack == true)
                            {
                                _boolHoldBack = false;
                                output[intTarget] = Convert.ToByte(100);
                                _MenuWait = 0;
                            }
                            else
                                _MenuWait = 0;
                        }
                    }
                }
                */
                if (keyboardInterface != null && keyboardInterface.output != null)
                {
                    for (int intCount = 0; intCount < _XboxCount; intCount++)
                    {
                        if (keyboardInterface.output[intCount] != 0)
                            output[intCount] = keyboardInterface.output[intCount];
                    }
                }

                //Block gamepad rumble
                //gcapi_WriteEX(uint8_t *outpacket, uint8_t size)
                /*
                [0xFF,0x01 : 2 byte, Packet Signature]
            [Update LED Command (0,1) : 1 byte]
            [LED 1 Status : 1 byte]
            [LED 2 Status : 1 byte]
            [LED 3 Status : 1 byte]
            [LED 4 Status : 1 byte]
            [Reset LEDs Command (0,1) : 1 byte]
            [Update Rumble Command (0,1) : 1 byte]
            [Rumble 1 Value : 1 byte]
            [Rumble 2 Value : 1 byte]
            [Rumble 3 Value : 1 byte]
            [Rumble 4 Value : 1 byte]
            [Reset Rumble Command (0,1) : 1 byte]
            [Block Rumble Command (0,1) : 1 byte]
            [Turn Off Controller Command (0,1) : 1 byte]
            [Button States : 36 bytes - same format as gcapi_Write]
                _gcapi_WriteEx(output);
                 */

                _gcapi_Write(output);

                if (system.boolUseRumble == true)
                {
                    if (_devId == DevPID.TitanOne)
                    {
                        GCAPI_REPORT_TITANONE report = new GCAPI_REPORT_TITANONE();
                        if (_gcapi_Read_TO(ref report) != IntPtr.Zero)
                            GamePad.SetState(PlayerIndex.One, report.rumble[0], report.rumble[1]);
                    }
                    else
                    {
                        GCAPI_REPORT_CONTROLLERMAX report = new GCAPI_REPORT_CONTROLLERMAX();
                        if (_gcapi_Read_CM(ref report) != IntPtr.Zero)
                            GamePad.SetState(PlayerIndex.One, report.rumble[0], report.rumble[1]);

                    }
                }
            }
            else
            {
                //If device just disconnected open up notice to tell user
                if (_boolNoticeTODisconnected == false)
                {
                    system.debug("titanOne.log", "[NOTE] " + _strTODevice + " is disconnected");
                    _boolNoticeTODisconnected = true;
                }

                //Keep alive for opening the menu
                _controls = GamePad.GetState(PlayerIndex.One);
                if (_controls.Buttons.Back)
                {
                    if (system.boolBlockMenuButton == false)
                    {
                        _MenuWait++;
                        if (!system.boolMenu)
                        {
                            if (_MenuWait >= _MenuShow + 20)
                                frmMain.openMenu();
                        }
                    }
                }
            }
        }