public void ChangeState(ShiftState newState) { if (_currentState != newState) { // TODO: This would unpress any keys from all controllers, make it device specific KeyboardDirector.Access.Release(); MouseDirector.Access.Release(); _currentState = newState; _nintroller.SetPlayerLED((int)newState + 1); Dispatcher.Invoke(new Action(() => { if (newState == ShiftState.None) { _controller.ChangeLEDs(true, false, false, false); } else if (newState == ShiftState.Red) { _controller.ChangeLEDs(false, true, false, false); } else if (newState == ShiftState.Blue) { _controller.ChangeLEDs(false, false, true, false); } else if (newState == ShiftState.Green) { _controller.ChangeLEDs(false, false, false, true); } })); } }
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); } } }
public void SetState(DeviceState newState) { state = newState; if (updateTimer != null) { updateTimer.Dispose(); updateTimer = null; } switch (newState) { case DeviceState.None: btnIdentify.IsEnabled = false; btnProperties.IsEnabled = false; btnXinput.IsEnabled = false; //btnVjoy.IsEnabled = false; btnConfig.IsEnabled = false; btnDetatch.IsEnabled = false; btnConfig.Visibility = Visibility.Hidden; btnDetatch.Visibility = Visibility.Hidden; break; case DeviceState.Discovered: btnIdentify.IsEnabled = true; btnProperties.IsEnabled = true; btnXinput.IsEnabled = true; //btnVjoy.IsEnabled = true; btnConfig.IsEnabled = false; btnDetatch.IsEnabled = false; btnConfig.Visibility = Visibility.Hidden; btnDetatch.Visibility = Visibility.Hidden; break; case DeviceState.Connected_XInput: btnIdentify.IsEnabled = true; btnProperties.IsEnabled = true; btnXinput.IsEnabled = false; //btnVjoy.IsEnabled = false; btnConfig.IsEnabled = true; btnDetatch.IsEnabled = true; btnConfig.Visibility = Visibility.Visible; btnDetatch.Visibility = Visibility.Visible; var xHolder = new Holders.XInputHolder(device.Type); LoadProfile(properties.profile, xHolder); xHolder.ConnectXInput(targetXDevice); holder = xHolder; device.SetPlayerLED(targetXDevice); updateTimer = new System.Threading.Timer(HolderUpdate, device, 1000, UPDATE_SPEED); break; //case DeviceState.Connected_VJoy: // btnIdentify.IsEnabled = true; // btnProperties.IsEnabled = true; // btnXinput.IsEnabled = false; // btnVjoy.IsEnabled = false; // btnConfig.IsEnabled = true; // btnDetatch.IsEnabled = true; // btnConfig.Visibility = System.Windows.Visibility.Visible; // btnDetatch.Visibility = System.Windows.Visibility.Visible; // // Instantiate VJoy Holder (not for 1st release) // break; } }