public void UpdateState(byte[] state) { // Log(string.Join(" ", state)); XInputGamepadButtons buttonsState = 0; XInputGamepadButtons dPadState = 0; for (var i = 0; i < _config.Mapping.MappingItems.Count; i++) { var configForCurrentItem = _config.Mapping.MappingItems[i]; var itemValue = state[i]; if (configForCurrentItem.Type == GamepadMappingItemType.Axis) { UpdateAxis(itemValue, configForCurrentItem); } else if ((configForCurrentItem.Type == GamepadMappingItemType.DPad) && ConvertToButtonState(itemValue) && (configForCurrentItem.ButtonType != null)) { dPadState |= configForCurrentItem.ButtonType.Value; } else if ((configForCurrentItem.Type == GamepadMappingItemType.Button) && ConvertToButtonState(itemValue) && (configForCurrentItem.ButtonType != null)) { buttonsState |= configForCurrentItem.ButtonType.Value; } } foreach (var virtualMapping in _virtualMappings) { if ((virtualMapping.Key & (buttonsState | dPadState)) == virtualMapping.Key) { buttonsState |= virtualMapping.Value; buttonsState ^= virtualMapping.Key; } } var buttonPressState = _vGenWrapper.vbox_SetButton(_config.GamepadId, buttonsState, true); var buttonReleaseState = _vGenWrapper.vbox_SetButton(_config.GamepadId, ~buttonsState, false); var dPadStatus = _vGenWrapper.vbox_SetDpad(_config.GamepadId, dPadState); if (dPadStatus != NtStatus.Success) { Log($"Failed to set DPad {dPadStatus} (${dPadStatus}). Gamepad {_config.GamepadId}"); } if (buttonPressState != NtStatus.Success) { Log($"Failed to set buttons (Press) {buttonsState} (${buttonPressState}). Gamepad {_config.GamepadId}"); } if (buttonReleaseState != NtStatus.Success) { Log($"Failed to set buttons (Release) {~buttonsState} (${buttonReleaseState}). Gamepad {_config.GamepadId}"); } }
public NtStatus vbox_SetButton(uint slotId, XInputGamepadButtons button, bool pressed) { return(SetButton(slotId, (ushort)button, pressed)); }
public NtStatus vbox_SetDpad(uint slotId, XInputGamepadButtons buttons) { return(SetDpad(slotId, (ushort)buttons)); }
public NtStatus vbox_SetDpad(uint slotId, XInputGamepadButtons buttons) { return SetDpad(slotId, (ushort) buttons); }
public NtStatus vbox_SetButton(uint slotId, XInputGamepadButtons button, bool pressed) { return SetButton(slotId, (ushort) button, pressed); }
public VirtualKeyMappingItem(List<XInputGamepadButtons?> sourceKeys, XInputGamepadButtons? destinationItem) { SourceKeys = sourceKeys; DestinationItem = destinationItem; }