From 476ca5a5e92867d135264b6561bf78908c828908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Thu, 8 Dec 2022 01:19:55 +0100 Subject: [PATCH] Simplify `Xbox360Controller` --- SteamController/Devices/Xbox360Controller.cs | 38 +++++--------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/SteamController/Devices/Xbox360Controller.cs b/SteamController/Devices/Xbox360Controller.cs index 9e84721..698d0cd 100644 --- a/SteamController/Devices/Xbox360Controller.cs +++ b/SteamController/Devices/Xbox360Controller.cs @@ -141,7 +141,9 @@ namespace SteamController.Devices { set { - SetButtonState(button, value); + if (value) + device?.SetButtonState(button, value); + submitReport = true; } } @@ -149,7 +151,8 @@ namespace SteamController.Devices { set { - SetAxisValue(axis, value); + device?.SetAxisValue(axis, value); + submitReport = true; } } @@ -157,36 +160,13 @@ namespace SteamController.Devices { set { - SetSliderValue(slider, value); + // rescale from 0..32767 to 0..255 + int result = Math.Clamp(value, (short)0, short.MaxValue) * byte.MaxValue / short.MaxValue; + device?.SetSliderValue(slider, (byte)result); + submitReport = true; } } - public void SetAxisValue(Xbox360Axis axis, short value) - { - device?.SetAxisValue(axis, value); - submitReport = true; - } - - public void SetButtonState(Xbox360Button button, bool pressed) - { - device?.SetButtonState(button, pressed); - submitReport = true; - } - - public void SetSliderValue(Xbox360Slider slider, byte value) - { - device?.SetSliderValue(slider, value); - submitReport = true; - } - - public void SetSliderValue(Xbox360Slider slider, short value) - { - // rescale from 0..32767 to 0..255 - int result = Math.Clamp(value, (short)0, short.MaxValue) * byte.MaxValue / short.MaxValue; - device?.SetSliderValue(slider, (byte)result); - submitReport = true; - } - public void ResetFeedback() { FeedbackReceived = null;