Esempio n. 1
0
        private void _btnConnect_Click(object sender, RoutedEventArgs e)
        {
            if (_nintroller != null)
            {
                _nintroller.ExtensionChange -= ExtensionChange;
                //_nintroller.StateChange -= StateChange;
                _nintroller.StateUpdate -= StateUpdate;
                _nintroller.Disconnect();
                _nintroller = null;
                _stackDigitalInputs.Children.Clear();
                _stackAnalogInputs.Children.Clear();
                _btnConnect.Content = "Connect";
            }
            else if (_comboBoxDeviceList.SelectedItem != null)
            {
                _nintroller = new Nintroller((string)_comboBoxDeviceList.SelectedItem);

                bool success = _nintroller.Connect();

                if (!success)
                {
                    Debug.WriteLine("Failed to connect");
                    _nintroller = null;
                }
                else
                {
                    _btnConnect.Content = "Disconnect";

                    _nintroller.ExtensionChange += ExtensionChange;
                    _nintroller.StateUpdate     += StateUpdate;
                    _nintroller.BeginReading();
                    _nintroller.GetStatus();
                    _nintroller.SetPlayerLED(1);
                }
            }
        }