public GamepadStateSnapshot GetMappedStateSnapshot() { GamepadStateSnapshot rawState = GetStateSnapshot(); GamepadStateSnapshot result = default; lock (_userMappingLock) { if (_buttonsUserMapping.Count == 0) { return(rawState); } foreach (ButtonMappingEntry entry in _buttonsUserMapping) { if (entry.From == GamepadButtonInputId.Unbound || entry.To == GamepadButtonInputId.Unbound) { continue; } // Do not touch state of button already pressed if (!result.IsPressed(entry.To)) { result.SetPressed(entry.To, rawState.IsPressed(entry.From)); } } (float leftStickX, float leftStickY) = rawState.GetStick(_stickUserMapping[(int)StickInputId.Left]); (float rightStickX, float rightStickY) = rawState.GetStick(_stickUserMapping[(int)StickInputId.Right]); result.SetStick(StickInputId.Left, leftStickX, leftStickY); result.SetStick(StickInputId.Right, rightStickX, rightStickY); } return(result); }
public NpadController(CemuHookClient cemuHookClient) { State = default; _id = null; _isValid = false; _cemuHookClient = cemuHookClient; }
public GamepadStateSnapshot GetMappedStateSnapshot() { KeyboardStateSnapshot rawState = GetKeyboardStateSnapshot(); GamepadStateSnapshot result = default; lock (_userMappingLock) { if (!HasConfiguration) { return(result); } foreach (ButtonMappingEntry entry in _buttonsUserMapping) { if (entry.From == Key.Unknown || entry.From == Key.Unbound || entry.To == GamepadButtonInputId.Unbound) { continue; } // Do not touch state of button already pressed if (!result.IsPressed(entry.To)) { result.SetPressed(entry.To, rawState.IsPressed(entry.From)); } } (short leftStickX, short leftStickY) = GetStickValues(ref rawState, _configuration.LeftJoyconStick); (short rightStickX, short rightStickY) = GetStickValues(ref rawState, _configuration.RightJoyconStick); result.SetStick(StickInputId.Left, ConvertRawStickValue(leftStickX), ConvertRawStickValue(leftStickY)); result.SetStick(StickInputId.Right, ConvertRawStickValue(rightStickX), ConvertRawStickValue(rightStickY)); } return(result); }
public void Update() { if (_isValid && GamepadDriver != null) { State = _gamepad.GetMappedStateSnapshot(); if (_config is StandardControllerInputConfig controllerConfig && controllerConfig.Motion.EnableMotion) { if (controllerConfig.Motion.MotionBackend == MotionInputBackendType.GamepadDriver) { if (_gamepad.Features.HasFlag(GamepadFeaturesFlag.Motion)) { Vector3 accelerometer = _gamepad.GetMotionData(MotionInputId.Accelerometer); Vector3 gyroscope = _gamepad.GetMotionData(MotionInputId.Gyroscope); accelerometer = new Vector3(accelerometer.X, -accelerometer.Z, accelerometer.Y); gyroscope = new Vector3(gyroscope.X, gyroscope.Z, gyroscope.Y); _leftMotionInput.Update(accelerometer, gyroscope, (ulong)PerformanceCounter.ElapsedNanoseconds / 1000, controllerConfig.Motion.Sensitivity, (float)controllerConfig.Motion.GyroDeadzone); if (controllerConfig.ControllerType == ConfigControllerType.JoyconPair) { _rightMotionInput = _leftMotionInput; } } } else if (controllerConfig.Motion.MotionBackend == MotionInputBackendType.CemuHook && controllerConfig.Motion is CemuHookMotionConfigController cemuControllerConfig) { int clientId = (int)controllerConfig.PlayerIndex; // First of all ensure we are registered _cemuHookClient.RegisterClient(clientId, cemuControllerConfig.DsuServerHost, cemuControllerConfig.DsuServerPort); // Then request and retrieve the data _cemuHookClient.RequestData(clientId, cemuControllerConfig.Slot); _cemuHookClient.TryGetData(clientId, cemuControllerConfig.Slot, out _leftMotionInput); if (controllerConfig.ControllerType == ConfigControllerType.JoyconPair) { if (!cemuControllerConfig.MirrorInput) { _cemuHookClient.RequestData(clientId, cemuControllerConfig.AltSlot); _cemuHookClient.TryGetData(clientId, cemuControllerConfig.AltSlot, out _rightMotionInput); } else { _rightMotionInput = _leftMotionInput; } } } } } else { // Reset states State = default; _leftMotionInput = null; } }
public void Initialize() { if (_gamepad != null) { _currState = _gamepad.GetStateSnapshot(); _prevState = _currState; } }
public void ReadInput() { if (_gamepad != null) { _prevState = _currState; _currState = _gamepad.GetStateSnapshot(); } CollectButtonStats(); }