28 #define OSVR_MULTISERVER_VERBOSE
39 #include "com_osvr_Multiserver_OSVRHackerDevKit_json.h"
40 #include "com_osvr_Multiserver_OneEuroFilter_json.h"
41 #include "com_osvr_Multiserver_RazerHydra_json.h"
42 #include "com_osvr_Multiserver_Sensics_zSight_json.h"
45 #include "hidapi/hidapi.h"
46 #include "vrpn_Connection.h"
47 #include "vrpn_Tracker_RazerHydra.h"
48 #include "vrpn_Tracker_zSight.h"
49 #include "vrpn_Tracker_OSVRHackerDevKit.h"
50 #include "vrpn_Tracker_Filter.h"
51 #include <boost/noncopyable.hpp>
53 #include <json/value.h>
54 #include <json/reader.h>
56 #ifdef OSVR_MULTISERVER_VERBOSE
57 #include <boost/format.hpp>
68 #ifdef OSVR_MULTISERVER_VERBOSE
77 #ifdef OSVR_MULTISERVER_VERBOSE
82 struct hid_device_info *enumData = hid_enumerate(0, 0);
83 for (
struct hid_device_info *dev = enumData; dev !=
nullptr;
86 if (m_isPathHandled(dev->path)) {
90 #ifdef OSVR_MULTISERVER_VERBOSE
92 std::cout <<
"[OSVR Multiserver] HID Enumeration: "
93 << boost::format(
"0x%04x") % dev->vendor_id <<
":"
94 << boost::format(
"0x%04x") % dev->product_id
103 if (dev->vendor_id == 0x1532 && dev->product_id == 0x0300) {
106 auto ctrlDev = dev->next;
107 while (ctrlDev !=
nullptr &&
108 !(ctrlDev->vendor_id == 0x1532 &&
109 ctrlDev->product_id == 0x0300)) {
110 ctrlDev = ctrlDev->next;
114 <<
"com_osvr_Multiserver warning: could only find "
115 "one of two interfaces for the Razer Hydra!"
119 if (dataDev->interface_number == 1 && ctrlDev->interface_number == 0) {
123 std::swap(dataDev, ctrlDev);
127 m_handlePath(dataDev->path);
128 m_handlePath(ctrlDev->path);
131 com_osvr_Multiserver_RazerHydra_json);
132 Json::Value hydraJson;
134 if (!reader.parse(hydraJsonString, hydraJson)) {
135 throw std::logic_error(
"Faulty JSON file for Hydra - "
136 "should not be possible!");
146 name.c_str(), ctrlDev->path, dataDev->path,
148 reg.setDeviceDescriptor(hydraJsonString);
150 std::string localName =
"*" + name;
155 Json::Value filterJson;
158 com_osvr_Multiserver_OneEuroFilter_json),
160 throw std::logic_error(
"Faulty JSON file for One "
161 "Euro Filter - should not "
165 (filterJson[
"semantic"] = Json::objectValue);
166 auto &hydraSem = hydraJson[
"semantic"];
167 for (
auto const &element : {
"left",
"right"}) {
168 filterSem[element] = Json::objectValue;
169 filterSem[element][
"$target"] =
170 hydraSem[element][
"$target"];
172 auto &filterAuto = (filterJson[
"automaticAliases"] =
174 filterAuto[
"$priority"] =
176 auto &hydraAuto = hydraJson[
"automaticAliases"];
177 for (
auto const &element :
178 {
"/me/hands/left",
"/me/hands/right"}) {
179 filterAuto[element] = hydraAuto[element];
186 m_data.getName(
"OneEuroFilter")).c_str(),
188 1.0, 1.2, 1.5, 5.0, 1.2));
190 reg.setDeviceDescriptor(filterJson.toStyledString());
196 if ((dev->vendor_id == 0x1532 && dev->product_id == 0x0b00) ||
197 (dev->vendor_id == 0x03EB && dev->product_id == 0x2421)) {
199 m_handlePath(dev->path);
201 auto name = m_data.getName(
"OSVRHackerDevKit");
204 vrpn_Tracker_OSVRHackerDevKit>(name);
206 com_osvr_Multiserver_OSVRHackerDevKit_json));
210 new vrpn_Tracker_DeadReckoning_Rotation(
212 "OSVRHackerDevKitPrediction")),
216 com_osvr_Multiserver_OSVRHackerDevKit_json));
223 #if defined(_WIN32) && defined(VRPN_USE_DIRECTINPUT) && defined(VRPN_HAVE_ATLBASE)
224 if ((dev->vendor_id == 0x16d0 && dev->product_id == 0x0515)) {
226 m_handlePath(dev->path);
228 auto name = m_data.getName(
"Sensics_zSight");
231 vrpn_Tracker_zSight>(name);
233 com_osvr_Multiserver_Sensics_zSight_json));
238 hid_free_enumeration(enumData);
240 #ifdef OSVR_MULTISERVER_VERBOSE
249 bool m_isPathHandled(
const char *path) {
250 return std::find(begin(m_handledPaths), end(m_handledPaths),
251 std::string(path)) != end(m_handledPaths);
253 void m_handlePath(
const char *path) {
254 m_handledPaths.push_back(std::string(path));
257 std::vector<std::string> m_handledPaths;
268 ctx,
"YEI_3Space_Sensor", &wrappedConstructor<&createYEI>, &data);
vrpn_Connection * getVRPNConnection()
Get the vrpn_Connection object to use in constructing your object.
std::string makeString(const char(&arrayLiteral)[N])
Safely and easily convert a literal array of characters (like from osvr_json_to_c) into a std::string...
Header to bring unique_ptr into the osvr namespace.
C++ wrapper class for the opaque plugin context.
T * constructAndRegisterDevice(std::string const &name)
Constructs and registers your custom device with the server and takes ownership of the object...
OSVR_ReturnCode osvrRegisterDriverInstantiationCallback(OSVR_PluginRegContext ctx, const char *name, OSVR_DriverInstantiationCallback cb, void *userData=NULL)
Register an instantiation callback (constructor) for a driver type. The given constructor may be call...
Header with a convenience function to make a std::string out of a non-null-terminated char array (str...
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
Header including the full PluginKit C++ interface.
#define OSVR_PLUGIN(PLUGIN_NAME)
This macro begins the entry point function of your plugin.
OSVR_ReturnCode operator()(OSVR_PluginRegContext ctx)
T * registerDevice(T *dev)
Registers your custom device with the server and takes ownership of the object.
std::string useDecoratedName(std::string const &name)
Decorates a device name with the plugin name and returns it, as well as records it for registration w...
OSVR_EXTERN_C_BEGIN typedef void * OSVR_PluginRegContext
A context pointer passed in to your plugin's entry point and other locations of control flow transfer...