private void _mediator_PhysicalControlStateChanged(object sender, PhysicalControlStateChangedEventArgs e) { if (e.Control.Parent.Key != _deviceMonitor.DeviceInfo.Key) { return; } switch (e.Control.ControlType) { case ControlType.Axis: var thisAxis = _axes.SingleOrDefault(x => x.Id == e.Control.ToString()); if (thisAxis != null) { thisAxis.State = e.CurrentState; } break; case ControlType.Button: var thisButton = _buttons.SingleOrDefault(x => x.Id == e.Control.ToString()); if (thisButton != null) { thisButton.State = e.CurrentState == 1; } break; case ControlType.Pov: var thisPov = _povs.SingleOrDefault(x => x.Id == e.Control.ToString()); if (thisPov != null) { thisPov.State = e.CurrentState; } break; } }
public void MediatorPhysicalControlStateChanged(object sender, PhysicalControlStateChangedEventArgs e) { if (e == null || e.Control == null || e.Control.Parent == null) { return; } if (e.Control.ControlType == ControlType.Axis || e.Control.ControlType == ControlType.Unknown) { return; } if (_controlBindings != null) { foreach (var binding in _controlBindings.Values) { if (binding.BindingType == BindingType.Unknown || binding.BindingType == BindingType.Keybinding) { continue; } var control = (DIPhysicalControlInfo)e.Control; var device = (DIPhysicalDeviceInfo)e.Control.Parent; if (binding.DirectInputDevice != null && device.Guid != Guid.Empty && binding.DirectInputDevice.Guid != Guid.Empty && device.Guid == binding.DirectInputDevice.Guid) { //something on a device we're interested in just changed if (control.Equals(binding.DirectInputControl)) { if (binding.BindingType == BindingType.DirectInputButtonBinding && control.ControlType == ControlType.Button) { if (e.CurrentState == 1 && e.PreviousState != 1) { //this button was just pressed, so fire the attached event if (_manager != null) { _manager.FireHandler(binding.CpdInputControl); } } break; } if (binding.BindingType == BindingType.DirectInputPovBinding && control.ControlType == ControlType.Pov) { var currentDegrees = e.CurrentState / 100.0f; if (e.CurrentState == -1) { currentDegrees = -1; } /* POV directions in degrees * 0 * 337.5 22.5 * 315 45 * 292.5 67.5 * 270 90 * 247.5 112.5 * 225 135 * 202.5 157.5 * 180 */ PovDirections?direction = null; if ((currentDegrees > 337.5 && currentDegrees <= 360) || (currentDegrees >= 0 && currentDegrees <= 22.5)) { direction = PovDirections.Up; } else if (currentDegrees > 22.5 && currentDegrees <= 67.5) { direction = PovDirections.UpRight; } else if (currentDegrees > 67.5 && currentDegrees <= 112.5) { direction = PovDirections.Right; } else if (currentDegrees > 112.5 && currentDegrees <= 157.5) { direction = PovDirections.DownRight; } else if (currentDegrees > 157.5 && currentDegrees <= 202.5) { direction = PovDirections.Down; } else if (currentDegrees > 202.5 && currentDegrees <= 247.5) { direction = PovDirections.DownLeft; } else if (currentDegrees > 247.5 && currentDegrees <= 292.5) { direction = PovDirections.Left; } else if (currentDegrees > 292.5 && currentDegrees <= 337.5) { direction = PovDirections.UpLeft; } if (direction != null && direction == binding.PovDirection) { if (_manager != null) { _manager.FireHandler(binding.CpdInputControl); } } break; } } } else { continue; } } } }
private void _mediator_PhysicalControlStateChanged(object sender, PhysicalControlStateChangedEventArgs e) { if (e.Control.ControlType == ControlType.Button || e.Control.ControlType == ControlType.Pov) { rdoJoystick.Checked = true; var control = (DIPhysicalControlInfo)e.Control; var device = (DIPhysicalDeviceInfo)control.Parent; cbJoysticks.SelectedItem = device; cboJoystickControl.SelectedItem = control; if (control.ControlType == ControlType.Pov) { var currentDegrees = e.CurrentState / 100.0f; if (e.CurrentState == -1) { currentDegrees = -1; } /* POV directions in degrees * 0 * 337.5 22.5 * 315 45 * 292.5 67.5 * 270 90 * 247.5 112.5 * 225 135 * 202.5 157.5 * 180 */ if ((currentDegrees > 337.5 && currentDegrees <= 360) || (currentDegrees >= 0 && currentDegrees <= 22.5)) { rdoPovUp.Checked = true; } else if (currentDegrees > 22.5 && currentDegrees <= 67.5) { rdoPovUpRight.Checked = true; } else if (currentDegrees > 67.5 && currentDegrees <= 112.5) { rdoPovRight.Checked = true; } else if (currentDegrees > 112.5 && currentDegrees <= 157.5) { rdoPovDownRight.Checked = true; } else if (currentDegrees > 157.5 && currentDegrees <= 202.5) { rdoPovDown.Checked = true; } else if (currentDegrees > 202.5 && currentDegrees <= 247.5) { rdoPovDownLeft.Checked = true; } else if (currentDegrees > 247.5 && currentDegrees <= 292.5) { rdoPovLeft.Checked = true; } else if (currentDegrees > 292.5 && currentDegrees <= 337.5) { rdoPovUpLeft.Checked = true; } } } }
public void HandleStateChange(object sender, PhysicalControlStateChangedEventArgs e) { var keySettings = _keySettingsReader.Read(); if (_directInputEventHotkeyFilter.CheckIfMatches(e, keySettings.NVISKey)) { _inputEvents.NightVisionModeToggled.Handle(true); } else if (_directInputEventHotkeyFilter.CheckIfMatches(e, keySettings.AirspeedIndexIncreaseKey)) { _inputEvents.AirspeedIndexIncreasedByOne.Handle(true); } else if (_directInputEventHotkeyFilter.CheckIfMatches(e, keySettings.AirspeedIndexDecreaseKey)) { _inputEvents.AirspeedIndexDecreasedByOne.Handle(true); } else if (_directInputEventHotkeyFilter.CheckIfMatches(e, keySettings.EHSIHeadingDecreaseKey)) { _inputEvents.EHSILeftKnobDecreasedByOne.Handle(true); } else if (_directInputEventHotkeyFilter.CheckIfMatches(e, keySettings.EHSIHeadingIncreaseKey)) { _inputEvents.EHSILeftKnobIncreasedByOne.Handle(true); } else if (_directInputEventHotkeyFilter.CheckIfMatches(e, keySettings.EHSICourseDecreaseKey)) { _inputEvents.EHSIRightKnobDecreasedByOne.Handle(true); } else if (_directInputEventHotkeyFilter.CheckIfMatches(e, keySettings.EHSICourseIncreaseKey)) { _inputEvents.EHSIRightKnobIncreasedByOne.Handle(true); } else if (_directInputEventHotkeyFilter.CheckIfMatches(e, keySettings.EHSICourseDepressedKey)) { if (e.Control.ControlType == ControlType.Button && e.CurrentState == 0 && e.PreviousState == 1) { _inputEvents.EHSIRightKnobReleased.Handle(true); } else { _inputEvents.EHSIRightKnobDepressed.Handle(true); } } else if (_directInputEventHotkeyFilter.CheckIfMatches(e, keySettings.EHSIMenuButtonDepressedKey)) { _inputEvents.EHSIMenuButtonDepressed.Handle(true); } else if (_directInputEventHotkeyFilter.CheckIfMatches(e, keySettings.ISISBrightButtonKey)) { _inputEvents.ISISBrightButtonDepressed.Handle(true); } else if (_directInputEventHotkeyFilter.CheckIfMatches(e, keySettings.ISISStandardButtonKey)) { _inputEvents.ISISStandardButtonDepressed.Handle(true); } else if (_directInputEventHotkeyFilter.CheckIfMatches(e, keySettings.AzimuthIndicatorBrightnessIncreaseKey)) { _inputEvents.AzimuthIndicatorBrightnessIncreased.Handle(true); } else if (_directInputEventHotkeyFilter.CheckIfMatches(e, keySettings.AzimuthIndicatorBrightnessDecreaseKey)) { _inputEvents.AzimuthIndicatorBrightnessDecreased.Handle(true); } else if (_directInputEventHotkeyFilter.CheckIfMatches(e, keySettings.AccelerometerResetKey)) { _inputEvents.AccelerometerReset.Handle(true); } }
public bool CheckIfMatches(PhysicalControlStateChangedEventArgs directInputEvent, InputControlSelection inputControlSelection) { if (directInputEvent == null) { return(false); } if (directInputEvent.Control == null) { return(false); } if (inputControlSelection == null) { return(false); } if ( inputControlSelection.ControlType != ControlType.Axis && inputControlSelection.ControlType != ControlType.Button && inputControlSelection.ControlType != ControlType.Pov ) { return(false); } if (inputControlSelection.DirectInputControl == null) { return(false); } if (inputControlSelection.DirectInputDevice == null) { return(false); } if ( directInputEvent.Control.ControlType == inputControlSelection.DirectInputControl.ControlType && directInputEvent.Control.ControlNum == inputControlSelection.DirectInputControl.ControlNum && ( (directInputEvent.Control.ControlType == ControlType.Axis && directInputEvent.Control.AxisType == inputControlSelection.DirectInputControl.AxisType) || (directInputEvent.Control.ControlType != ControlType.Axis) ) && Equals(directInputEvent.Control.Parent.Key, inputControlSelection.DirectInputDevice.Key) && ( directInputEvent.Control.ControlType != ControlType.Pov || ( inputControlSelection.ControlType == ControlType.Pov && inputControlSelection.PovDirection == Util.GetPovDirection(directInputEvent.CurrentState) ) ) && ( directInputEvent.Control.ControlType != ControlType.Button || ( directInputEvent.Control.ControlType == ControlType.Button && directInputEvent.CurrentState == 1 ) ) ) { return(true); } return(false); }