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

Commit

Permalink
Better button support (#17)
Browse files Browse the repository at this point in the history
* Fixes issues with bumper and home button

* more updates to the controller and added touch gesture events

* reverted some changes and updated packages

* updated home button press state when button is down, not up

* updated packages
  • Loading branch information
StephenHodgson authored May 3, 2019
1 parent e71ab97 commit 006dfeb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 27 deletions.
47 changes: 27 additions & 20 deletions Controllers/LuminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public LuminController(TrackingState trackingState, Handedness controllerHandedn
new MixedRealityInteractionMapping(5, "Home Press", AxisType.Digital, DeviceInputType.ButtonPress, MixedRealityInputAction.None),
new MixedRealityInteractionMapping(6, "Touchpad Position", AxisType.DualAxis, DeviceInputType.Touchpad, MixedRealityInputAction.None),
new MixedRealityInteractionMapping(7, "Touchpad Press", AxisType.SingleAxis, DeviceInputType.TouchpadPress, MixedRealityInputAction.None),
new MixedRealityInteractionMapping(8, "Touchpad Touch", AxisType.SingleAxis, DeviceInputType.TouchpadTouch, MixedRealityInputAction.None),
};

/// <inheritdoc />
Expand All @@ -50,6 +51,8 @@ public override void SetupDefaultInteractions(Handedness controllerHandedness)
internal MLInputController MlControllerReference { get; set; }
//internal LuminControllerGestureSettings ControllerGestureSettings { get; set; }

internal bool IsHomePressed;

private MixedRealityPose currentPointerPose = MixedRealityPose.ZeroIdentity;
private MixedRealityPose lastControllerPose = MixedRealityPose.ZeroIdentity;
private MixedRealityPose currentControllerPose = MixedRealityPose.ZeroIdentity;
Expand Down Expand Up @@ -166,12 +169,18 @@ private void UpdateButtonData(MixedRealityInteractionMapping interactionMapping)
{
Debug.Assert(interactionMapping.AxisType == AxisType.Digital);

var buttonId = interactionMapping.Description.Contains("Home")
? (int)MLInputControllerButton.HomeTap
: (int)MLInputControllerButton.Bumper;
var isHomeButton = interactionMapping.Description.Contains("Home");

// Update the interaction data source
interactionMapping.BoolData = MlControllerReference.State.ButtonState[buttonId] == 1;
if (!isHomeButton)
{
interactionMapping.BoolData = MlControllerReference.State.ButtonState[(int)MLInputControllerButton.Bumper] > 0;
}
else
{
interactionMapping.BoolData = IsHomePressed;
IsHomePressed = false;
}

// If our value changed raise it.
if (interactionMapping.Changed)
Expand All @@ -186,12 +195,11 @@ private void UpdateButtonData(MixedRealityInteractionMapping interactionMapping)
MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
}
else


if (interactionMapping.Updated)
{
if (interactionMapping.BoolData)
{
MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
}

Expand All @@ -207,21 +215,22 @@ private void UpdateSingleAxisData(MixedRealityInteractionMapping interactionMapp
{
case DeviceInputType.Select:
case DeviceInputType.TriggerPress:
case DeviceInputType.TouchpadPress:
// Update the interaction data source
interactionMapping.BoolData = singleAxisValue.Equals(1);
interactionMapping.BoolData = singleAxisValue.Equals(1f);
break;
case DeviceInputType.TriggerTouch:
case DeviceInputType.TouchpadTouch:
case DeviceInputType.TriggerNearTouch:
// Update the interaction data source
interactionMapping.BoolData = !singleAxisValue.Equals(0);
interactionMapping.BoolData = !singleAxisValue.Equals(0f);
break;
case DeviceInputType.Trigger:
case DeviceInputType.TouchpadPress:
// Update the interaction data source
interactionMapping.FloatData = singleAxisValue;

// If our value changed raise it.
if (interactionMapping.Changed)
if (interactionMapping.Updated)
{
// Raise input system Event if it enabled
MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, interactionMapping.FloatData);
Expand All @@ -245,12 +254,10 @@ private void UpdateSingleAxisData(MixedRealityInteractionMapping interactionMapp
MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
}
else

if (interactionMapping.Updated)
{
if (interactionMapping.BoolData)
{
MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, singleAxisValue);
}
MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, singleAxisValue);
}
}

Expand All @@ -265,7 +272,7 @@ private void UpdateDualAxisData(MixedRealityInteractionMapping interactionMappin
interactionMapping.Vector2Data = dualAxisPosition;

// If our value changed raise it.
if (interactionMapping.Changed)
if (interactionMapping.Updated)
{
// Raise input system Event if it enabled
MixedRealityToolkit.InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, interactionMapping.Vector2Data);
Expand All @@ -291,7 +298,7 @@ private void UpdatePoseData(MixedRealityInteractionMapping interactionMapping)
interactionMapping.PoseData = currentPointerPose;

// If our value changed raise it.
if (interactionMapping.Changed)
if (interactionMapping.Updated)
{
// Raise input system Event if it enabled
MixedRealityToolkit.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, interactionMapping.PoseData);
Expand Down
26 changes: 19 additions & 7 deletions Controllers/LuminControllerDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class LuminControllerDataProvider : BaseControllerDataProvider
/// <param name="name"></param>
/// <param name="priority"></param>
/// <param name="profile"></param>
public LuminControllerDataProvider(string name, uint priority, BaseMixedRealityControllerDataProviderProfile profile)
public LuminControllerDataProvider(string name, uint priority, BaseMixedRealityControllerDataProviderProfile profile)
: base(name, priority, profile)
{
}
Expand All @@ -42,9 +42,9 @@ public override IMixedRealityController[] GetActiveControllers()
{
var list = new List<IMixedRealityController>();

foreach (LuminController value in activeControllers.Values)
foreach (var controller in activeControllers.Values)
{
list.Add(value);
list.Add(controller);
}

return list.ToArray();
Expand Down Expand Up @@ -91,6 +91,7 @@ public override void Enable()

MLInput.OnControllerConnected += OnControllerConnected;
MLInput.OnControllerDisconnected += OnControllerDisconnected;
MLInput.OnControllerButtonDown += MlInputOnControllerButtonDown;
}

/// <inheritdoc />
Expand All @@ -100,15 +101,14 @@ public override void Update()
{
controller.Value?.UpdateController();
}

// TODO Update hand gestures
}

/// <inheritdoc />
public override void Disable()
{
MLInput.OnControllerConnected -= OnControllerConnected;
MLInput.OnControllerDisconnected -= OnControllerDisconnected;
MLInput.OnControllerButtonDown -= MlInputOnControllerButtonDown;
MLInput.Stop();
MLHands.Stop();

Expand Down Expand Up @@ -188,9 +188,8 @@ private void OnControllerConnected(byte controllerId)
if (controller != null)
{
MixedRealityToolkit.InputSystem?.RaiseSourceDetected(controller.InputSource, controller);
controller.UpdateController();
}

controller?.UpdateController();
}

private void OnControllerDisconnected(byte controllerId)
Expand All @@ -205,6 +204,19 @@ private void OnControllerDisconnected(byte controllerId)
activeControllers.Remove(controllerId);
}

private void MlInputOnControllerButtonDown(byte controllerId, MLInputControllerButton button)
{
if (activeControllers.TryGetValue(controllerId, out var controller))
{
switch (button)
{
case MLInputControllerButton.HomeTap:
controller.IsHomePressed = true;
break;
}
}
}

#endregion Controller Events

#endif // PLATFORM_LUMIN
Expand Down

0 comments on commit 006dfeb

Please sign in to comment.