OSVR-Core
TrackerSensorInfo.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_TrackerSensorInfo_h_GUID_AEDB8ECA_7CAC_4A84_ACAB_CF05A681B260
26 #define INCLUDED_TrackerSensorInfo_h_GUID_AEDB8ECA_7CAC_4A84_ACAB_CF05A681B260
27 
28 // Internal Includes
31 
32 // Library/third-party includes
33 #include <boost/assert.hpp>
34 
35 // Standard includes
36 // - none
37 
38 namespace osvr {
39 namespace common {
42  bool reportsPosition = true;
43  bool reportsOrientation = true;
44  bool reportsLinearVelocity = false;
45  bool reportsAngularVelocity = false;
46  bool reportsLinearAcceleration = false;
47  bool reportsAngularAcceleration = false;
48  };
49 
52  inline TrackerSensorInfo
54  BOOST_ASSERT_MSG(
55  source.isResolved(),
56  "Can't pass an unresolved source to getTrackerSensorInfo!");
57 
58  BOOST_ASSERT_MSG(
59  source.getInterfaceName() == "tracker",
60  "Can't pass a non-tracker source to getTrackerSensorInfo!");
61 
62  auto &devDescriptor =
63  source.getDeviceElement().getDescriptor()["interfaces"]["tracker"];
66  auto getBool = [](Json::Value const &root, const char key[],
67  bool &val) { val = root.get(key, val).asBool(); };
68  auto setupFromJson = [&getBool](TrackerSensorInfo &info,
69  Json::Value const &root) {
70  if (root.isNull()) {
71  return;
72  }
73  getBool(root, "position", info.reportsPosition);
74  getBool(root, "orientation", info.reportsOrientation);
75  getBool(root, "linearVelocity", info.reportsLinearVelocity);
76  getBool(root, "angularVelocity", info.reportsAngularVelocity);
77  getBool(root, "linearAcceleration", info.reportsLinearAcceleration);
78  getBool(root, "angularAcceleration",
79  info.reportsAngularAcceleration);
80  };
82 
84  setupFromJson(ret, devDescriptor);
85 
87  auto sensor = source.getSensorNumber();
88  if (sensor) {
89  setupFromJson(ret, devDescriptor["traits"][*sensor]);
90  }
91 
94  return ret;
95  }
96 } // namespace common
97 } // namespace osvr
98 
99 #endif // INCLUDED_TrackerSensorInfo_h_GUID_AEDB8ECA_7CAC_4A84_ACAB_CF05A681B260
The result of resolving a tree node to a device: either an original source to connect to...
Definition: OriginalSource.h:47
Handles spatial transformations.
Definition: SerializationTraitExample_Complicated.h:40
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
fully-resolved data about a tracker sensor. Defaults per the schema.
Definition: TrackerSensorInfo.h:41
TrackerSensorInfo getTrackerSensorInfo(OriginalSource const &source)
Given a fully-parsed tracker source, determines what messages and subsets thereof it reports...
Definition: TrackerSensorInfo.h:53