From 89043976855e2578f1099d79e569359e8f3e75f1 Mon Sep 17 00:00:00 2001 From: Otozinclus <58051309+Otozinclus@users.noreply.github.com> Date: Wed, 22 Jan 2025 21:55:53 +0100 Subject: [PATCH 01/19] Change controller LED color This changes the controller LED color. Now I need to add the option to change it in the settings --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 12bfab4bb..2736a3a26 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -86,6 +86,11 @@ namespace Ryujinx.Input.SDL2 Features = GetFeaturesFlag(); _triggerThreshold = 0.0f; + //if (SDL_GameControllerHasLED(_gamepadHandle)) + { + _setControllerLedColor("000000"); + } + // Enable motion tracking if (Features.HasFlag(GamepadFeaturesFlag.Motion)) { @@ -101,6 +106,16 @@ namespace Ryujinx.Input.SDL2 } } + private void _setControllerLedColor(string hex) + { + ulong LEDcolor = Convert.ToUInt64(hex, 16); + byte red = (byte)((LEDcolor >> 16) % 256); + byte green = (byte)((LEDcolor >> 8) % 256); + byte blue = (byte)(LEDcolor % 256); + + SDL_GameControllerSetLED(_gamepadHandle, red, green, blue); + } + private GamepadFeaturesFlag GetFeaturesFlag() { GamepadFeaturesFlag result = GamepadFeaturesFlag.None; From e861204078e85a36c6e59b7cc6e3cc266faf560a Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Wed, 22 Jan 2025 16:04:57 -0600 Subject: [PATCH 02/19] fix formatting & styling --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 2736a3a26..0c95d0b7c 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -88,7 +88,7 @@ namespace Ryujinx.Input.SDL2 //if (SDL_GameControllerHasLED(_gamepadHandle)) { - _setControllerLedColor("000000"); + SetLedColor("000000"); } // Enable motion tracking @@ -106,7 +106,7 @@ namespace Ryujinx.Input.SDL2 } } - private void _setControllerLedColor(string hex) + public void SetLedColor(string hex) { ulong LEDcolor = Convert.ToUInt64(hex, 16); byte red = (byte)((LEDcolor >> 16) % 256); From 6c0526c59fbcab0de6ac21ec5f974d2fecf18f6b Mon Sep 17 00:00:00 2001 From: Otozinclus <58051309+Otozinclus@users.noreply.github.com> Date: Wed, 22 Jan 2025 23:18:41 +0100 Subject: [PATCH 03/19] Check if controller has a controllable LED --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 0c95d0b7c..d3c8e8fda 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -86,7 +86,7 @@ namespace Ryujinx.Input.SDL2 Features = GetFeaturesFlag(); _triggerThreshold = 0.0f; - //if (SDL_GameControllerHasLED(_gamepadHandle)) + if (SDL_GameControllerHasLED(_gamepadHandle) == SDL_bool.SDL_TRUE) { SetLedColor("000000"); } From 861531f431d0c233ab6c303f298107b60343941b Mon Sep 17 00:00:00 2001 From: mika Date: Thu, 23 Jan 2025 00:06:24 +0100 Subject: [PATCH 04/19] just testing if git is working --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index d3c8e8fda..cd887a5f3 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -88,7 +88,7 @@ namespace Ryujinx.Input.SDL2 if (SDL_GameControllerHasLED(_gamepadHandle) == SDL_bool.SDL_TRUE) { - SetLedColor("000000"); + SetLedColor("FFE4B5"); } // Enable motion tracking From c21aa86a7ba1a553de330d7b3681a33cd746e6cf Mon Sep 17 00:00:00 2001 From: mika Date: Thu, 23 Jan 2025 00:09:07 +0100 Subject: [PATCH 05/19] just testing if git works --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index cd887a5f3..1c634229c 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -88,7 +88,7 @@ namespace Ryujinx.Input.SDL2 if (SDL_GameControllerHasLED(_gamepadHandle) == SDL_bool.SDL_TRUE) { - SetLedColor("FFE4B5"); + SetLedColor("FFE3B5"); } // Enable motion tracking From eff11f52a8f0864fe9eca6a54f74c4eadcfa3973 Mon Sep 17 00:00:00 2001 From: Otozinclus <58051309+Otozinclus@users.noreply.github.com> Date: Wed, 22 Jan 2025 21:55:53 +0100 Subject: [PATCH 06/19] Change controller LED color This changes the controller LED color. Now I need to add the option to change it in the settings --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index ed22c3661..16d1e070f 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -87,6 +87,11 @@ namespace Ryujinx.Input.SDL2 Features = GetFeaturesFlag(); _triggerThreshold = 0.0f; + //if (SDL_GameControllerHasLED(_gamepadHandle)) + { + _setControllerLedColor("000000"); + } + // Enable motion tracking if (Features.HasFlag(GamepadFeaturesFlag.Motion)) { @@ -102,6 +107,16 @@ namespace Ryujinx.Input.SDL2 } } + private void _setControllerLedColor(string hex) + { + ulong LEDcolor = Convert.ToUInt64(hex, 16); + byte red = (byte)((LEDcolor >> 16) % 256); + byte green = (byte)((LEDcolor >> 8) % 256); + byte blue = (byte)(LEDcolor % 256); + + SDL_GameControllerSetLED(_gamepadHandle, red, green, blue); + } + private GamepadFeaturesFlag GetFeaturesFlag() { GamepadFeaturesFlag result = GamepadFeaturesFlag.None; From f4c3a2e4873e7c44234be418fd2b745edee1e8e1 Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Wed, 22 Jan 2025 16:04:57 -0600 Subject: [PATCH 07/19] fix formatting & styling --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 16d1e070f..45f626543 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -89,7 +89,7 @@ namespace Ryujinx.Input.SDL2 //if (SDL_GameControllerHasLED(_gamepadHandle)) { - _setControllerLedColor("000000"); + SetLedColor("000000"); } // Enable motion tracking @@ -107,7 +107,7 @@ namespace Ryujinx.Input.SDL2 } } - private void _setControllerLedColor(string hex) + public void SetLedColor(string hex) { ulong LEDcolor = Convert.ToUInt64(hex, 16); byte red = (byte)((LEDcolor >> 16) % 256); From 488b09f97452d1acd9bb95bb65b549760037c0fc Mon Sep 17 00:00:00 2001 From: Otozinclus <58051309+Otozinclus@users.noreply.github.com> Date: Wed, 22 Jan 2025 23:18:41 +0100 Subject: [PATCH 08/19] Check if controller has a controllable LED --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 45f626543..a5b427f59 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -87,7 +87,7 @@ namespace Ryujinx.Input.SDL2 Features = GetFeaturesFlag(); _triggerThreshold = 0.0f; - //if (SDL_GameControllerHasLED(_gamepadHandle)) + if (SDL_GameControllerHasLED(_gamepadHandle) == SDL_bool.SDL_TRUE) { SetLedColor("000000"); } From bdaaddb591219fe6dc622a6a0992e0ab40672742 Mon Sep 17 00:00:00 2001 From: mika Date: Thu, 23 Jan 2025 00:06:24 +0100 Subject: [PATCH 09/19] just testing if git is working --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index a5b427f59..427c859c1 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -89,7 +89,7 @@ namespace Ryujinx.Input.SDL2 if (SDL_GameControllerHasLED(_gamepadHandle) == SDL_bool.SDL_TRUE) { - SetLedColor("000000"); + SetLedColor("FFE4B5"); } // Enable motion tracking From e9455652597e7974ed736c052e27ed2542a52b38 Mon Sep 17 00:00:00 2001 From: mika Date: Thu, 23 Jan 2025 00:09:07 +0100 Subject: [PATCH 10/19] just testing if git works --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 427c859c1..3e712a389 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -89,7 +89,7 @@ namespace Ryujinx.Input.SDL2 if (SDL_GameControllerHasLED(_gamepadHandle) == SDL_bool.SDL_TRUE) { - SetLedColor("FFE4B5"); + SetLedColor("FFE3B5"); } // Enable motion tracking From 2c4236f7332b0469c34704136c111457e4a28106 Mon Sep 17 00:00:00 2001 From: mika Date: Thu, 23 Jan 2025 03:39:33 +0100 Subject: [PATCH 11/19] test --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 3e712a389..039567228 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -87,9 +87,9 @@ namespace Ryujinx.Input.SDL2 Features = GetFeaturesFlag(); _triggerThreshold = 0.0f; - if (SDL_GameControllerHasLED(_gamepadHandle) == SDL_bool.SDL_TRUE) + if (Features.HasFlag(GamepadFeaturesFlag.Led)) { - SetLedColor("FFE3B5"); + SetLedColor(); } // Enable motion tracking @@ -107,12 +107,13 @@ namespace Ryujinx.Input.SDL2 } } - public void SetLedColor(string hex) + public void SetLedColor() { - ulong LEDcolor = Convert.ToUInt64(hex, 16); - byte red = (byte)((LEDcolor >> 16) % 256); - byte green = (byte)((LEDcolor >> 8) % 256); - byte blue = (byte)(LEDcolor % 256); + //IAMTOOTIREDWILLCONTINUETOMORROWSORRY + uint rawColor = 100; + byte red = (byte)(rawColor >> 16); + byte green = (byte)(rawColor >> 8); + byte blue = (byte)(rawColor % 256); SDL_GameControllerSetLED(_gamepadHandle, red, green, blue); } From 740e35872db4abc398640272041e1827a6a24000 Mon Sep 17 00:00:00 2001 From: mika Date: Thu, 23 Jan 2025 03:40:45 +0100 Subject: [PATCH 12/19] test --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 039567228..7cd3d4b4b 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -110,7 +110,7 @@ namespace Ryujinx.Input.SDL2 public void SetLedColor() { //IAMTOOTIREDWILLCONTINUETOMORROWSORRY - uint rawColor = 100; + uint rawColor = 111; byte red = (byte)(rawColor >> 16); byte green = (byte)(rawColor >> 8); byte blue = (byte)(rawColor % 256); From 9aa834c268d67075cb41479441dbccc38e58a542 Mon Sep 17 00:00:00 2001 From: mika Date: Thu, 23 Jan 2025 05:02:11 +0100 Subject: [PATCH 13/19] maybe this works --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index e9f23d80a..82004729f 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -1,6 +1,7 @@ using Ryujinx.Common.Configuration.Hid; using Ryujinx.Common.Configuration.Hid.Controller; using Ryujinx.Common.Logging; +using Ryujinx.HLE.HOS.Services.Hid; using SDL2; using System; using System.Collections.Generic; @@ -87,7 +88,7 @@ namespace Ryujinx.Input.SDL2 Features = GetFeaturesFlag(); _triggerThreshold = 0.0f; - if (Features.HasFlag(GamepadFeaturesFlag.Led)) + //if (Features.HasFlag(GamepadFeaturesFlag.Led)) { SetLedColor(); } @@ -110,7 +111,8 @@ namespace Ryujinx.Input.SDL2 public void SetLedColor() { //IAMTOOTIREDWILLCONTINUETOMORROWSORRY - uint rawColor = 110; + //uint rawColor = 0; + uint rawColor = _configuration.Led.LedColor; byte red = (byte)(rawColor >> 16); byte green = (byte)(rawColor >> 8); byte blue = (byte)(rawColor % 256); From 96e9e3611d9ef25dc6cad2f4202163ec69b36b87 Mon Sep 17 00:00:00 2001 From: mika Date: Thu, 23 Jan 2025 05:29:18 +0100 Subject: [PATCH 14/19] move logic around --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 82004729f..641ccebe9 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -78,6 +78,8 @@ namespace Ryujinx.Input.SDL2 private float _triggerThreshold; + private uint _rawColor; + public SDL2Gamepad(nint gamepadHandle, string driverId) { _gamepadHandle = gamepadHandle; @@ -110,12 +112,11 @@ namespace Ryujinx.Input.SDL2 public void SetLedColor() { - //IAMTOOTIREDWILLCONTINUETOMORROWSORRY //uint rawColor = 0; - uint rawColor = _configuration.Led.LedColor; - byte red = (byte)(rawColor >> 16); - byte green = (byte)(rawColor >> 8); - byte blue = (byte)(rawColor % 256); + //_rawColor = _configuration.Led.LedColor; + byte red = (byte)(_rawColor >> 16); + byte green = (byte)(_rawColor >> 8); + byte blue = (byte)(_rawColor % 256); SDL_GameControllerSetLED(_gamepadHandle, red, green, blue); } @@ -238,6 +239,9 @@ namespace Ryujinx.Input.SDL2 { _configuration = (StandardControllerInputConfig)configuration; + _rawColor = _configuration.Led.LedColor; + SetLedColor(); + _buttonsUserMapping.Clear(); // First update sticks From 898153ae13770c0513cf1c4273389673c5481113 Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Wed, 22 Jan 2025 22:35:09 -0600 Subject: [PATCH 15/19] Update SDL2Gamepad.cs --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 641ccebe9..8f208481b 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -78,8 +78,6 @@ namespace Ryujinx.Input.SDL2 private float _triggerThreshold; - private uint _rawColor; - public SDL2Gamepad(nint gamepadHandle, string driverId) { _gamepadHandle = gamepadHandle; @@ -89,11 +87,6 @@ namespace Ryujinx.Input.SDL2 Id = driverId; Features = GetFeaturesFlag(); _triggerThreshold = 0.0f; - - //if (Features.HasFlag(GamepadFeaturesFlag.Led)) - { - SetLedColor(); - } // Enable motion tracking if (Features.HasFlag(GamepadFeaturesFlag.Motion)) @@ -112,8 +105,9 @@ namespace Ryujinx.Input.SDL2 public void SetLedColor() { - //uint rawColor = 0; - //_rawColor = _configuration.Led.LedColor; + if (!HasConfiguration) return; + + uint _rawColor = _configuration.Led.LedColor; byte red = (byte)(_rawColor >> 16); byte green = (byte)(_rawColor >> 8); byte blue = (byte)(_rawColor % 256); @@ -239,8 +233,8 @@ namespace Ryujinx.Input.SDL2 { _configuration = (StandardControllerInputConfig)configuration; - _rawColor = _configuration.Led.LedColor; - SetLedColor(); + if (Features.HasFlag(GamepadFeaturesFlag.Led)) + SetLedColor(); _buttonsUserMapping.Clear(); From 5276991517a5ab3863db7285488ee92afc369414 Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Wed, 22 Jan 2025 22:37:03 -0600 Subject: [PATCH 16/19] Update SDL2Gamepad.cs --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 8f208481b..48636b99b 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -106,6 +106,7 @@ namespace Ryujinx.Input.SDL2 public void SetLedColor() { if (!HasConfiguration) return; + if (!_configuration.Led.EnableLed) return; uint _rawColor = _configuration.Led.LedColor; byte red = (byte)(_rawColor >> 16); From 5712e83a11037b30be26eec1cfd66c1b6aada028 Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Thu, 23 Jan 2025 17:22:25 -0600 Subject: [PATCH 17/19] UI: enable LED changing --- src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs index 3d1bd5f4a..720a43614 100644 --- a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs @@ -69,8 +69,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input public bool IsRight { get; set; } public bool IsLeft { get; set; } - public bool HasLed => false; //temporary - //SelectedGamepad.Features.HasFlag(GamepadFeaturesFlag.Led); + public bool HasLed => SelectedGamepad.Features.HasFlag(GamepadFeaturesFlag.Led); public bool IsModified { get; set; } public event Action NotifyChangesEvent; From cfe42563f298ea3e577fa652c2aa9f541f201a5b Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Thu, 23 Jan 2025 18:33:52 -0600 Subject: [PATCH 18/19] Add the LED functionality to the base IGamepad interface --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 14 +++++++------- src/Ryujinx.Input.SDL2/SDL2Keyboard.cs | 2 ++ src/Ryujinx.Input.SDL2/SDL2Mouse.cs | 2 ++ src/Ryujinx.Input/IGamepad.cs | 7 +++++++ src/Ryujinx/Input/AvaloniaKeyboard.cs | 2 ++ src/Ryujinx/Input/AvaloniaMouse.cs | 2 ++ 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 48636b99b..9037f7ef7 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -103,16 +103,16 @@ namespace Ryujinx.Input.SDL2 } } - public void SetLedColor() + public void SetLed(uint packedRgb) { + if (!Features.HasFlag(GamepadFeaturesFlag.Led)) return; if (!HasConfiguration) return; if (!_configuration.Led.EnableLed) return; - uint _rawColor = _configuration.Led.LedColor; - byte red = (byte)(_rawColor >> 16); - byte green = (byte)(_rawColor >> 8); - byte blue = (byte)(_rawColor % 256); - + byte red = (byte)(packedRgb >> 16); + byte green = (byte)(packedRgb >> 8); + byte blue = (byte)(packedRgb % 256); + SDL_GameControllerSetLED(_gamepadHandle, red, green, blue); } @@ -235,7 +235,7 @@ namespace Ryujinx.Input.SDL2 _configuration = (StandardControllerInputConfig)configuration; if (Features.HasFlag(GamepadFeaturesFlag.Led)) - SetLedColor(); + SetLed(_configuration.Led.LedColor); _buttonsUserMapping.Clear(); diff --git a/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs b/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs index 8d6a30d11..4a418230b 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs @@ -384,6 +384,8 @@ namespace Ryujinx.Input.SDL2 _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleLeftTrigger1, (Key)_configuration.RightJoycon.ButtonSl)); } } + + public void SetLed(uint packedRgb) {} public void SetTriggerThreshold(float triggerThreshold) { diff --git a/src/Ryujinx.Input.SDL2/SDL2Mouse.cs b/src/Ryujinx.Input.SDL2/SDL2Mouse.cs index 37b356b76..57997726f 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Mouse.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Mouse.cs @@ -75,6 +75,8 @@ namespace Ryujinx.Input.SDL2 { throw new NotImplementedException(); } + + public void SetLed(uint packedRgb) {} public void SetTriggerThreshold(float triggerThreshold) { diff --git a/src/Ryujinx.Input/IGamepad.cs b/src/Ryujinx.Input/IGamepad.cs index 3853f2819..6781c0faa 100644 --- a/src/Ryujinx.Input/IGamepad.cs +++ b/src/Ryujinx.Input/IGamepad.cs @@ -65,6 +65,13 @@ namespace Ryujinx.Input /// The configuration of the gamepad void SetConfiguration(InputConfig configuration); + /// + /// Set the LED on the gamepad to a given color. + /// + /// Does nothing on a controller without LED functionality. + /// The packed RGB integer. + void SetLed(uint packedRgb); + /// /// Starts a rumble effect on the gamepad. /// diff --git a/src/Ryujinx/Input/AvaloniaKeyboard.cs b/src/Ryujinx/Input/AvaloniaKeyboard.cs index 0b63af2d9..0b79c76ce 100644 --- a/src/Ryujinx/Input/AvaloniaKeyboard.cs +++ b/src/Ryujinx/Input/AvaloniaKeyboard.cs @@ -142,6 +142,8 @@ namespace Ryujinx.Ava.Input #pragma warning restore IDE0055 } } + + public void SetLed(uint packedRgb) { } public void SetTriggerThreshold(float triggerThreshold) { } diff --git a/src/Ryujinx/Input/AvaloniaMouse.cs b/src/Ryujinx/Input/AvaloniaMouse.cs index 1aa2d586a..6cc7d14bb 100644 --- a/src/Ryujinx/Input/AvaloniaMouse.cs +++ b/src/Ryujinx/Input/AvaloniaMouse.cs @@ -73,6 +73,8 @@ namespace Ryujinx.Ava.Input { throw new NotImplementedException(); } + + public void SetLed(uint packedRgb) { } public void SetTriggerThreshold(float triggerThreshold) { From 72d5af8b46ad3a603aec22753504a0d5b1880d48 Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Thu, 23 Jan 2025 19:02:35 -0600 Subject: [PATCH 19/19] Update LED as its changed in the UI --- src/Ryujinx.Input.SDL2/SDL2Gamepad.cs | 4 +--- src/Ryujinx.Input.SDL2/SDL2Keyboard.cs | 8 ++++++-- src/Ryujinx.Input.SDL2/SDL2Mouse.cs | 8 ++++++-- src/Ryujinx/Input/AvaloniaKeyboard.cs | 8 ++++++-- src/Ryujinx/Input/AvaloniaMouse.cs | 8 ++++++-- .../Input/ControllerInputViewModel.cs | 1 + .../UI/Views/Input/ControllerInputView.axaml | 4 +++- .../Views/Input/ControllerInputView.axaml.cs | 18 ++++++++++++++++++ 8 files changed, 47 insertions(+), 12 deletions(-) diff --git a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs index 9037f7ef7..4f2160cf2 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Gamepad.cs @@ -106,8 +106,6 @@ namespace Ryujinx.Input.SDL2 public void SetLed(uint packedRgb) { if (!Features.HasFlag(GamepadFeaturesFlag.Led)) return; - if (!HasConfiguration) return; - if (!_configuration.Led.EnableLed) return; byte red = (byte)(packedRgb >> 16); byte green = (byte)(packedRgb >> 8); @@ -234,7 +232,7 @@ namespace Ryujinx.Input.SDL2 { _configuration = (StandardControllerInputConfig)configuration; - if (Features.HasFlag(GamepadFeaturesFlag.Led)) + if (Features.HasFlag(GamepadFeaturesFlag.Led) && _configuration.Led.EnableLed) SetLed(_configuration.Led.LedColor); _buttonsUserMapping.Clear(); diff --git a/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs b/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs index 4a418230b..270af5114 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Keyboard.cs @@ -1,5 +1,6 @@ using Ryujinx.Common.Configuration.Hid; using Ryujinx.Common.Configuration.Hid.Keyboard; +using Ryujinx.Common.Logging; using System; using System.Collections.Generic; using System.Numerics; @@ -384,8 +385,11 @@ namespace Ryujinx.Input.SDL2 _buttonsUserMapping.Add(new ButtonMappingEntry(GamepadButtonInputId.SingleLeftTrigger1, (Key)_configuration.RightJoycon.ButtonSl)); } } - - public void SetLed(uint packedRgb) {} + + public void SetLed(uint packedRgb) + { + Logger.Info?.Print(LogClass.UI, "SetLed called on an SDL2Keyboard"); + } public void SetTriggerThreshold(float triggerThreshold) { diff --git a/src/Ryujinx.Input.SDL2/SDL2Mouse.cs b/src/Ryujinx.Input.SDL2/SDL2Mouse.cs index 57997726f..eb86fa799 100644 --- a/src/Ryujinx.Input.SDL2/SDL2Mouse.cs +++ b/src/Ryujinx.Input.SDL2/SDL2Mouse.cs @@ -1,4 +1,5 @@ using Ryujinx.Common.Configuration.Hid; +using Ryujinx.Common.Logging; using System; using System.Drawing; using System.Numerics; @@ -75,8 +76,11 @@ namespace Ryujinx.Input.SDL2 { throw new NotImplementedException(); } - - public void SetLed(uint packedRgb) {} + + public void SetLed(uint packedRgb) + { + Logger.Info?.Print(LogClass.UI, "SetLed called on an SDL2Mouse"); + } public void SetTriggerThreshold(float triggerThreshold) { diff --git a/src/Ryujinx/Input/AvaloniaKeyboard.cs b/src/Ryujinx/Input/AvaloniaKeyboard.cs index 0b79c76ce..031d8b033 100644 --- a/src/Ryujinx/Input/AvaloniaKeyboard.cs +++ b/src/Ryujinx/Input/AvaloniaKeyboard.cs @@ -1,5 +1,6 @@ using Ryujinx.Common.Configuration.Hid; using Ryujinx.Common.Configuration.Hid.Keyboard; +using Ryujinx.Common.Logging; using Ryujinx.Input; using System; using System.Collections.Generic; @@ -142,8 +143,11 @@ namespace Ryujinx.Ava.Input #pragma warning restore IDE0055 } } - - public void SetLed(uint packedRgb) { } + + public void SetLed(uint packedRgb) + { + Logger.Info?.Print(LogClass.UI, "SetLed called on an AvaloniaKeyboard"); + } public void SetTriggerThreshold(float triggerThreshold) { } diff --git a/src/Ryujinx/Input/AvaloniaMouse.cs b/src/Ryujinx/Input/AvaloniaMouse.cs index 6cc7d14bb..52a341a01 100644 --- a/src/Ryujinx/Input/AvaloniaMouse.cs +++ b/src/Ryujinx/Input/AvaloniaMouse.cs @@ -1,4 +1,5 @@ using Ryujinx.Common.Configuration.Hid; +using Ryujinx.Common.Logging; using Ryujinx.Input; using System; using System.Drawing; @@ -73,8 +74,11 @@ namespace Ryujinx.Ava.Input { throw new NotImplementedException(); } - - public void SetLed(uint packedRgb) { } + + public void SetLed(uint packedRgb) + { + Logger.Info?.Print(LogClass.UI, "SetLed called on an AvaloniaMouse"); + } public void SetTriggerThreshold(float triggerThreshold) { diff --git a/src/Ryujinx/UI/ViewModels/Input/ControllerInputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/ControllerInputViewModel.cs index 0380ef598..107b543ca 100644 --- a/src/Ryujinx/UI/ViewModels/Input/ControllerInputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/ControllerInputViewModel.cs @@ -1,5 +1,6 @@ using Avalonia.Svg.Skia; using CommunityToolkit.Mvvm.ComponentModel; +using FluentAvalonia.UI.Controls; using Ryujinx.Ava.UI.Models.Input; using Ryujinx.Ava.UI.Views.Input; diff --git a/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml b/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml index db7040f4b..3592df7cd 100644 --- a/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml +++ b/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml @@ -429,7 +429,7 @@ - + diff --git a/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml.cs b/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml.cs index 52a6d51b9..4e469da81 100644 --- a/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml.cs +++ b/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml.cs @@ -4,6 +4,7 @@ using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.LogicalTree; +using FluentAvalonia.UI.Controls; using Ryujinx.Ava.UI.Helpers; using Ryujinx.Ava.UI.ViewModels.Input; using Ryujinx.Common.Configuration.Hid.Controller; @@ -234,5 +235,22 @@ namespace Ryujinx.Ava.UI.Views.Input _currentAssigner?.Cancel(); _currentAssigner = null; } + + private void ColorPickerButton_OnColorChanged(ColorPickerButton sender, ColorButtonColorChangedEventArgs args) + { + if (!args.NewColor.HasValue) return; + if (DataContext is not ControllerInputViewModel cVm) return; + if (!cVm.Config.EnableLedChanging) return; + + cVm.ParentModel.SelectedGamepad.SetLed(args.NewColor.Value.ToUInt32()); + } + + private void ColorPickerButton_OnAttachedToVisualTree(object sender, VisualTreeAttachmentEventArgs e) + { + if (DataContext is not ControllerInputViewModel cVm) return; + if (!cVm.Config.EnableLedChanging) return; + + cVm.ParentModel.SelectedGamepad.SetLed(cVm.Config.LedColor.ToUInt32()); + } } }