Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Commit

Permalink
Dev/controller updates (#40)
Browse files Browse the repository at this point in the history
* Simplified controller implementation

* removed unused namspace

* Added Bit flag for device removal
  • Loading branch information
StephenHodgson authored and SimonDarksideJ committed Sep 29, 2019
1 parent 5c64a44 commit c9cbc49
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 205 deletions.
212 changes: 16 additions & 196 deletions Controllers/WindowsMixedRealityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using XRTK.Definitions.Devices;
using XRTK.Definitions.InputSystem;
using XRTK.Definitions.Utilities;
using XRTK.Extensions;
using XRTK.Interfaces.InputSystem;
using XRTK.Providers.Controllers;

Expand Down Expand Up @@ -94,49 +95,55 @@ public void UpdateController(InteractionSourceState interactionSourceState)
{
if (!Enabled) { return; }

base.UpdateController();

UpdateControllerData(interactionSourceState);

if (Interactions == null)
{
Debug.LogError($"No interaction configuration for Windows Mixed Reality Motion Controller {ControllerHandedness}");
Debug.LogError($"No interaction configuration for {GetType().Name} {ControllerHandedness}");
Enabled = false;
}

for (int i = 0; i < Interactions?.Length; i++)
{
switch (Interactions[i].InputType)
var interactionMapping = Interactions[i];

switch (interactionMapping.InputType)
{
case DeviceInputType.None:
break;
case DeviceInputType.SpatialPointer:
UpdatePointerData(interactionSourceState, Interactions[i]);
UpdatePointerData(interactionSourceState, interactionMapping);
break;
case DeviceInputType.Select:
case DeviceInputType.Trigger:
case DeviceInputType.TriggerTouch:
case DeviceInputType.TriggerPress:
UpdateTriggerData(interactionSourceState, Interactions[i]);
UpdateTriggerData(interactionSourceState, interactionMapping);
break;
case DeviceInputType.SpatialGrip:
UpdateGripData(interactionSourceState, Interactions[i]);
UpdateGripData(interactionSourceState, interactionMapping);
break;
case DeviceInputType.ThumbStick:
case DeviceInputType.ThumbStickPress:
UpdateThumbStickData(interactionSourceState, Interactions[i]);
UpdateThumbStickData(interactionSourceState, interactionMapping);
break;
case DeviceInputType.Touchpad:
case DeviceInputType.TouchpadTouch:
case DeviceInputType.TouchpadPress:
UpdateTouchPadData(interactionSourceState, Interactions[i]);
UpdateTouchPadData(interactionSourceState, interactionMapping);
break;
case DeviceInputType.Menu:
UpdateMenuData(interactionSourceState, Interactions[i]);
UpdateMenuData(interactionSourceState, interactionMapping);
break;
default:
Debug.LogError($"Input [{Interactions[i].InputType}] is not handled for this controller [WindowsMixedRealityController]");
Debug.LogError($"Input [{interactionMapping.InputType}] is not handled for this controller [{GetType().Name}]");
Enabled = false;
break;
}

interactionMapping.RaiseInputAction(InputSource, ControllerHandedness);
}

LastSourceStateReading = interactionSourceState;
Expand Down Expand Up @@ -219,15 +226,7 @@ private void UpdatePointerData(InteractionSourceState interactionSourceState, Mi
currentPointerPose.Position = currentPointerPosition;
currentPointerPose.Rotation = currentPointerRotation;

// Update the interaction data source
interactionMapping.PoseData = currentPointerPose;

// If our value was updated, raise it.
if (interactionMapping.Updated)
{
// Raise input system Event if it enabled
MixedRealityToolkit.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, currentPointerPose);
}
}

/// <summary>
Expand Down Expand Up @@ -255,15 +254,7 @@ private void UpdateGripData(InteractionSourceState interactionSourceState, Mixed
currentGripPose.Rotation = currentGripRotation;
}

// Update the interaction data source
interactionMapping.PoseData = currentGripPose;

// If our value was updated, raise it.
if (interactionMapping.Updated)
{
// Raise input system Event if it enabled
MixedRealityToolkit.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, currentGripPose);
}
}
break;
}
Expand All @@ -280,67 +271,17 @@ private void UpdateTouchPadData(InteractionSourceState interactionSourceState, M
{
case DeviceInputType.TouchpadTouch:
{
// Update the interaction data source
interactionMapping.BoolData = interactionSourceState.touchpadTouched;

// If our value changed raise it.
if (interactionMapping.Changed)
{
// Raise input system Event if it enabled
if (interactionSourceState.touchpadTouched)
{
MixedRealityToolkit.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
else
{
MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
}

// If our value was updated, raise it.
if (interactionMapping.Updated)
{
MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
break;
}
case DeviceInputType.TouchpadPress:
{
//Update the interaction data source
interactionMapping.BoolData = interactionSourceState.touchpadPressed;

// If our value changed raise it.
if (interactionMapping.Changed)
{
// Raise input system Event if it enabled
if (interactionSourceState.touchpadPressed)
{
MixedRealityToolkit.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
else
{
MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
}

// If our value was updated, raise it.
if (interactionMapping.Updated)
{
MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
break;
}
case DeviceInputType.Touchpad:
{
// Update the interaction data source
interactionMapping.Vector2Data = interactionSourceState.touchpadPosition;

// If our value was updated, raise it.
if (interactionMapping.Updated)
{
// Raise input system Event if it enabled
MixedRealityToolkit.InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, interactionSourceState.touchpadPosition);
}
break;
}
}
Expand All @@ -357,41 +298,12 @@ private void UpdateThumbStickData(InteractionSourceState interactionSourceState,
{
case DeviceInputType.ThumbStickPress:
{
// Update the interaction data source
interactionMapping.BoolData = interactionSourceState.thumbstickPressed;

// If our value changed raise it.
if (interactionMapping.Changed)
{
// Raise input system Event if it enabled
if (interactionSourceState.thumbstickPressed)
{
MixedRealityToolkit.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
else
{
MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
}

// If our value was updated, raise it.
if (interactionMapping.Updated)
{
MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
break;
}
case DeviceInputType.ThumbStick:
{
// Update the interaction data source
interactionMapping.Vector2Data = interactionSourceState.thumbstickPosition;

// If our value was updated, raise it.
if (interactionMapping.Updated)
{
// Raise input system Event if it enabled
MixedRealityToolkit.InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, interactionSourceState.thumbstickPosition);
}
break;
}
}
Expand All @@ -407,28 +319,7 @@ private void UpdateTriggerData(InteractionSourceState interactionSourceState, Mi
switch (interactionMapping.InputType)
{
case DeviceInputType.TriggerPress:
//Update the interaction data source
interactionMapping.BoolData = interactionSourceState.grasped;

// If our value changed raise it.
if (interactionMapping.Changed)
{
// Raise input system Event if it enabled
if (interactionMapping.BoolData)
{
MixedRealityToolkit.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
else
{
MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
}

// If our value was updated, raise it.
if (interactionMapping.Updated)
{
MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
break;
case DeviceInputType.Select:
{
Expand Down Expand Up @@ -456,66 +347,16 @@ private void UpdateTriggerData(InteractionSourceState interactionSourceState, Mi
// END WORKAROUND: Unity issue #1033526

interactionMapping.BoolData = selectPressed;

// If our value changed raise it.
if (interactionMapping.Changed)
{
// Raise input system Event if it enabled
if (interactionMapping.BoolData)
{
MixedRealityToolkit.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
else
{
MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
}

// If our value was updated, raise it.
if (interactionMapping.Updated)
{
MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
break;
}
case DeviceInputType.Trigger:
{
// Update the interaction data source
interactionMapping.FloatData = interactionSourceState.selectPressedAmount;

// If our value was updated, raise it.
if (interactionMapping.Updated)
{
// Raise input system Event if it enabled
MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, interactionSourceState.selectPressedAmount);
}
break;
}
case DeviceInputType.TriggerTouch:
{
// Update the interaction data source
interactionMapping.BoolData = interactionSourceState.selectPressedAmount > 0;

// If our value changed raise it.
if (interactionMapping.Changed)
{
// Raise input system Event if it enabled
if (interactionSourceState.selectPressedAmount > 0)
{
MixedRealityToolkit.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
else
{
MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
}

// If our value was updated, raise it.
if (interactionMapping.Updated)
{
// Raise input system Event if it enabled
MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, interactionSourceState.selectPressedAmount);
}
break;
}
}
Expand All @@ -528,28 +369,7 @@ private void UpdateTriggerData(InteractionSourceState interactionSourceState, Mi
/// <param name="interactionMapping"></param>
private void UpdateMenuData(InteractionSourceState interactionSourceState, MixedRealityInteractionMapping interactionMapping)
{
//Update the interaction data source
interactionMapping.BoolData = interactionSourceState.menuPressed;

// If our value changed raise it.
if (interactionMapping.Changed)
{
// Raise input system Event if it enabled
if (interactionMapping.BoolData)
{
MixedRealityToolkit.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
else
{
MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
}

// If our value was updated, raise it.
if (interactionMapping.Updated)
{
MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
}

#endregion Update data functions
Expand Down
15 changes: 8 additions & 7 deletions Controllers/WindowsMixedRealityDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#if UNITY_WSA
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.XR.WSA.Input;
using XRTK.Definitions.Devices;
Expand Down Expand Up @@ -80,9 +79,6 @@ public WindowsMixedRealityDataProvider(string name, uint priority, WindowsMixedR
/// </summary>
public InteractionSourceState[] LastInteractionManagerStateReading { get; protected set; }

/// <inheritdoc/>
public override IMixedRealityController[] GetActiveControllers() => activeControllers.Values.ToArray();

private static bool gestureRecognizerEnabled;

/// <summary>
Expand Down Expand Up @@ -373,7 +369,7 @@ public override void Disable()

for (var i = 0; i < states.Length; i++)
{
RemoveController(states[i]);
RemoveController(states[i], false);
}
}

Expand Down Expand Up @@ -441,6 +437,7 @@ private WindowsMixedRealityController GetController(InteractionSource interactio
}

activeControllers.Add(interactionSource.id, detectedController);
AddController(detectedController);
return detectedController;
}

Expand Down Expand Up @@ -500,16 +497,20 @@ async void DispatchedHandler()
/// Remove the selected controller from the Active Store
/// </summary>
/// <param name="interactionSourceState">Source State provided by the SDK to remove</param>
private void RemoveController(InteractionSourceState interactionSourceState)
private void RemoveController(InteractionSourceState interactionSourceState, bool clearFromRegistry = true)
{
var controller = GetController(interactionSourceState.source);

if (controller != null)
{
MixedRealityToolkit.InputSystem?.RaiseSourceLost(controller.InputSource, controller);
RemoveController(controller);
}

activeControllers.Remove(interactionSourceState.source.id);
if (clearFromRegistry)
{
activeControllers.Remove(interactionSourceState.source.id);
}
}

#endregion Controller Utilities
Expand Down
Loading

0 comments on commit c9cbc49

Please sign in to comment.