private void ProcessUpdate(JoystickUpdate update) { GameControllerButtonMapping unsetButtonMapping = null; GameControllerAxisMapping unsetAxisMapping = null; string name = "<Unknown>"; _Controller.JoystickObjects.TryGetValue(update.Offset, out name); if (_CurrentSetting == GameControllerCurrentSetting.ButtonCommand && update.RawOffset >= 48 && update.RawOffset <= 175) { if (SelectedButtonMapping != null) { SelectedButtonMapping.JoystickOffset = update.Offset; SelectedButtonMapping.Name = name; unsetButtonMapping = Controller.ButtonMappings.Where(m => m.Command != SelectedButtonMapping.Command && m.JoystickOffset == update.Offset).FirstOrDefault(); } } else if (_CurrentSetting == GameControllerCurrentSetting.ButtonCommand && update.RawOffset >= 32 && update.RawOffset <= 44) // POV controls { if (SelectedButtonMapping != null) { GameControllerPOVDirection direction = GameController.GetPOVDirection(update); if (direction != GameControllerPOVDirection.UNMAPPED) { SelectedButtonMapping.JoystickOffset = update.Offset; SelectedButtonMapping.Name = $"{name} ({direction})"; SelectedButtonMapping.POVDirection = direction; unsetButtonMapping = Controller.ButtonMappings.Where(m => m.Command != SelectedButtonMapping.Command && m.JoystickOffset == update.Offset && m.POVDirection == direction).FirstOrDefault(); } } } else if (update.RawOffset <= 20) // Axis { if (_CurrentSetting == GameControllerCurrentSetting.AxisCommand) { if (SelectedAxisMapping != null) { SelectedAxisMapping.JoystickOffset = update.Offset; SelectedAxisMapping.Name = name; unsetAxisMapping = Controller.AxisMappings.Where(m => m.Command != SelectedAxisMapping.Command && m.JoystickOffset == update.Offset).FirstOrDefault(); } } } if (unsetButtonMapping != null) { unsetButtonMapping.JoystickOffset = null; unsetButtonMapping.Name = null; unsetButtonMapping.POVDirection = GameControllerPOVDirection.UNMAPPED; } if (unsetAxisMapping != null) { unsetAxisMapping.Name = null; unsetAxisMapping.JoystickOffset = null; unsetAxisMapping.ReverseDirection = false; } }
private void ProcessAxes(GameController controller, IEnumerable <JoystickUpdate> updates, IProgress <GameControllerProgressArgs> progress) { // System.Diagnostics.Debug.WriteLine($"ProcessAxis ({updates.Count()})"); foreach (JoystickUpdate state in updates) // Just take the down clicks not the up. { GameControllerAxisMapping mapping = controller.AxisMappings.Where(m => m.JoystickOffset == state.Offset).FirstOrDefault(); ProcessAxisMapping(mapping, state.Value, progress); } }
private void ProcessDualSpeedAxis(GameControllerAxisMapping mapping, int stateValue, IProgress <GameControllerProgressArgs> progress) { if (mapping != null) { System.Diagnostics.Debug.Write($" {stateValue}"); bool highspeed = (stateValue <= -9900 || stateValue >= 9900); bool reverse = (stateValue <= -10); bool stop = (stateValue > -10 && stateValue < 10); if (mapping.ReverseDirection) { System.Diagnostics.Debug.WriteLine("(Reversed direction)"); reverse = !reverse; } GameControllerAxisCommandState history = _AxisCommandHistory.Where(h => h.Command == mapping.Command).FirstOrDefault(); if (history == null) { if (!stop) { // New command _AxisCommandHistory.Add(new GameControllerAxisCommandState(mapping.Command, highspeed, reverse)); progress.Report(new GameControllerProgressArgs(GameControllerUpdateNotification.CommandDown, mapping.Command, reverse, highspeed)); } } else { // See if command has changed if (stop) { // Issue command up and remove history progress.Report(new GameControllerProgressArgs(GameControllerUpdateNotification.CommandUp, mapping.Command, history.Reverse, history.Highspeed)); _AxisCommandHistory.Remove(history); } else if (history.Highspeed != highspeed || history.Reverse != reverse) { // There has been a change of something so stop and restart progress.Report(new GameControllerProgressArgs(GameControllerUpdateNotification.CommandUp, mapping.Command, history.Reverse, history.Highspeed)); history.Highspeed = highspeed; history.Reverse = reverse; if (reverse) { System.Diagnostics.Debug.Write("(Reverse)"); } progress.Report(new GameControllerProgressArgs(GameControllerUpdateNotification.CommandDown, mapping.Command, reverse, highspeed)); } } } }
private void ProcessAxis(GameControllerAxisMapping mapping, int stateValue, bool highspeed, IProgress <GameControllerProgressArgs> progress) { if (mapping != null) { bool reverse = (stateValue <= -10); bool stop = (stateValue > -10 && stateValue < 10); if (mapping.ReverseDirection) { reverse = !reverse; } GameControllerAxisCommandState history = _AxisCommandHistory.Where(h => h.Command == mapping.Command).FirstOrDefault(); if (history == null) { if (!stop) { // New command _AxisCommandHistory.Add(new GameControllerAxisCommandState(mapping.Command, highspeed, reverse)); progress.Report(new GameControllerProgressArgs(GameControllerUpdateNotification.CommandDown, mapping.Command, reverse, highspeed)); } } else { // See if command has changed if (stop) { // Issue command up and remove history progress.Report(new GameControllerProgressArgs(GameControllerUpdateNotification.CommandUp, mapping.Command, false, false)); _AxisCommandHistory.Remove(history); } else if (history.Reverse != reverse) { // There has been a change of something so stop and restart progress.Report(new GameControllerProgressArgs(GameControllerUpdateNotification.CommandUp, mapping.Command, false, false)); history.Highspeed = highspeed; history.Reverse = reverse; progress.Report(new GameControllerProgressArgs(GameControllerUpdateNotification.CommandDown, mapping.Command, highspeed, reverse)); } } } }
private void ProcessAxisMapping(GameControllerAxisMapping mapping, int stateValue, IProgress <GameControllerProgressArgs> progress) { if (mapping != null) { switch (mapping.Command) { case GameControllerAxisCommand.SlewNSDualSpeed: case GameControllerAxisCommand.SlewEWDualSpeed: ProcessDualSpeedAxis(mapping, stateValue, progress); break; case GameControllerAxisCommand.SlewNSHighSpeed: case GameControllerAxisCommand.SlewEWHighSpeed: ProcessAxis(mapping, stateValue, true, progress); break; default: ProcessAxis(mapping, stateValue, false, progress); break; } } }
public void PushProperties() { _OriginalController.Name = _Controller.Name; foreach (GameControllerButtonMapping newMapping in _Controller.ButtonMappings) { GameControllerButtonMapping originalMapping = _OriginalController.ButtonMappings.Where(m => m.Command == newMapping.Command).FirstOrDefault(); if (originalMapping != null) { originalMapping.JoystickOffset = newMapping.JoystickOffset; originalMapping.POVDirection = newMapping.POVDirection; originalMapping.Name = newMapping.Name; } } foreach (GameControllerAxisMapping newMapping in _Controller.AxisMappings) { GameControllerAxisMapping originalMapping = _OriginalController.AxisMappings.Where(m => m.Command == newMapping.Command).FirstOrDefault(); if (originalMapping != null) { originalMapping.JoystickOffset = newMapping.JoystickOffset; originalMapping.Name = newMapping.Name; originalMapping.ReverseDirection = newMapping.ReverseDirection; } } }
public void PopProperties() { _Controller = new GameController(_OriginalController.Id, _OriginalController.Name); foreach (GameControllerButtonMapping originalMapping in _OriginalController.ButtonMappings) { GameControllerButtonMapping newMapping = _Controller.ButtonMappings.Where(m => m.Command == originalMapping.Command).FirstOrDefault(); if (newMapping != null) { newMapping.JoystickOffset = originalMapping.JoystickOffset; newMapping.POVDirection = originalMapping.POVDirection; newMapping.Name = originalMapping.Name; } } foreach (GameControllerAxisMapping originalMapping in _OriginalController.AxisMappings) { GameControllerAxisMapping newMapping = _Controller.AxisMappings.Where(m => m.Command == originalMapping.Command).FirstOrDefault(); if (newMapping != null) { newMapping.JoystickOffset = originalMapping.JoystickOffset; newMapping.Name = originalMapping.Name; newMapping.ReverseDirection = originalMapping.ReverseDirection; } } }