Skip to content

Commit 793f63c

Browse files
author
lawwong
committed
Add UnknownControllerState from CommonUsages
1 parent a5a0c5f commit 793f63c

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

Assets/HTC.UnityPlugin/VRModule/Modules/UnityXRModule.cs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected override void UpdateNewConnectedInputDevice(IVRModuleDeviceStateRW sta
120120
updateFunc = UpdateWaveCRControllerState;
121121
break;
122122
default:
123-
updateFunc = null;
123+
updateFunc = UpdateUnknownControllerState;
124124
break;
125125
}
126126

@@ -176,6 +176,48 @@ private void UpdateControllerState(IVRModuleDeviceStateRW state, InputDevice dev
176176
}
177177
}
178178

179+
private void UpdateUnknownControllerState(IVRModuleDeviceStateRW state, InputDevice device)
180+
{
181+
bool primaryButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.primaryButton);
182+
bool primaryTouch = GetDeviceFeatureValueOrDefault(device, CommonUsages.primaryTouch);
183+
bool secondaryButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondaryButton);
184+
bool secondaryTouch = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondaryTouch);
185+
bool gripButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.gripButton);
186+
bool triggerButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.triggerButton);
187+
bool menuButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.menuButton);
188+
bool primary2DAxisClick = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxisClick);
189+
bool primary2DAxisTouch = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxisTouch);
190+
bool secondary2DAxisClick = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondary2DAxisClick);
191+
bool secondary2DAxisTouch = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondary2DAxisTouch);
192+
193+
float triggerValue = GetDeviceFeatureValueOrDefault(device, CommonUsages.trigger);
194+
float gripValue = GetDeviceFeatureValueOrDefault(device, CommonUsages.grip);
195+
196+
Vector2 primary2DAxisValue = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxis);
197+
Vector2 secondary2DAxisValue = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondary2DAxis);
198+
199+
state.SetButtonPress(VRModuleRawButton.A, primaryButton);
200+
state.SetButtonPress(VRModuleRawButton.ApplicationMenu, secondaryButton | menuButton);
201+
state.SetButtonPress(VRModuleRawButton.Trigger, triggerButton);
202+
state.SetButtonPress(VRModuleRawButton.Grip, gripButton);
203+
state.SetButtonPress(VRModuleRawButton.Touchpad, primary2DAxisClick);
204+
state.SetButtonPress(VRModuleRawButton.Joystick, secondary2DAxisClick);
205+
206+
state.SetButtonTouch(VRModuleRawButton.A, primaryTouch);
207+
state.SetButtonTouch(VRModuleRawButton.ApplicationMenu, secondaryTouch | menuButton);
208+
state.SetButtonTouch(VRModuleRawButton.Trigger, triggerButton);
209+
state.SetButtonTouch(VRModuleRawButton.Grip, gripButton);
210+
state.SetButtonTouch(VRModuleRawButton.Touchpad, primary2DAxisTouch);
211+
state.SetButtonTouch(VRModuleRawButton.Joystick, secondary2DAxisTouch);
212+
213+
state.SetAxisValue(VRModuleRawAxis.Trigger, triggerValue);
214+
state.SetAxisValue(VRModuleRawAxis.CapSenseGrip, gripValue);
215+
state.SetAxisValue(VRModuleRawAxis.TouchpadX, primary2DAxisValue.x);
216+
state.SetAxisValue(VRModuleRawAxis.TouchpadY, primary2DAxisValue.y);
217+
state.SetAxisValue(VRModuleRawAxis.JoystickX, secondary2DAxisValue.x);
218+
state.SetAxisValue(VRModuleRawAxis.JoystickY, secondary2DAxisValue.y);
219+
}
220+
179221
private void UpdateViveControllerState(IVRModuleDeviceStateRW state, InputDevice device)
180222
{
181223
bool menuButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.menuButton);

Assets/HTC.UnityPlugin/VRModule/Submodules/ViveHandTrackingSubmodule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private IEnumerator StartDetectionCoroutine()
7171
retryCount = RETRY_COUNT;
7272
lastResultFrame = -1;
7373
isStarted = true;
74-
Debug.Log(LOG_PREFIX + "StartGestureDetection");
74+
Debug.Log(LOG_PREFIX + "Detection started");
7575
break;
7676
case GestureFailure.Camera:
7777
--retryCount;
@@ -121,7 +121,7 @@ protected override void OnUpdateDeviceConnectionAndPoses()
121121

122122
if (resultFrame < 0)
123123
{
124-
Debug.Log("[ViveHandTrackingSubmodule] Detection stopped!");
124+
Debug.Log(LOG_PREFIX + "Detection stopped");
125125
isStarted = false;
126126
return;
127127
}

Assets/HTC.UnityPlugin/VRModule/VRModuleBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ protected static void SetupKnownDeviceModel(IVRModuleDeviceStateRW deviceState)
386386
}
387387

388388
deviceState.deviceModel = VRModuleDeviceModel.Unknown;
389+
deviceState.input2DType = VRModuleInput2DType.Unknown;
389390
}
390391

391392
public static bool AxisToPress(bool previousPressedState, float currentAxisValue, float setThreshold, float unsetThreshold)

0 commit comments

Comments
 (0)