private void ProcessPOVs(GameController controller, IEnumerable <JoystickUpdate> updates, IProgress <GameControllerProgressArgs> progress) { GameControllerPOVDirection previousPOVDirection = GameControllerPOVDirection.UNMAPPED; GameControllerButtonMapping previousMapping = null; foreach (JoystickUpdate state in updates) { if (_PreviousPOVState.Timestamp != 0) { // Get previous stuff previousPOVDirection = GameController.GetPOVDirection(_PreviousPOVState); previousMapping = controller.ButtonMappings.Where(m => m.JoystickOffset == _PreviousPOVState.Offset && m.POVDirection == previousPOVDirection).FirstOrDefault(); } GameControllerPOVDirection povDirection = GameController.GetPOVDirection(state); if (povDirection == GameControllerPOVDirection.UNMAPPED) { if (previousMapping != null) { ProcessButtonMapping(previousMapping, -1, progress); } _PreviousPOVState = new JoystickUpdate(); } else { if (povDirection != previousPOVDirection && previousPOVDirection != GameControllerPOVDirection.UNMAPPED) { // switch from one direction to another without coming up so need to UP the previous mapping. ProcessButtonMapping(previousMapping, -1, progress); } GameControllerButtonMapping mapping = controller.ButtonMappings.Where(m => m.JoystickOffset == state.Offset && m.POVDirection == povDirection).FirstOrDefault(); ProcessButtonMapping(mapping, state.Value, progress); _PreviousPOVState = state; } } }
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; } }
public static GameControllerPOVDirection GetPOVDirection(JoystickUpdate update) { GameControllerPOVDirection direction = GameControllerPOVDirection.UNMAPPED; switch (update.Value) { case 0: direction = GameControllerPOVDirection.N; break; case 4500: direction = GameControllerPOVDirection.NE; break; case 9000: direction = GameControllerPOVDirection.E; break; case 13500: direction = GameControllerPOVDirection.SE; break; case 18000: direction = GameControllerPOVDirection.S; break; case 22500: direction = GameControllerPOVDirection.SW; break; case 27000: direction = GameControllerPOVDirection.W; break; case 31500: direction = GameControllerPOVDirection.NW; break; } return(direction); }