-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathHardwareDetection.cpp
123 lines (110 loc) · 5.24 KB
/
HardwareDetection.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "HardwareDetection.h"
#include "ControllerDevice.h"
#include <iostream>
#include <json/reader.h>
#include <json/value.h>
using namespace LeapOsvr;
////////////////////////////////////////////////////////////////////////////////////////////////////////
/*----------------------------------------------------------------------------------------------------*/
HardwareDetection::HardwareDetection() {
//do nothing...
}
HardwareDetection::~HardwareDetection() {
if (mConnection) {
LeapDestroyConnection(mConnection);
}
}
OSVR_ReturnCode HardwareDetection::operator()(OSVR_PluginRegContext pContext) {
return (*this)(pContext, nullptr);
}
/*----------------------------------------------------------------------------------------------------*/
OSVR_ReturnCode HardwareDetection::operator()(OSVR_PluginRegContext pContext, const char *params) {
eLeapRS result;
if(!mConnection) {
result = LeapCreateConnection(nullptr, &mConnection);
if (LEAP_FAILED(result)) {
std::cerr << "com_osvr_LeapMotion - HardwareDetection::operator(): LeapCreateConnection call failed." << std::endl;
return OSVR_RETURN_FAILURE;
}
result = LeapOpenConnection(mConnection);
if (LEAP_FAILED(result)) {
std::cerr << "com_osvr_LeapMotion - HardwareDetection::operator(): LeapOpenConnection call failed." << std::endl;
LeapDestroyConnection(mConnection);
mConnection = nullptr;
return OSVR_RETURN_FAILURE;
}
}
if (!mFound) {
if (params) {
Json::Value root;
Json::Reader reader;
if (!reader.parse(params, root)) {
std::cerr << "Couldn't parse JSON for " << kLeapDriverName << std::endl;
return OSVR_RETURN_FAILURE;
}
if (root.isMember("hmdMode")) {
mConfig.hmdMode = root.get("hmdMode", mConfig.hmdMode).asBool();
}
}
for (int i = 0; i < 5; i++) {
LEAP_CONNECTION_MESSAGE msg;
result = LeapPollConnection(mConnection, 1000, &msg);
if (LEAP_FAILED(result)) {
//std::cout << "com_osvr_LeapMotion - HardwareDetection::operator(): LeapPollConnection call failed." << std::endl;
return OSVR_RETURN_FAILURE;
}
switch (msg.type) {
case eLeapEventType_Connection:
//std::cout << "com_osvr_LeapMotion - HardwareDetection::operator(): got eLeapEventType_Connection event." << std::endl;
// @todo
break;
case eLeapEventType_ConnectionLost:
//std::cout << "com_osvr_LeapMotion - HardwareDetection::operator(): got eLeapEventType_ConnectionLost event." << std::endl;
// @todo
break;
case eLeapEventType_Device:
{
std::cout << "com_osvr_LeapMotion - HardwareDetection::operator(): got eLeapEventType_Device event." << std::endl;
const LEAP_DEVICE_EVENT* deviceEvent = msg.device_event;
if (deviceEvent->status & eLeapDeviceStatus_Streaming) {
mFound = true;
osvr::pluginkit::registerObjectForDeletion(pContext, new ControllerDevice(pContext, mConnection, mConfig));
mConnection = nullptr; // pass ownership to the controller device
}
}
break;
case eLeapEventType_DeviceLost:
//std::cout << "com_osvr_LeapMotion - HardwareDetection::operator(): got eLeapEventType_DeviceLost event." << std::endl;
break;
case eLeapEventType_DeviceFailure:
//std::cout << "com_osvr_LeapMotion - HardwareDetection::operator(): got eLeapEventType_DeviceFailure event." << std::endl;
break;
case eLeapEventType_Tracking:
//std::cout << "com_osvr_LeapMotion - HardwareDetection::operator(): got eLeapEventType_Tracking event." << std::endl;
break;
case eLeapEventType_ImageComplete:
// @todo
break;
case eLeapEventType_ImageRequestError:
// @todo
break;
case eLeapEventType_LogEvent:
//std::cout << "com_osvr_LeapMotion - HardwareDetection::operator(): got eLeapEventType_LogEvent event." << std::endl;
break;
case eLeapEventType_Policy:
//std::cout << "com_osvr_LeapMotion - HardwareDetection::operator(): got eLeapEventType_Policy event." << std::endl;
break;
case eLeapEventType_ConfigChange:
//std::cout << "com_osvr_LeapMotion - HardwareDetection::operator(): got eLeapEventType_ConfigChange event." << std::endl;
break;
case eLeapEventType_ConfigResponse:
//std::cout << "com_osvr_LeapMotion - HardwareDetection::operator(): got eLeapEventType_ConfigResponse event." << std::endl;
break;
default:
std::cout << "com_osvr_LeapMotion - HardwareDetection::operator(): got unknown leap event type." << std::endl;
break;
}
}
}
return OSVR_RETURN_SUCCESS;
}