diff --git a/.gitignore b/.gitignore index 232aa8c..b59be1e 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ # Build directory build +nbproject +CMakeFiles diff --git a/openvr b/openvr index b653929..5d0574b 160000 --- a/openvr +++ b/openvr @@ -1 +1 @@ -Subproject commit b6539291b88eaa65c58c076cafe4eacd0ae2e062 +Subproject commit 5d0574bf6473130d25dd296ad30206ccd148590b diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ad58d6b..ef80985 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,6 +47,8 @@ add_library(driver_osvr OSVRDisplay.cpp OSVRTrackedDevice.cpp OSVRTrackedDevice.h + OSVRTrackedController.cpp + OSVRTrackedController.h OSVRTrackedHMD.cpp OSVRTrackedHMD.h OSVRTrackingReference.cpp diff --git a/src/OSVRTrackedController.cpp b/src/OSVRTrackedController.cpp new file mode 100644 index 0000000..ff0807f --- /dev/null +++ b/src/OSVRTrackedController.cpp @@ -0,0 +1,499 @@ +/** @file + @brief OSVR tracked controller + + @date 2015 + + @author + Sensics, Inc. + +*/ + +// Copyright 2015 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Internal Includes +#include "OSVRTrackedController.h" + +#include "osvr_compiler_detection.h" +#include "make_unique.h" +#include "matrix_cast.h" +#include "ValveStrCpy.h" +#include "platform_fixes.h" // strcasecmp +#include "Logging.h" + +// OpenVR includes +#include + +// Library/third-party includes +#include +#include +#include +#include + +// Standard includes +#include +#include +#include +#include +#include + +// TODO: +// Joystick support +// OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Left_Thumbstick, "/controller/left/joystick/button"), +// OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::MotionController_Left_Shoulder, "/controller/left/bumper"), +// OSVRButton(OSVR_BUTTON_TYPE_DIGITAL, FGamepadKeyNames::SpecialLeft, "/controller/left/middle"), + +OSVRTrackedController::OSVRTrackedController(osvr::clientkit::ClientContext& context, int controller_index) : + OSVRTrackedDevice(context, vr::TrackedDeviceClass_Controller, "OSVR controller"+std::to_string(controller_index)), controllerIndex_(controller_index) +{ + OSVR_LOG(trace) << "OSVRTrackedController::constructor() called. name = " << name_ <<"\n"; +} + +OSVRTrackedController::~OSVRTrackedController() +{ + // DO NOTHING +} + +vr::EVRInitError OSVRTrackedController::Activate(uint32_t object_id) +{ + OSVRTrackedDevice::Activate(object_id); + const std::time_t wait_time = 5; // wait up to 5 seconds for init + + freeInterfaces(); + + // Ensure context is fully started up + OSVR_LOG(info) << "Waiting for the context to fully start up..."; + const auto start_time = std::time(nullptr); + while (!context_.checkStatus()) { + context_.update(); + if (std::time(nullptr) > start_time + wait_time) { + OSVR_LOG(warn) << "Context startup timed out!"; + return vr::VRInitError_Driver_Failed; + } + } + + // Register callbacks + std::string trackerPath; + std::string buttonPath; + std::string triggerPath; + std::string joystickPath; + std::string trackpadPath; + std::string batteryPath; + if (controllerIndex_ == vr::TrackedControllerRole_LeftHand) { + trackerPath = "/me/hands/left"; + buttonPath = "/controller/left/"; + triggerPath = "/controller/left/trigger"; + joystickPath = "/controller/left/joystick"; + trackpadPath = "/controller/left/trackpad"; + batteryPath = "/controller/left/battery"; + } else if (controllerIndex_ == vr::TrackedControllerRole_RightHand) { + trackerPath = "/me/hands/right"; + buttonPath = "/controller/right/"; + triggerPath = "/controller/right/trigger"; + joystickPath = "/controller/right/joystick"; + trackpadPath = "/controller/right/trackpad"; + batteryPath = "/controller/right/battery"; + } else { + buttonPath = "/controller" + std::to_string(controllerIndex_) + "/"; + triggerPath = "/controller" + std::to_string(controllerIndex_) + "/trigger"; + joystickPath = "/controller" + std::to_string(controllerIndex_) + "/joystick"; + } + + if (!trackerPath.empty()) { + trackerInterface_ = context_.getInterface(trackerPath); + if(trackerInterface_.notEmpty()){ + OSVR_LOG(trace) << "OSVRTrackedController::Activate() tracker Interface is empty "<(userdata); + + vr::DriverPose_t pose = { 0 }; + pose.poseTimeOffset = 0; // close enough + + Eigen::Vector3d::Map(pose.vecWorldFromDriverTranslation) = Eigen::Vector3d::Zero(); + Eigen::Vector3d::Map(pose.vecDriverFromHeadTranslation) = Eigen::Vector3d::Zero(); + + map(pose.qWorldFromDriverRotation) = Eigen::Quaterniond::Identity(); + map(pose.qDriverFromHeadRotation) = Eigen::Quaterniond::Identity(); + //pose.qWorldFromDriverRotation = HmdQuaternion_Init(1, 0, 0, 0); + //pose.qDriverFromHeadRotation = HmdQuaternion_Init(1, 0, 0, 0); + + // Position + Eigen::Vector3d::Map(pose.vecPosition) = osvr::util::vecMap(report->pose.translation); + + // Position velocity and acceleration are not currently consistently provided + Eigen::Vector3d::Map(pose.vecVelocity) = Eigen::Vector3d::Zero(); + Eigen::Vector3d::Map(pose.vecAcceleration) = Eigen::Vector3d::Zero(); + + // Orientation + map(pose.qRotation) = osvr::util::fromQuat(report->pose.rotation); + + // Angular velocity and acceleration are not currently consistently provided + Eigen::Vector3d::Map(pose.vecAngularVelocity) = Eigen::Vector3d::Zero(); + Eigen::Vector3d::Map(pose.vecAngularAcceleration) = Eigen::Vector3d::Zero(); + + pose.result = vr::TrackingResult_Running_OK; + pose.poseIsValid = true; + //pose.willDriftInYaw = true; + //pose.shouldApplyHeadModel = true; + pose.deviceIsConnected = true; + + self->pose_ = pose; + + vr::VRServerDriverHost()->TrackedDevicePoseUpdated(self->objectId_, self->pose_,sizeof(self->pose_)); +} + +void OSVRTrackedController::controllerButtonCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_ButtonReport* report) +{ + if (!userdata) + return; + + auto* button_interface = static_cast(userdata); + OSVRTrackedController* self = button_interface->parentController; + if(!self){ + return; + } + + // error checking + if((button_interface->button_id >=0 && button_interface->button_id <= 7) || (button_interface->button_id >= 31 && button_interface->button_id <= 36)){ + if (OSVR_BUTTON_PRESSED == report->state) { + vr::VRServerDriverHost()->TrackedDeviceButtonPressed(self->objectId_, button_interface->button_id, 0); + } else { + vr::VRServerDriverHost()->TrackedDeviceButtonUnpressed(self->objectId_, button_interface->button_id, 0); + } + } +} + +void OSVRTrackedController::controllerButtonTouchCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_ButtonReport* report) +{ + if (!userdata) + return; + + auto* button_interface = static_cast(userdata); + OSVRTrackedController* self = button_interface->parentController; + if(!self){ + return; + } + + // error checking + if((button_interface->button_id >=0 && button_interface->button_id <= 7) || (button_interface->button_id >= 31 && button_interface->button_id <= 36)){ + if (OSVR_BUTTON_PRESSED == report->state) { + vr::VRServerDriverHost()->TrackedDeviceButtonTouched(self->objectId_, button_interface->button_id, 0); + } else { + vr::VRServerDriverHost()->TrackedDeviceButtonUntouched(self->objectId_, button_interface->button_id, 0); + } + } +} + +void OSVRTrackedController::controllerTriggerCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_AnalogReport* report) +{ + if (!userdata) + return; + + auto* analog_interface = static_cast(userdata); + OSVRTrackedController* self = analog_interface->parentController; + + analog_interface->x = report->state; + + vr::VRControllerAxis_t axis_state; + axis_state.x = static_cast(analog_interface->x); + axis_state.y = 0; + + vr::VRServerDriverHost()->TrackedDeviceAxisUpdated(self->objectId_, analog_interface->axisIndex, axis_state); +} + +void OSVRTrackedController::controllerBatteryCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_AnalogReport* report) +{ + if (!userdata) + return; + + auto* batteryInterface = static_cast(userdata); + OSVRTrackedController* self = batteryInterface->parentController; + vr::PropertyContainerHandle_t container = vr::VRProperties()->TrackedDeviceToPropertyContainer(self->objectId_); + vr::VRProperties()->SetFloatProperty(container, vr::Prop_DeviceBatteryPercentage_Float, report->state); +} + +void OSVRTrackedController::controllerXAxisCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_AnalogReport* report) +{ + if (!userdata) + return; + + auto* analog_interface = static_cast(userdata); + OSVRTrackedController* self = analog_interface->parentController; + + analog_interface->x = report->state; + + vr::VRControllerAxis_t axis_state; + axis_state.x = static_cast(analog_interface->x); + axis_state.y = static_cast(analog_interface->y); + + vr::VRServerDriverHost()->TrackedDeviceAxisUpdated(self->objectId_, analog_interface->axisIndex, axis_state); +} + +void OSVRTrackedController::controllerYAxisCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_AnalogReport* report) +{ + if (!userdata) + return; + + auto* analog_interface = static_cast(userdata); + OSVRTrackedController* self = analog_interface->parentController; + + analog_interface->y = report->state; + + vr::VRControllerAxis_t axis_state; + axis_state.x = static_cast(analog_interface->x); + axis_state.y = static_cast(analog_interface->y); + + vr::VRServerDriverHost()->TrackedDeviceAxisUpdated(self->objectId_, analog_interface->axisIndex, axis_state); +} + +const char* OSVRTrackedController::GetId() +{ + /// @todo When available, return the actual unique ID of the HMD + return name_.c_str(); +} + +void OSVRTrackedController::configure() +{ + configureProperties(); +} + +void OSVRTrackedController::configureProperties() +{ + + propertyContainer_ = vr::VRProperties()->TrackedDeviceToPropertyContainer(this->objectId_); + // Additional properties from nolo's osvr tracked device + vr::VRProperties()->SetStringProperty(propertyContainer_, vr::Prop_TrackingSystemName_String, "NoloVR"); + vr::VRProperties()->SetStringProperty(propertyContainer_, vr::Prop_ManufacturerName_String, "LYRobotix"); + vr::VRProperties()->SetStringProperty(propertyContainer_, vr::Prop_TrackingFirmwareVersion_String, "0.1.0"); + vr::VRProperties()->SetStringProperty(propertyContainer_, vr::Prop_HardwareRevision_String, "0.1.0"); + vr::VRProperties()->SetStringProperty(propertyContainer_, vr::Prop_AllWirelessDongleDescriptions_String, ""); + vr::VRProperties()->SetStringProperty(propertyContainer_, vr::Prop_ConnectedWirelessDongle_String, ""); + vr::VRProperties()->SetStringProperty(propertyContainer_, vr::Prop_Firmware_ManualUpdateURL_String, ""); + vr::VRProperties()->SetStringProperty(propertyContainer_, vr::Prop_Firmware_ProgrammingTarget_String, ""); + vr::VRProperties()->SetStringProperty(propertyContainer_, vr::Prop_DriverVersion_String, "0.1.0"); + vr::VRProperties()->SetStringProperty(propertyContainer_, vr::Prop_AttachedDeviceId_String, "3000"); + vr::VRProperties()->SetStringProperty(propertyContainer_, vr::Prop_ModeLabel_String, ""); + //vr::VRProperties()->SetBoolProperty(propertyContainer_, vr::Prop_WillDriftInYaw_Bool, true); + //vr::VRProperties()->SetBoolProperty(propertyContainer_, vr::Prop_DeviceIsWireless_Bool, false); + vr::VRProperties()->SetInt32Property(propertyContainer_, vr::Prop_DeviceClass_Int32, static_cast(deviceClass_)); + /* + vr::VRProperties()->SetInt32Property(propertyContainer_, vr::Prop_Axis0Type_Int32, static_cast(analogInterface_[0].axisType)); + vr::VRProperties()->SetInt32Property(propertyContainer_, vr::Prop_Axis1Type_Int32, static_cast(analogInterface_[1].axisType)); + vr::VRProperties()->SetInt32Property(propertyContainer_, vr::Prop_Axis2Type_Int32, static_cast(analogInterface_[2].axisType)); + vr::VRProperties()->SetInt32Property(propertyContainer_, vr::Prop_Axis3Type_Int32, static_cast(analogInterface_[3].axisType)); + vr::VRProperties()->SetInt32Property(propertyContainer_, vr::Prop_Axis4Type_Int32, static_cast(analogInterface_[4].axisType)); + vr::VRProperties()->SetUint64Property(propertyContainer_, vr::Prop_SupportedButtons_Uint64, static_cast(NUM_BUTTONS)); + */ + vr::VRProperties()->SetStringProperty(propertyContainer_, vr::Prop_ModelNumber_String, "OSVR Controller"); + vr::VRProperties()->SetStringProperty(propertyContainer_, vr::Prop_SerialNumber_String, name_.c_str()); + // set the vive controller at the default. + vr::VRProperties()->SetStringProperty(propertyContainer_, vr::Prop_RenderModelName_String, "vr_controller_vive_1_5"); + //vr::VRProperties()->SetStringProperty(propertyContainer_, vr::Prop_RenderModelName_String, settings_->getSetting("cameraRenderModel", "").c_str()); +} + +/** + * Registers a button based on the path and id. + * @param id the id of the button which is used for indexing an array. + * @param path the complete path to the button. + */ +void OSVRTrackedController::registerButton(int id, const std::string& path, vr::EVRButtonId button_id){ + // check bounds + if(id < 0 || id >= NUM_BUTTONS){ + return; + } + + buttonInterface_[id].buttonInterface = context_.getInterface(path); + if (buttonInterface_[id].buttonInterface.notEmpty()) { + buttonInterface_[id].button_id = button_id; + buttonInterface_[id].parentController = this; + buttonInterface_[id].buttonInterface.registerCallback( &OSVRTrackedController::controllerButtonCallback, &buttonInterface_[id]); + }else{ + buttonInterface_[id].buttonInterface.free(); + } +} + +/** + * Registers a touch button based on the path and id. + * @param id the id of the button which is used for indexing an array. + * @param path the complete path to the button. + */ +void OSVRTrackedController::registerButtonTouch(int id, const std::string& path, vr::EVRButtonId button_id){ + // check bounds + if(id < 0 || id >= NUM_BUTTONS){ + return; + } + + buttonInterface_[id].buttonInterface = context_.getInterface(path); + if (buttonInterface_[id].buttonInterface.notEmpty()) { + buttonInterface_[id].button_id = button_id; + buttonInterface_[id].parentController = this; + buttonInterface_[id].buttonInterface.registerCallback( &OSVRTrackedController::controllerButtonTouchCallback, &buttonInterface_[id]); + }else{ + buttonInterface_[id].buttonInterface.free(); + } +} + +void OSVRTrackedController::registerBattery(const std::string& path){ + batteryInterface.interface = context_.getInterface(path); + if (batteryInterface.interface.notEmpty()) { + batteryInterface.parentController = this; + batteryInterface.interface.registerCallback(&OSVRTrackedController::controllerBatteryCallback, &batteryInterface); + propertyContainer_ = vr::VRProperties()->TrackedDeviceToPropertyContainer(this->objectId_); + vr::VRProperties()->SetBoolProperty(propertyContainer_, vr::Prop_DeviceProvidesBatteryStatus_Bool,true); + } else { + batteryInterface.interface.free(); + } +} + +void OSVRTrackedController::registerTrigger(int id, const std::string& path){ + // check bounds + if(id < 0 || id >= NUM_AXIS){ + return; + } + analogInterface_[id].analogInterfaceX = context_.getInterface(path); + if (analogInterface_[id].analogInterfaceX.notEmpty()) { + analogInterface_[id].axisIndex = id; + analogInterface_[id].axisType = vr::EVRControllerAxisType::k_eControllerAxis_Trigger; + analogInterface_[id].parentController = this; + analogInterface_[id].analogInterfaceX.registerCallback(&OSVRTrackedController::controllerTriggerCallback, &analogInterface_[id]); + propertyContainer_ = vr::VRProperties()->TrackedDeviceToPropertyContainer(this->objectId_); + vr::VRProperties()->SetInt32Property(propertyContainer_, vr::Prop_Axis1Type_Int32, static_cast(analogInterface_[id].axisType)); + } else { + analogInterface_[id].analogInterfaceX.free(); + } +} + +void OSVRTrackedController::registerTrackpad(int id, const std::string& path){ + // check bounds + if(id < 0 || id >= NUM_AXIS){ + return; + } + analogInterface_[id].analogInterfaceX = context_.getInterface(path + "/x"); + analogInterface_[id].analogInterfaceY = context_.getInterface(path + "/y"); + + if (analogInterface_[id].analogInterfaceX.notEmpty()) { + analogInterface_[id].axisIndex = id; + analogInterface_[id].axisType = vr::EVRControllerAxisType::k_eControllerAxis_TrackPad; + analogInterface_[id].parentController = this; + analogInterface_[id].analogInterfaceX.registerCallback(&OSVRTrackedController::controllerXAxisCallback, &analogInterface_[id]); + propertyContainer_ = vr::VRProperties()->TrackedDeviceToPropertyContainer(this->objectId_); + vr::VRProperties()->SetInt32Property(propertyContainer_, vr::Prop_Axis0Type_Int32, static_cast(analogInterface_[id].axisType)); + } else { + analogInterface_[id].analogInterfaceX.free(); + } + + if (analogInterface_[id].analogInterfaceY.notEmpty()) { + analogInterface_[id].axisIndex = id; + analogInterface_[id].axisType = vr::EVRControllerAxisType::k_eControllerAxis_TrackPad; + analogInterface_[id].parentController = this; + analogInterface_[id].analogInterfaceY.registerCallback(&OSVRTrackedController::controllerYAxisCallback, &analogInterface_[id]); + propertyContainer_ = vr::VRProperties()->TrackedDeviceToPropertyContainer(this->objectId_); + vr::VRProperties()->SetInt32Property(propertyContainer_, vr::Prop_Axis0Type_Int32, static_cast(analogInterface_[id].axisType)); + } else { + analogInterface_[id].analogInterfaceY.free(); + } +} diff --git a/src/OSVRTrackedController.h b/src/OSVRTrackedController.h new file mode 100644 index 0000000..70013ee --- /dev/null +++ b/src/OSVRTrackedController.h @@ -0,0 +1,155 @@ +/** @file + @brief OSVR tracked controller + + @date 2015 + + @author + Sensics, Inc. + +*/ + +// Copyright 2015 Sensics, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef INCLUDED_OSVRTrackedController_h_GUID_128E3B29_F5FC_4221_9B38_14E3F402E645 +#define INCLUDED_OSVRTrackedController_h_GUID_128E3B29_F5FC_4221_9B38_14E3F402E645 + + +#define NUM_BUTTONS 64 +#define NUM_TOUCHPAD 1 // only SteamVR Axis 0 for the moment (not implemented yet) +#define NUM_TRIGGER 1 // only SteamVR Axis 1 for the moment +#define NUM_JOYSTICKS 3 // only SteamVR Axis 2,3,4 for the moment (there is always x and y in one joystick) +#define NUM_AXIS 5 + +// Internal Includes +#include "OSVRTrackedDevice.h" +#include "osvr_compiler_detection.h" // for OSVR_OVERRIDE + +// OpenVR includes +#include + +// Library/third-party includes +#include +#include + +// Standard includes +#include + +class OSVRTrackedController; + +struct ButtonInterface { + osvr::clientkit::Interface buttonInterface; + OSVRTrackedController* parentController; + vr::EVRButtonId button_id; +}; + +struct AnalogInterface { + osvr::clientkit::Interface analogInterfaceX; + osvr::clientkit::Interface analogInterfaceY; + + OSVRTrackedController* parentController; + + vr::EVRControllerAxisType axisType; + double x; + double y; + uint32_t axisIndex; +}; + +struct BatteryInterface { + osvr::clientkit::Interface interface; + OSVRTrackedController* parentController; +}; + +class OSVRTrackedController : public OSVRTrackedDevice, public vr::IVRControllerComponent { + friend class ServerDriver_OSVR; + +public: + OSVRTrackedController(osvr::clientkit::ClientContext& context, int controller_index); + //OSVRTrackedController(osvr::clientkit::ClientContext& context); + + virtual ~OSVRTrackedController(); + + // ------------------------------------ + // Management Methods + // ------------------------------------ + + /** + * This is called before an HMD is returned to the application. It will + * always be called before any display or tracking methods. Memory and + * processor use by the ITrackedDeviceServerDriver object should be kept to + * a minimum until it is activated. The pose listener is guaranteed to be + * valid until Deactivate is called, but should not be used after that + * point. + */ + virtual vr::EVRInitError Activate(uint32_t object_id) OSVR_OVERRIDE; + + /** + * This is called when The VR system is switching from this Hmd being the + * active display to another Hmd being the active display. The driver should + * clean whatever memory and thread use it can when it is deactivated. + */ + virtual void Deactivate() OSVR_OVERRIDE; + + // ------------------------------------ + // Controller Methods + // ------------------------------------ + + /** + * Gets the current state of a controller. + */ + virtual vr::VRControllerState_t GetControllerState() OSVR_OVERRIDE; + + /** + * Returns a uint64 property. If the property is not available this function will return 0. + */ + virtual bool TriggerHapticPulse(uint32_t axis_id, uint16_t pulse_duration_microseconds) OSVR_OVERRIDE; + +protected: + const char* GetId(); + +private: + void configure(); + void configureProperties(); + + void freeInterfaces(); + + /** + * Callback function which is called whenever new data has been received + * from the tracker. + */ + static void controllerTrackerCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_PoseReport* report); + static void controllerButtonCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_ButtonReport* report); + static void controllerButtonTouchCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_ButtonReport* report); + static void controllerTriggerCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_AnalogReport* report); + static void controllerJoystickXCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_AnalogReport* report); + static void controllerJoystickYCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_AnalogReport* report); + static void controllerXAxisCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_AnalogReport* report); + static void controllerYAxisCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_AnalogReport* report); + static void controllerBatteryCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_AnalogReport* report); + + int controllerIndex_; + osvr::clientkit::Interface trackerInterface_; + uint32_t numAxis_; + AnalogInterface analogInterface_[NUM_AXIS]; + ButtonInterface buttonInterface_[NUM_BUTTONS]; + BatteryInterface batteryInterface; + void registerButton(int id, const std::string& path, vr::EVRButtonId button_id); + void registerButtonTouch(int id, const std::string& path, vr::EVRButtonId button_id); + void registerTrigger(int id, const std::string& path); + void registerTrackpad(int id, const std::string& path); + void registerBattery(const std::string& path ); +}; + +#endif // INCLUDED_OSVRTrackedDevice_h_GUID_128E3B29_F5FC_4221_9B38_14E3F402E645 + diff --git a/src/OSVRTrackingReference.cpp b/src/OSVRTrackingReference.cpp index 83c9ecd..57da5f5 100644 --- a/src/OSVRTrackingReference.cpp +++ b/src/OSVRTrackingReference.cpp @@ -211,6 +211,9 @@ void OSVRTrackingReference::configure() fovBottom_ = settings_->getSetting("cameraFOVBottomDegrees", fovBottom_); minTrackingRange_ = settings_->getSetting("minTrackingRangeMeters", minTrackingRange_); maxTrackingRange_ = settings_->getSetting("maxTrackingRangeMeters", maxTrackingRange_); + + //configureProperties(); + setProperties(); } std::string OSVRTrackingReference::getTrackerPath() const diff --git a/src/OSVRTrackingReference.h b/src/OSVRTrackingReference.h index a8bca41..fed81f3 100644 --- a/src/OSVRTrackingReference.h +++ b/src/OSVRTrackingReference.h @@ -97,7 +97,6 @@ friend class ServerDriver_OSVR; vr::ETrackedDeviceClass getDeviceClass() const; private: - std::string GetStringTrackedDeviceProperty(vr::ETrackedDeviceProperty prop, vr::ETrackedPropertyError *error); static void TrackerCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_PoseReport* report); /** diff --git a/src/PrettyPrint.cpp b/src/PrettyPrint.cpp index b8c28ec..08d3f09 100644 --- a/src/PrettyPrint.cpp +++ b/src/PrettyPrint.cpp @@ -213,8 +213,8 @@ std::string to_string(const vr::ETrackedDeviceProperty& value) return "Prop_DisplayMCImageNumChannels_Int32"; case vr::Prop_DisplayMCImageData_Binary: return "Prop_DisplayMCImageData_Binary"; - case vr::Prop_SecondsFromPhotonsToVblank_Float: - return "Prop_SecondsFromPhotonsToVblank_Float"; + //case vr::Prop_SecondsFromPhotonsToVblank_Float: + // return "Prop_SecondsFromPhotonsToVblank_Float"; case vr::Prop_AttachedDeviceId_String: return "Prop_AttachedDeviceId_String"; case vr::Prop_SupportedButtons_Uint64: @@ -271,20 +271,22 @@ std::string to_string(const vr::ETrackedDeviceProperty& value) return "Prop_UserConfigPath_String"; case vr::Prop_InstallPath_String: return "Prop_InstallPath_String"; - case vr::Prop_HasDisplayComponent_Bool: - return "Prop_HasDisplayComponent_Bool"; - case vr::Prop_HasControllerComponent_Bool: - return "Prop_HasControllerComponent_Bool"; - case vr::Prop_HasCameraComponent_Bool: - return "Prop_HasCameraComponent_Bool"; - case vr::Prop_HasDriverDirectModeComponent_Bool: - return "Prop_HasDriverDirectModeComponent_Bool"; - case vr::Prop_HasVirtualDisplayComponent_Bool: - return "Prop_HasVirtualDisplayComponent_Bool"; + //case vr::Prop_HasDisplayComponent_Bool: + // return "Prop_HasDisplayComponent_Bool"; + //case vr::Prop_HasControllerComponent_Bool: + // return "Prop_HasControllerComponent_Bool"; + //case vr::Prop_HasCameraComponent_Bool: + // return "Prop_HasCameraComponent_Bool"; + //case vr::Prop_HasDriverDirectModeComponent_Bool: + // return "Prop_HasDriverDirectModeComponent_Bool"; + //case vr::Prop_HasVirtualDisplayComponent_Bool: + // return "Prop_HasVirtualDisplayComponent_Bool"; case vr::Prop_VendorSpecific_Reserved_Start: return "Prop_VendorSpecific_Reserved_Start"; case vr::Prop_VendorSpecific_Reserved_End: return "Prop_VendorSpecific_Reserved_End"; + //case vr::Prop_UsesDriverDirectMode_Bool: + // return "Prop_UsesDriverDirectMode_Bool"; default: { std::ostringstream oss; diff --git a/src/ServerDriver_OSVR.cpp b/src/ServerDriver_OSVR.cpp index 59c79d9..f6ac2c8 100644 --- a/src/ServerDriver_OSVR.cpp +++ b/src/ServerDriver_OSVR.cpp @@ -27,6 +27,7 @@ #include "OSVRTrackedHMD.h" // for OSVRTrackedHMD #include "OSVRTrackingReference.h" // for OSVRTrackingReference +#include "OSVRTrackedController.h" // for OSVRTrackingReference #include "platform_fixes.h" // strcasecmp #include "make_unique.h" // for std::make_unique #include "Logging.h" // for OSVR_LOG, Logging @@ -86,6 +87,8 @@ vr::EVRInitError ServerDriver_OSVR::Init(vr::IVRDriverContext* driver_context) trackedDevices_.emplace_back(std::make_unique(*(context_.get()))); trackedDevices_.emplace_back(std::make_unique(*(context_.get()))); + trackedDevices_.emplace_back(std::make_unique(*(context_.get()), vr::TrackedControllerRole_LeftHand)); // left hand + trackedDevices_.emplace_back(std::make_unique(*(context_.get()), vr::TrackedControllerRole_RightHand)); // right hand for (auto& tracked_device : trackedDevices_) { vr::VRServerDriverHost()->TrackedDeviceAdded(tracked_device->getId(), tracked_device->getDeviceClass(), tracked_device.get());