Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller integration #125

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open

Conversation

Conzar
Copy link

@Conzar Conzar commented Aug 9, 2017

This PR adds controller integration with the following features:

  • Button Mapping
  • Axis Mapping
  • Touchpad Touch/untouch mapping
  • Trigger Mapping
  • Battery Mapping

Joysticks are not implemented.

Copy link
Contributor

@godbyk godbyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a first pass on this. It looks pretty good! I have a few questions and a couple thoughts on how we might be able to reduce the code a bit without overcomplicating things. Let me know what you think.

@@ -30,3 +30,5 @@
# Build directory
build

nbproject
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These folders should only exist in the build tree and the build tree should be outside of the source tree or contained within a subdirectory (e.g., build) so as not to interfere with the source tree.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are present in my repository. I use netbeans and netbeans automatically creates nbproject. I also create the build directory within the project directory. This is why I added them to .gitignore.

.gitmodules Outdated
@@ -1,6 +1,6 @@
[submodule "openvr"]
path = openvr
url = https://github.com/ValveSoftware/openvr.git
url = https://github.com/ValveSoftware/openvr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .git extension on the URL is what Github gives me. Did that not work for you?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some issues with submodule when I first created my fork. I had to delete it. I added it back with the git submodule add. I will change this back to .git though as I think its probably something on my end that wasn't correct.


for (auto& tracked_device : trackedDevices_) {
OSVR_LOG(debug) << "ServerDriver_OSVR - for loop - before TrackedDeviceAdded\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably remove this log entry.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

vr::VRServerDriverHost()->TrackedDeviceAdded(tracked_device->getId(), tracked_device->getDeviceClass(), tracked_device.get());
OSVR_LOG(debug) << "ServerDriver_OSVR - for loop - after TrackedDeviceAdded\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably remove this log entry.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -86,9 +87,13 @@ vr::EVRInitError ServerDriver_OSVR::Init(vr::IVRDriverContext* driver_context)

trackedDevices_.emplace_back(std::make_unique<OSVRTrackedHMD>(*(context_.get())));
trackedDevices_.emplace_back(std::make_unique<OSVRTrackingReference>(*(context_.get())));
trackedDevices_.emplace_back(std::make_unique<OSVRTrackedController>(*(context_.get()), 0)); // left hand
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing in 0 and 1 for the controller index, could we pass in vr::TrackedControllerRole_LeftHand and vr::TrackedControllerRole_RightHand instead? (They eval to 1 and 2 instead, so other code would have to be tweaked.)

I haven't reviewed the usage of the controller index yet, so this may be a bad idea.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OSVRTrackedDevice(context, vr::TrackedDeviceClass_Controller, "OSVR controller"+std::to_string(controller_index)), controllerIndex_(controller_index)
That is the constructor that uses the index. For OSVRTrackedDevice, its passed a string so the name probably doesn't matter.

There is a conditional statement that uses the value of the controllerIndex_ but certainly, that would be easily to change to RightHand. I will make the change now and check if that works.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and pushed

#define INCLUDED_OSVRTrackedController_h_GUID_128E3B29_F5FC_4221_9B38_14E3F402E645


#define NUM_BUTTONS 64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use vr:: k_EButton_Max instead of NUM_BUTTONS?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hum, when I change it to k_EButton_Max & k_unControllerStateAxisCount, after exiting steamvr, Steam crashes!!! I suspect there might be something up in this code
for (int iter_axis = 0; iter_axis < NUM_AXIS; iter_axis++)
and/or
for (int iter_button = 0; iter_button < NUM_BUTTONS; iter_button++) {
I replaced NUM_AXIS and NUM_BUTTONS with the enum values.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are any of these callbacks similar enough that we could consolidate them? (I haven't read through their implementations yet.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, I left controllerYAxisCallback & controllerXAxisCallback and removed the Joystick callbacks.

//vr::VRProperties()->SetBoolProperty(propertyContainer_, vr::Prop_DeviceIsWireless_Bool, false);
vr::VRProperties()->SetInt32Property(propertyContainer_, vr::Prop_DeviceClass_Int32, static_cast<int32_t>(deviceClass_));
/*
vr::VRProperties()->SetInt32Property(propertyContainer_, vr::Prop_Axis0Type_Int32, static_cast<int32_t>(analogInterface_[0].axisType));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to set the axis types so games can tell which ones are the touchpad, which are the triggers, etc.

Copy link
Author

@Conzar Conzar Aug 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree and its done in the registerTrigger, registerTouchpad, etc functions. See

in registerTrackpad
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<int32_t>(analogInterface_[id].axisType));

* @param path the complete path to the button.
*/
void OSVRTrackedController::registerButton(int id, std::string path, vr::EVRButtonId button_id){
buttonInterface_[id].buttonInterface = context_.getInterface(path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure id is within bounds of array so we don't try to access an element that doesn't exist (and segfault).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added checks and committed.

* @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, std::string path, vr::EVRButtonId button_id){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

registerButton() and registerButtonTouch() look to be the same but for the callback. Could we pass the callback function in as a parameter and just have a single registerButton() method?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, I had a go at it but I am not skilled enough in C++ to do this. Sorry.

@Conzar
Copy link
Author

Conzar commented Nov 19, 2017

I just want to bump this PR to see if there is anything else that I need to do to get it accepted. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants