TEST(BasicJointClientKitWithInterface, ConstructDestruct) {
    auto options = osvrJointClientCreateOptions();
    ASSERT_NE(nullptr, options);

    ASSERT_EQ(OSVR_RETURN_SUCCESS,
      osvrJointClientOptionsLoadPlugin(options, "com_osvr_example_AnalogSync"));

    ASSERT_EQ(OSVR_RETURN_SUCCESS,
      osvrJointClientOptionsTriggerHardwareDetect(options));

    auto ctx = osvrJointClientInit("org.osvr.test.jointclientkit", options);
    ASSERT_NE(nullptr, ctx);
    ASSERT_EQ(OSVR_RETURN_SUCCESS,
      osvrClientUpdate(ctx));

    OSVR_ClientInterface eye = nullptr;
    ASSERT_EQ(OSVR_RETURN_SUCCESS,
      osvrClientGetInterface(ctx, "/com_osvr_example_AnalogSync/MySyncDevice/analog/0", &eye));

    ASSERT_EQ(OSVR_RETURN_SUCCESS,
      osvrRegisterAnalogCallback(eye, &myAnalogCallback, nullptr));

    ASSERT_EQ(OSVR_RETURN_SUCCESS,
      osvrClientUpdate(ctx));

    ASSERT_EQ(true, reportReceived);

    ASSERT_EQ(OSVR_RETURN_SUCCESS,
      osvrClientShutdown(ctx));
}
Example #2
0
void OSVRInterface::RegisterCallbacks()
{
#if OSVR_ENABLED

	if (HasPoseState())
	{
		//osvrRegisterPoseCallback(GetRawInterface(), &OSVRPoseCallback, this);
	}
	/*else*/ if (HasPositionState())
	{
		osvrRegisterPositionCallback(GetRawInterface(), &OSVRPositionCallback, this);
	}
	/*else*/ if (HasOrientationState())
	{
		osvrRegisterOrientationCallback(GetRawInterface(), &OSVROrientationCallback, this);
	}

	if (HasAnalogState())
	{
		osvrRegisterAnalogCallback(GetRawInterface(), &OSVRAnalogCallback, this);
	}

	if (HasButtonState())
	{
		osvrRegisterButtonCallback(GetRawInterface(), &OSVRButtonCallback, this);
	}

#endif // OSVR_ENABLED
}
Example #3
0
FOSVRInputDevice::FOSVRInputDevice(
    const TSharedRef< FGenericApplicationMessageHandler >& InMessageHandler,
    TSharedPtr<OSVREntryPoint, ESPMode::ThreadSafe> osvrEntryPoint,
    TSharedPtr<FOSVRHMD, ESPMode::ThreadSafe> osvrHMD) :
    mOSVREntryPoint(osvrEntryPoint), mOSVRHMD(osvrHMD), MessageHandler(InMessageHandler)
{
    // make sure OSVR module is loaded.
    contextMutex = mOSVREntryPoint->GetClientContextMutex();
    FScopeLock lock(contextMutex);
    context = mOSVREntryPoint->GetClientContext();

    bContextValid = context && osvrClientCheckStatus(context) == OSVR_RETURN_SUCCESS;

    if (bContextValid)
    {
        const float defaultThreshold = 0.25f;

        TSharedPtr<OSVRButton> buttons[] =
        {
            // left hand
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::SpecialLeft, "/controller/left/middle")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Left_Shoulder, "/controller/left/bumper")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Left_Thumbstick, "/controller/left/joystick/button")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Left_FaceButton1, "/controller/left/1")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Left_FaceButton2, "/controller/left/2")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Left_FaceButton3, "/controller/left/3")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Left_FaceButton4, "/controller/left/4")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::MotionController_Left_Thumbstick_X, "/controller/left/joystick/x")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_GT, defaultThreshold, FGamepadKeyNames::MotionController_Left_Thumbstick_Right, "/controller/left/joystick/x")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_LT, -defaultThreshold, FGamepadKeyNames::MotionController_Left_Thumbstick_Left, "/controller/left/joystick/x")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::MotionController_Left_Thumbstick_Y, "/controller/left/joystick/y")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_GT, defaultThreshold, FGamepadKeyNames::MotionController_Left_Thumbstick_Up, "/controller/left/joystick/y")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_LT, -defaultThreshold, FGamepadKeyNames::MotionController_Left_Thumbstick_Down, "/controller/left/joystick/y")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::MotionController_Left_TriggerAxis, "/controller/left/trigger")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, FGamepadKeyNames::MotionController_Left_Trigger, "/controller/left/trigger")),

            // right hand
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::SpecialRight, "/controller/right/middle")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Right_Shoulder, "/controller/right/bumper")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Right_Thumbstick, "/controller/right/joystick/button")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Right_FaceButton1, "/controller/right/1")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Right_FaceButton2, "/controller/right/2")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Right_FaceButton3, "/controller/right/3")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Right_FaceButton4, "/controller/right/4")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::MotionController_Right_Thumbstick_X, "/controller/right/joystick/x")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_GT, defaultThreshold, FGamepadKeyNames::MotionController_Right_Thumbstick_Right, "/controller/right/joystick/x")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_LT, -defaultThreshold, FGamepadKeyNames::MotionController_Right_Thumbstick_Left, "/controller/right/joystick/x")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::MotionController_Right_Thumbstick_Y, "/controller/right/joystick/y")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_GT, defaultThreshold, FGamepadKeyNames::MotionController_Right_Thumbstick_Up, "/controller/right/joystick/y")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_LT, -defaultThreshold, FGamepadKeyNames::MotionController_Right_Thumbstick_Down, "/controller/right/joystick/y")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::MotionController_Right_TriggerAxis, "/controller/right/trigger")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, FGamepadKeyNames::MotionController_Right_Trigger, "/controller/right/trigger")),

            // "controller" (like xbox360)
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::RightShoulder, "/controller/right/bumper")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::RightThumb, "/controller/right/joystick/button")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::FaceButtonBottom, "/controller/right/1")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::FaceButtonRight, "/controller/right/2")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::FaceButtonLeft, "/controller/right/3")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::FaceButtonTop, "/controller/right/4")),

            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::LeftShoulder, "/controller/left/bumper")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::LeftThumb, "/controller/left/joystick/button")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::DPadDown, "/controller/left/1")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::DPadRight, "/controller/left/2")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::DPadLeft, "/controller/left/3")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::DPadUp, "/controller/left/4")),

            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::LeftAnalogX, "/controller/left/joystick/x")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_GT, defaultThreshold, FGamepadKeyNames::LeftStickRight, "/controller/left/joystick/x")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_LT, -defaultThreshold, FGamepadKeyNames::LeftStickLeft, "/controller/left/joystick/x")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::LeftAnalogY, "/controller/left/joystick/y")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_GT, defaultThreshold, FGamepadKeyNames::LeftStickUp, "/controller/left/joystick/y")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_LT, -defaultThreshold, FGamepadKeyNames::LeftStickDown, "/controller/left/joystick/y")),

            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::RightAnalogX, "/controller/right/joystick/x")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_GT, defaultThreshold, FGamepadKeyNames::RightStickRight, "/controller/right/joystick/x")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_LT, -defaultThreshold, FGamepadKeyNames::RightStickLeft, "/controller/right/joystick/x")),

            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::RightAnalogY, "/controller/right/joystick/y")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_GT, defaultThreshold, FGamepadKeyNames::RightStickUp, "/controller/right/joystick/y")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, OSVR_THRESHOLD_TYPE_LT, -defaultThreshold, FGamepadKeyNames::RightStickDown, "/controller/right/joystick/y")),

            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::LeftTriggerAnalog, "/controller/left/trigger")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_ANALOG, FGamepadKeyNames::RightTriggerAnalog, "/controller/right/trigger")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, FGamepadKeyNames::LeftTriggerThreshold, "/controller/left/trigger")),
            MakeShareable(new OSVRButton(OSVR_BUTTON_TYPE_THRESHOLD, FGamepadKeyNames::RightTriggerThreshold, "/controller/right/trigger")),
        };
        osvrButtons.Append(buttons, ARRAY_COUNT(buttons));

        for (auto& button : osvrButtons)
        {
            auto ifaceItr = interfaces.Find(button->ifacePath);
            OSVR_ClientInterface iface = nullptr;
            if (!ifaceItr)
            {
                if (osvrClientGetInterface(context, TCHAR_TO_ANSI(*(button->ifacePath)), &iface) != OSVR_RETURN_SUCCESS)
                {
                    button->bIsValid = false;
                }
                else
                {
                    interfaces.Add(button->ifacePath, iface);
                }
            }
            else
            {
                iface = *ifaceItr;
            }

            if (button->bIsValid)
            {
                if (button->type == OSVR_BUTTON_TYPE_DIGITAL)
                {
                    if (osvrRegisterButtonCallback(iface, buttonCallback, button.Get()) == OSVR_RETURN_FAILURE)
                    {
                        button->bIsValid = false;
                    }
                }

                if (button->type == OSVR_BUTTON_TYPE_ANALOG ||
                    button->type == OSVR_BUTTON_TYPE_THRESHOLD)
                {
                    if (osvrRegisterAnalogCallback(iface, analogCallback, button.Get()) == OSVR_RETURN_FAILURE)
                    {
                        button->bIsValid = false;
                    }
                }
            }
        }

        bLeftHandValid = osvrClientGetInterface(context, "/me/hands/left", &leftHand)
            == OSVR_RETURN_SUCCESS;

        bRightHandValid = osvrClientGetInterface(context, "/me/hands/right", &rightHand)
            == OSVR_RETURN_SUCCESS;

        IModularFeatures::Get().RegisterModularFeature(GetModularFeatureName(), this);

#if !OSVR_UNREAL_4_12
        // This may need to be removed in a future version of the engine.
        // From the SteamVR plugin: "construction of the controller happens after InitializeMotionControllers(), so we manually add this to the array here"
        GEngine->MotionControllerDevices.AddUnique(this);
#endif
    }
}