Skip to content

Commit

Permalink
Feature: Motion Toggle (Valkirie#842) (Valkirie#73)
Browse files Browse the repository at this point in the history
* Adds feature to use the motion trigger as toggle

* removed unintended changes

* Update HandheldCompanion/Managers/MotionManager.cs



---------

Co-authored-by: Sergio Perilla <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 23, 2023
1 parent 28f212f commit 8d1ec42
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 8 deletions.
2 changes: 2 additions & 0 deletions HandheldCompanion/Actions/GyroActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions HandheldCompanion/Controls/Mapping/GyroMapping.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
SelectionChanged="cB_UMC_MotionDefaultOffOn_SelectionChanged">
<ComboBoxItem Content="{x:Static resx:Resources.ProfilesPage_UMCMotionOff}" />
<ComboBoxItem Content="{x:Static resx:Resources.ProfilesPage_UMCMotionOn}" />
<ComboBoxItem Content="{x:Static resx:Resources.ProfilesPage_UMCMotionToggle}" />
</ComboBox>
</ui:SimpleStackPanel>
</Grid>
Expand Down
27 changes: 24 additions & 3 deletions HandheldCompanion/Managers/MotionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
14 changes: 12 additions & 2 deletions HandheldCompanion/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions HandheldCompanion/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -762,13 +762,17 @@
</data>
<data name="ProfilesPage_UMCMotionOn" xml:space="preserve">
<value>Enabled, turn off with button(s)</value>
</data>
<data name="ProfilesPage_UMCMotionToggle" xml:space="preserve">
<value>Toggle between enabled or disabled with button(s)</value>
</data>
<data name="ProfilesPage_UMCMotionOnOff" xml:space="preserve">
<value>Motion activation</value>
</data>
<data name="ProfilesPage_UMCMotionOnOffDesc" xml:space="preserve">
<value>With motion input disabled, use selected button(s) to enable motion,
with motion input enabled, use selected button(s) to disable motion.</value>
<value>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.</value>
</data>
<data name="ProfilesPage_UMCSelectionRightLeftDesc" xml:space="preserve">
<value>Select the device that will receive the motion commands</value>
Expand Down
3 changes: 2 additions & 1 deletion HandheldCompanion/Utils/InputUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public enum MotionOuput
public enum MotionMode
{
Off = 0,
On = 1
On = 1,
Toggle = 2
}

public enum OverlayModelMode
Expand Down
1 change: 1 addition & 0 deletions HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
SelectionChanged="cB_UMC_MotionDefaultOffOn_SelectionChanged">
<ComboBoxItem Content="{x:Static resx:Resources.ProfilesPage_UMCMotionOff}" />
<ComboBoxItem Content="{x:Static resx:Resources.ProfilesPage_UMCMotionOn}" />
<ComboBoxItem Content="{x:Static resx:Resources.ProfilesPage_UMCMotionToggle}" />
</ComboBox>
</Grid>

Expand Down

0 comments on commit 8d1ec42

Please sign in to comment.