Ejemplo n.º 1
0
        public override void Disconnect()
        {
            if (forceFeedbackCall != null)
            {
                cont.FeedbackReceived -= forceFeedbackCall;
                forceFeedbackCall      = null;
            }

            connected = false;
            cont.Disconnect();
            cont = null;
        }
    public static async Task <int> ConnectGamepad()
    {
        var gamepad = singleton.client.CreateXbox360Controller();

        // the feedback event is called immediately after the UserIndex is assigned
        // we can use this to check when the gamepad is initialised
        var compl = new TaskCompletionSource <byte>();
        Xbox360FeedbackReceivedEventHandler tmpHandler = (sender, e) => {
            compl.SetResult(e.LedNumber);
        };

        gamepad.FeedbackReceived += tmpHandler;
        gamepad.Connect();
        await compl.Task;

        gamepad.FeedbackReceived -= tmpHandler;

        Console.WriteLine("connect {0}", gamepad.UserIndex);
        singleton.gamepads[gamepad.UserIndex] = gamepad;
        singleton.StartAliveTimer(gamepad.UserIndex);
        return(gamepad.UserIndex);
    }