Skip to content

Commit 440eaa6

Browse files
committed
Controllers support
1 parent 2d1ba0e commit 440eaa6

File tree

9 files changed

+547
-2351
lines changed

9 files changed

+547
-2351
lines changed

OpenVR/headers/openvr.h

Lines changed: 35 additions & 501 deletions
Large diffs are not rendered by default.

OpenVR/headers/openvr_api.cs

Lines changed: 49 additions & 583 deletions
Large diffs are not rendered by default.

OpenVR/headers/openvr_api.json

Lines changed: 34 additions & 511 deletions
Large diffs are not rendered by default.

OpenVR/headers/openvr_capi.h

Lines changed: 11 additions & 303 deletions
Large diffs are not rendered by default.

OpenVR/headers/openvr_driver.h

Lines changed: 60 additions & 439 deletions
Large diffs are not rendered by default.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#include "DummyController.h"
2+
3+
DummyController::DummyController()
4+
{
5+
}
6+
7+
DummyController::DummyController(std::string serial, bool side, DriverPose_t initial_pose, VRControllerState_t initial_state) :
8+
serial_(serial),
9+
side_(side),
10+
controller_pose_(initial_pose),
11+
controller_state_(initial_state)
12+
{
13+
}
14+
15+
DummyController::~DummyController()
16+
{
17+
}
18+
19+
void DummyController::updateControllerState(VRControllerState_t new_state)
20+
{
21+
controller_state_ = new_state;
22+
}
23+
24+
void DummyController::updateControllerPose(DriverPose_t new_pose)
25+
{
26+
controller_pose_ = new_pose;
27+
}
28+
29+
uint32_t DummyController::getObjectID()
30+
{
31+
return object_id_;
32+
}
33+
34+
VRControllerState_t DummyController::GetControllerState()
35+
{
36+
return controller_state_;
37+
}
38+
39+
bool DummyController::TriggerHapticPulse(uint32_t unAxisId, uint16_t usPulseDurationMicroseconds)
40+
{
41+
return false;
42+
}
43+
44+
EVRInitError DummyController::Activate(uint32_t unObjectId)
45+
{
46+
object_id_ = unObjectId;
47+
48+
PropertyContainerHandle_t prop_handle = VRProperties()->TrackedDeviceToPropertyContainer(unObjectId);
49+
50+
VRProperties()->SetBoolProperty(prop_handle, vr::Prop_WillDriftInYaw_Bool, false);
51+
VRProperties()->SetBoolProperty(prop_handle, vr::Prop_DeviceIsWireless_Bool, true);
52+
VRProperties()->SetBoolProperty(prop_handle, vr::Prop_HasControllerComponent_Bool, true);
53+
54+
if (side_) {
55+
VRProperties()->SetInt32Property(prop_handle, vr::Prop_ControllerRoleHint_Int32, ETrackedControllerRole::TrackedControllerRole_RightHand);
56+
}else {
57+
VRProperties()->SetInt32Property(prop_handle, vr::Prop_ControllerRoleHint_Int32, ETrackedControllerRole::TrackedControllerRole_LeftHand);
58+
}
59+
60+
VRProperties()->SetInt32Property(prop_handle, vr::Prop_Axis0Type_Int32, vr::k_eControllerAxis_TrackPad);
61+
VRProperties()->SetInt32Property(prop_handle, vr::Prop_Axis1Type_Int32, vr::k_eControllerAxis_Trigger);
62+
63+
VRProperties()->SetStringProperty(prop_handle, Prop_SerialNumber_String, serial_.c_str());
64+
VRProperties()->SetStringProperty(prop_handle, Prop_ModelNumber_String, "Vive Controller MV");
65+
VRProperties()->SetStringProperty(prop_handle, Prop_RenderModelName_String, "vr_controller_vive_1_5");
66+
VRProperties()->SetStringProperty(prop_handle, Prop_ManufacturerName_String, "HTC");
67+
68+
uint64_t available_buttons = vr::ButtonMaskFromId(vr::k_EButton_ApplicationMenu) |
69+
vr::ButtonMaskFromId(vr::k_EButton_SteamVR_Touchpad) |
70+
vr::ButtonMaskFromId(vr::k_EButton_SteamVR_Trigger) |
71+
vr::ButtonMaskFromId(vr::k_EButton_System) |
72+
vr::ButtonMaskFromId(vr::k_EButton_Grip);
73+
74+
vr::VRProperties()->SetUint64Property(prop_handle, Prop_SupportedButtons_Uint64, available_buttons);
75+
76+
return EVRInitError::VRInitError_None;
77+
}
78+
79+
void DummyController::Deactivate()
80+
{
81+
}
82+
83+
void DummyController::EnterStandby()
84+
{
85+
}
86+
87+
void * DummyController::GetComponent(const char * pchComponentNameAndVersion)
88+
{
89+
if (0 == strcmp(IVRControllerComponent_Version, pchComponentNameAndVersion))
90+
{
91+
return (vr::IVRControllerComponent*)this;
92+
}
93+
94+
return NULL;
95+
}
96+
97+
void DummyController::DebugRequest(const char * pchRequest, char * pchResponseBuffer, uint32_t unResponseBufferSize)
98+
{
99+
if (unResponseBufferSize >= 1)
100+
pchResponseBuffer[0] = 0;
101+
}
102+
103+
DriverPose_t DummyController::GetPose()
104+
{
105+
return controller_pose_;
106+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#pragma once
2+
3+
#include <openvr_driver.h>
4+
using namespace vr;
5+
6+
class DummyController : public ITrackedDeviceServerDriver, public IVRControllerComponent
7+
{
8+
public:
9+
DummyController();
10+
11+
DummyController(std::string serial, bool side, DriverPose_t initial_pose, VRControllerState_t initial_state);
12+
13+
virtual ~DummyController();
14+
15+
virtual void updateControllerState(VRControllerState_t new_state);
16+
17+
virtual void updateControllerPose(DriverPose_t new_pose);
18+
19+
virtual uint32_t getObjectID();
20+
21+
/*
22+
Inherited from ITrackedDeviceServerDriver:
23+
*/
24+
25+
EVRInitError Activate(uint32_t unObjectId) override;
26+
27+
void Deactivate() override;
28+
29+
void EnterStandby() override;
30+
31+
void *GetComponent(const char* pchComponentNameAndVersion) override;
32+
33+
void DebugRequest(const char* pchRequest, char* pchResponseBuffer, uint32_t unResponseBufferSize) override;
34+
35+
DriverPose_t GetPose() override;
36+
37+
/*
38+
Inherited from IVRControllerComponent:
39+
*/
40+
41+
VRControllerState_t GetControllerState() override;
42+
43+
bool TriggerHapticPulse(uint32_t unAxisId, uint16_t usPulseDurationMicroseconds) override;
44+
45+
private:
46+
VRControllerState_t controller_state_;
47+
48+
DriverPose_t controller_pose_;
49+
50+
uint32_t object_id_;
51+
52+
std::string serial_;
53+
54+
bool side_;
55+
};

0 commit comments

Comments
 (0)