private void Timer_Tick(object sender, EventArgs e) { joystick.Poll(); joystick.GetCurrentState(); var datas = joystick.GetBufferedData(); if (datas.Length > 0 && !firstRun) { foreach (var item in datas) { JoystickUpdate x = datas[0]; if (x.Offset != JoystickOffset.Buttons4 && x.Value > 0) { buttonColor = new JoystickButtonToColor { Button = x.Offset, Color = new LEDBulb(), ButtonType = buttonType, PressedBrightness = 64, ReleasedBrightness = 255 }; timer.Stop(); DialogHost.CloseDialogCommand.Execute(buttonColor, this); } } } firstRun = false; }
private async void Button_AddButtonColor_Click(object sender, RoutedEventArgs e) { var view = new AddButton(guids[combo_joysticks.SelectedIndex], joystickHelper, JoystickButtonToColor.ButtonTypeEnum.Color); JoystickButtonToColor newButton = (JoystickButtonToColor)await DialogHost.Show(view); if (newButton == null) { return; } newButton.ButtonType = JoystickButtonToColor.ButtonTypeEnum.Color; //TODO: REMOVE POG buttonsToColors.Add(newButton); var panel = new ButtonColorPicker(buttonsToColors[buttonsToColors.Count - 1]); panel.colorPanel.ColorChanged += ColorPanel_ColorChanged; panel.colorPanel.MouseLeave += ColorPanel_MouseLeave; ContextMenu context = new ContextMenu(); MenuItem menu = new MenuItem(); menu.Header = "Remove"; menu.Click += Item_Click; menu.Uid = (buttonsToColors.Count - 1).ToString(); context.Items.Add(menu); panel.ContextMenu = context; StackColors.Children.Add(panel); joystickHelper.SaveJoystickButtons(buttonsToColors.ToList(), guids[combo_joysticks.SelectedIndex]); }
public ButtonColorPicker(JoystickButtonToColor buttonColor) { InitializeComponent(); this.colorPanel.InitialColorBrush = new Media.SolidColorBrush(Media.Color.FromRgb(buttonColor.Color.R, buttonColor.Color.G, buttonColor.Color.B)); this.colorPanel.SelectedColorBrush = new Media.SolidColorBrush(Media.Color.FromRgb(buttonColor.Color.R, buttonColor.Color.G, buttonColor.Color.B)); this.labelBindedButton.DataContext = buttonColor.Button; this.rectangle.Background = new Media.SolidColorBrush((Media.Color.FromRgb(buttonColor.Color.R, buttonColor.Color.G, buttonColor.Color.B))); }
private void Timer_Tick(object sender, EventArgs e) { joystick.Poll(); joystick.GetCurrentState(); var datas = joystick.GetBufferedData(); if (datas.Length > 0 && !firstRun) { foreach (var item in datas) { JoystickUpdate x; if (joystick.Information.InstanceName.Contains("Xbox")) { //not sure why, but xbox controllers always put pressed buttons after axis manipulation data contrary to my PS2 adapter x = datas[datas.Length - 1]; } else { x = datas[0]; } if ((x.Offset != JoystickOffset.Buttons4 && (toggle_ignore.IsChecked ?? false)) && x.Value > 0) { buttonColor = new JoystickButtonToColor() { Button = x.Offset, Color = new Color(), ControlType = controlType, PressedBrightness = 64, CenteredBrightness = 255 }; buttonColor.SetMinMaxValues(x.Value); timer.Stop(); DialogHost.CloseDialogCommand.Execute(buttonColor, this); } } } firstRun = false; }
private async void Button_AddButtonBrightness_Click(object sender, RoutedEventArgs e) { var view = new AddButton(guids[combo_joysticks.SelectedIndex], joystickHelper, JoystickButtonToColor.ButtonTypeEnum.Color); JoystickButtonToColor newButton = (JoystickButtonToColor)await DialogHost.Show(view); if (newButton == null) { return; } newButton.ButtonType = JoystickButtonToColor.ButtonTypeEnum.Brightness; //TODO: REMOVE POG buttonsToColors.Add(newButton); var panel = new ButtonBrightnessPicker(buttonsToColors[buttonsToColors.Count - 1]); ContextMenu context = new ContextMenu(); MenuItem menu = new MenuItem(); menu.Header = "Remove"; menu.Click += Item_Click; context.Items.Add(menu); panel.ContextMenu = context; StackColors.Children.Add(panel); }
public ButtonBrightnessPicker(JoystickButtonToColor joystickButtonToColor) { InitializeComponent(); gridMain.DataContext = joystickButtonToColor; }
private void BackgroundWorker_DoWork(object tokenObject) { var cancellationToken = (CancellationToken)tokenObject; Joystick joystick = joystickHelper.HookJoystick(guids[selectedjoystick]);; while (!cancellationToken.IsCancellationRequested) { try { if (joystick == null) { return; } joystick.Poll(); joystick.GetCurrentState(); var datas = joystick.GetBufferedData(); foreach (var state in datas) { JoystickButtonToColor Pressed = buttonsToColors.FirstOrDefault(x => x.Button == state.Offset); if (Pressed != null) { if (Pressed.ButtonType == JoystickButtonToColor.ButtonTypeEnum.Color) { if (state.Value > 0) { pressedButtons.Add(Pressed); } else { pressedButtons.Remove(Pressed); } } else { if (state.Value != 32511) //Guitar strum bar is centered { App.settings.Brightness = Pressed.PressedBrightness; } else { App.settings.Brightness = Pressed.ReleasedBrightness; } } } } if (pressedButtons.Count == 0 && App.settings.JoystickUseDefault > 0) { Effects.FixedColor(); } else { Effects.JoystickMode(pressedButtons, App.settings.Length); } Task.Delay(16, cancellationToken).Wait(cancellationToken); //60 FPS } catch (OperationCanceledException) { return; } catch { } } }
private void BackgroundWorker_DoWork(object tokenObject) { var cancellationToken = (CancellationToken)tokenObject; Joystick joystick = joystickHelper.HookJoystick(guids[selectedjoystick]);; while (!cancellationToken.IsCancellationRequested) { try { if (joystick == null) { return; } joystick.Poll(); joystick.GetCurrentState(); var datas = joystick.GetBufferedData(); foreach (var state in datas) { JoystickButtonToColor Pressed = buttonsToColors.FirstOrDefault(x => x.Button == state.Offset); if (Pressed != null) { if (Pressed.ControlType == JoystickButtonToColor.ControlTypeEnum.Color) { if (state.Value > 0) { pressedButtons.Add(Pressed); } else { pressedButtons.Remove(Pressed); } } else { Pressed.SetMinMaxValues(state.Value); var center = (Pressed.MinMaxValue[1] - Pressed.MinMaxValue[0]) / 2; var test = (state.Value - center).Clamp(0, 255); //TODO: Normalize values into [0, 255] int deadZone = 500; if (state.Value > (center + deadZone) || state.Value < (center - deadZone)) { App.settings.Brightness = Pressed.PressedBrightness; } else { App.settings.Brightness = Pressed.CenteredBrightness; } } } } if (pressedButtons.Count == 0 && App.settings.JoystickUseDefault > 0) { Mode.FixedColor(); } else { Mode.JoystickMode(pressedButtons, App.settings.Length); } Task.Delay(16, cancellationToken).Wait(cancellationToken); //60 FPS } catch (OperationCanceledException) { return; } catch { } } }