public AddButton(Guid _guid, JoystickHelper helper, ButtonTypeEnum _buttonType) { InitializeComponent(); joystick = helper.HookJoystick(_guid); buttonType = _buttonType; timer = new DispatcherTimer() { Interval = new TimeSpan(20) }; timer.Tick += Timer_Tick; timer.Start(); }
public AddButton(Guid _guid, JoystickHelper helper, ControlTypeEnum _controlType) { InitializeComponent(); joystick = helper.HookJoystick(_guid); controlType = _controlType; toggle_ignore.DataContext = this; timer = new DispatcherTimer() { Interval = new TimeSpan(20) }; timer.Tick += Timer_Tick; timer.Start(); }
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 { } } }