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 e364aebc7..206ee2186 100644 --- a/HandheldCompanion/Controls/Mapping/GyroMapping.xaml +++ b/HandheldCompanion/Controls/Mapping/GyroMapping.xaml @@ -136,6 +136,7 @@ SelectionChanged="cB_UMC_MotionDefaultOffOn_SelectionChanged"> + diff --git a/HandheldCompanion/Managers/MotionManager.cs b/HandheldCompanion/Managers/MotionManager.cs index 78ccb70e6..c8cf697db 100644 --- a/HandheldCompanion/Managers/MotionManager.cs +++ b/HandheldCompanion/Managers/MotionManager.cs @@ -146,13 +146,34 @@ private static void CalculateMotion(ControllerState controllerState) // update timestamp double TotalMilliseconds = TimerManager.Stopwatch.Elapsed.TotalMilliseconds; - DeltaSeconds = (TotalMilliseconds - PreviousTotalMilliseconds) / 1000L; + DeltaSeconds = (TotalMilliseconds - PreviousTotalMilliseconds) / 1000; 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 bd7948046..b7bfd62db 100644 --- a/HandheldCompanion/Properties/Resources.Designer.cs +++ b/HandheldCompanion/Properties/Resources.Designer.cs @@ -5599,8 +5599,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 { @@ -5608,6 +5609,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 25e98f036..f7eaea2ec 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 4ccd56666..96e380cd8 100644 --- a/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml +++ b/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml @@ -308,6 +308,7 @@ SelectionChanged="cB_UMC_MotionDefaultOffOn_SelectionChanged"> +