From 497c31445843ab262567b37a1446b5cf69d766bb Mon Sep 17 00:00:00 2001 From: Fighterguard Date: Wed, 22 Nov 2023 19:08:45 +0100 Subject: [PATCH 1/3] Adds feature to use the motion trigger as toggle --- HandheldCompanion/Actions/GyroActions.cs | 2 ++ .../Controls/Mapping/GyroMapping.xaml | 4 +-- HandheldCompanion/Managers/MotionManager.cs | 25 +++++++++++++++++-- .../Properties/Resources.Designer.cs | 14 +++++++++-- HandheldCompanion/Properties/Resources.resx | 8 ++++-- HandheldCompanion/Utils/InputUtils.cs | 3 ++- .../Views/QuickPages/QuickProfilesPage.xaml | 1 + 7 files changed, 48 insertions(+), 9 deletions(-) diff --git a/HandheldCompanion/Actions/GyroActions.cs b/HandheldCompanion/Actions/GyroActions.cs index 619748531..66601f66a 100644 --- a/HandheldCompanion/Actions/GyroActions.cs +++ b/HandheldCompanion/Actions/GyroActions.cs @@ -9,6 +9,8 @@ public class GyroActions : IActions { public MotionInput MotionInput = MotionInput.JoystickCamera; public MotionMode MotionMode = MotionMode.Off; + public bool MotionToggleStatus = false; + public bool MotionTogglePressed = false; // for debouncing public ButtonState MotionTrigger = new(); diff --git a/HandheldCompanion/Controls/Mapping/GyroMapping.xaml b/HandheldCompanion/Controls/Mapping/GyroMapping.xaml index f478dc4c2..1376d6c85 100644 --- a/HandheldCompanion/Controls/Mapping/GyroMapping.xaml +++ b/HandheldCompanion/Controls/Mapping/GyroMapping.xaml @@ -91,10 +91,9 @@ Name="cB_Input" Grid.Column="1" Margin="12,0,0,0" - HorizontalAlignment="Stretch" VerticalAlignment="Center" HorizontalContentAlignment="Left" - SelectionChanged="cB_Input_SelectionChanged" /> + SelectionChanged="cB_Input_SelectionChanged" Width="371" /> @@ -136,6 +135,7 @@ SelectionChanged="cB_UMC_MotionDefaultOffOn_SelectionChanged"> + diff --git a/HandheldCompanion/Managers/MotionManager.cs b/HandheldCompanion/Managers/MotionManager.cs index 78ccb70e6..5dd74e02a 100644 --- a/HandheldCompanion/Managers/MotionManager.cs +++ b/HandheldCompanion/Managers/MotionManager.cs @@ -149,10 +149,31 @@ private static void CalculateMotion(ControllerState controllerState) DeltaSeconds = (TotalMilliseconds - PreviousTotalMilliseconds) / 1000L; PreviousTotalMilliseconds = TotalMilliseconds; - // check if motion trigger is pressed + //toggle motion when trigger is pressed + if (gyroAction.MotionMode == MotionMode.Toggle) + { + if (gyroAction.MotionTogglePressed) + { + if (!controllerState.ButtonState.ContainsTrue(gyroAction.MotionTrigger)) + { + gyroAction.MotionTogglePressed = false; // disable debounce flag + } + } + else + { + if (controllerState.ButtonState.ContainsTrue(gyroAction.MotionTrigger)) + { + gyroAction.MotionToggleStatus = !gyroAction.MotionToggleStatus; + gyroAction.MotionTogglePressed = true; // enable debounce flag + } + } + } + + // check if motion input is active bool MotionTriggered = (gyroAction.MotionMode == MotionMode.Off && controllerState.ButtonState.ContainsTrue(gyroAction.MotionTrigger)) || - (gyroAction.MotionMode == MotionMode.On && !controllerState.ButtonState.ContainsTrue(gyroAction.MotionTrigger)); + (gyroAction.MotionMode == MotionMode.On && !controllerState.ButtonState.ContainsTrue(gyroAction.MotionTrigger)) || + (gyroAction.MotionMode == MotionMode.Toggle && gyroAction.MotionToggleStatus); bool MotionMapped = action?.ActionType != ActionType.Disabled; diff --git a/HandheldCompanion/Properties/Resources.Designer.cs b/HandheldCompanion/Properties/Resources.Designer.cs index 9bcd89f4c..ef1e2d1c3 100644 --- a/HandheldCompanion/Properties/Resources.Designer.cs +++ b/HandheldCompanion/Properties/Resources.Designer.cs @@ -5122,8 +5122,9 @@ public static string ProfilesPage_UMCMotionOnOff { } /// - /// Looks up a localized string similar to With motion input disabled, use selected button(s) to enable motion, - ///with motion input enabled, use selected button(s) to disable motion.. + /// Looks up a localized string similar to With motion input disabled, hold selected button(s) to enable motion, + ///with motion input enabled, hold selected button(s) to disable motion, + ///with motion input toggle, press selected button(s) to switch from enabled to disabled and viceversa.. /// public static string ProfilesPage_UMCMotionOnOffDesc { get { @@ -5131,6 +5132,15 @@ public static string ProfilesPage_UMCMotionOnOffDesc { } } + /// + /// Looks up a localized string similar to Toggle between enabled or disabled with button(s). + /// + public static string ProfilesPage_UMCMotionToggle { + get { + return ResourceManager.GetString("ProfilesPage_UMCMotionToggle", resourceCulture); + } + } + /// /// Looks up a localized string similar to Select the device that will receive the motion commands. /// diff --git a/HandheldCompanion/Properties/Resources.resx b/HandheldCompanion/Properties/Resources.resx index 647981f7e..6989dd684 100644 --- a/HandheldCompanion/Properties/Resources.resx +++ b/HandheldCompanion/Properties/Resources.resx @@ -762,13 +762,17 @@ Enabled, turn off with button(s) + + + Toggle between enabled or disabled with button(s) Motion activation - With motion input disabled, use selected button(s) to enable motion, -with motion input enabled, use selected button(s) to disable motion. + With motion input disabled, hold selected button(s) to enable motion, +with motion input enabled, hold selected button(s) to disable motion, +with motion input toggle, press selected button(s) to switch from enabled to disabled and viceversa. Select the device that will receive the motion commands diff --git a/HandheldCompanion/Utils/InputUtils.cs b/HandheldCompanion/Utils/InputUtils.cs index c01eacb9a..3afc6bf78 100644 --- a/HandheldCompanion/Utils/InputUtils.cs +++ b/HandheldCompanion/Utils/InputUtils.cs @@ -33,7 +33,8 @@ public enum MotionOuput public enum MotionMode { Off = 0, - On = 1 + On = 1, + Toggle = 2 } public enum OverlayModelMode diff --git a/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml b/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml index a412bb363..043c7e2d8 100644 --- a/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml +++ b/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml @@ -581,6 +581,7 @@ SelectionChanged="cB_UMC_MotionDefaultOffOn_SelectionChanged"> + From c330092ffa4f0ca026f9497d809406295ddd01c1 Mon Sep 17 00:00:00 2001 From: Fighterguard Date: Wed, 22 Nov 2023 19:15:16 +0100 Subject: [PATCH 2/3] removed unintended changes --- HandheldCompanion/Controls/Mapping/GyroMapping.xaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/HandheldCompanion/Controls/Mapping/GyroMapping.xaml b/HandheldCompanion/Controls/Mapping/GyroMapping.xaml index 1376d6c85..7c552dc3b 100644 --- a/HandheldCompanion/Controls/Mapping/GyroMapping.xaml +++ b/HandheldCompanion/Controls/Mapping/GyroMapping.xaml @@ -91,9 +91,10 @@ Name="cB_Input" Grid.Column="1" Margin="12,0,0,0" + HorizontalAlignment="Stretch" VerticalAlignment="Center" HorizontalContentAlignment="Left" - SelectionChanged="cB_Input_SelectionChanged" Width="371" /> + SelectionChanged="cB_Input_SelectionChanged" /> From 7abed0fd14b41db6a89eab18e1a385546ba807d6 Mon Sep 17 00:00:00 2001 From: Lesueur Benjamin Date: Wed, 22 Nov 2023 19:45:25 +0100 Subject: [PATCH 3/3] Update HandheldCompanion/Managers/MotionManager.cs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- HandheldCompanion/Managers/MotionManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HandheldCompanion/Managers/MotionManager.cs b/HandheldCompanion/Managers/MotionManager.cs index 5dd74e02a..c8cf697db 100644 --- a/HandheldCompanion/Managers/MotionManager.cs +++ b/HandheldCompanion/Managers/MotionManager.cs @@ -146,7 +146,7 @@ private static void CalculateMotion(ControllerState controllerState) // update timestamp double TotalMilliseconds = TimerManager.Stopwatch.Elapsed.TotalMilliseconds; - DeltaSeconds = (TotalMilliseconds - PreviousTotalMilliseconds) / 1000L; + DeltaSeconds = (TotalMilliseconds - PreviousTotalMilliseconds) / 1000; PreviousTotalMilliseconds = TotalMilliseconds; //toggle motion when trigger is pressed