OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
TrackerInterfaceC.cpp
Go to the documentation of this file.
1 
11 // Copyright 2014 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 // Internal Includes
32 #include "HandleNullContext.h"
34 #include "UseSendGuard.h"
35 
36 // Library/third-party includes
37 // - none
38 
39 // Standard includes
40 // - none
41 
45  tracker;
46 };
47 
48 OSVR_ReturnCode
50  OSVR_OUT_PTR OSVR_TrackerDeviceInterface *iface) {
51  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceTrackerConfigure", opts);
52  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceTrackerConfigure", iface);
54  opts->makeInterfaceObject<OSVR_TrackerDeviceInterfaceObject>();
55  *iface = ifaceObj;
56  opts->setTracker(ifaceObj->tracker);
57  return OSVR_RETURN_SUCCESS;
58 }
59 
60 template <typename StateType>
61 static inline OSVR_ReturnCode
62 osvrTrackerSend(const char method[], OSVR_DeviceToken,
63  OSVR_TrackerDeviceInterface iface, StateType const *val,
64  OSVR_ChannelCount sensor, OSVR_TimeValue const *timestamp) {
65  OSVR_PLUGIN_HANDLE_NULL_CONTEXT(method, iface);
66  OSVR_PLUGIN_HANDLE_NULL_CONTEXT(method, timestamp);
67  return useSendGuardVoid(
68  iface, [&]() { iface->tracker->sendReport(*val, sensor, *timestamp); });
69 }
70 
71 template <typename StateType>
72 static inline OSVR_ReturnCode
73 osvrTrackerSendVel(const char method[], OSVR_DeviceToken,
74  OSVR_TrackerDeviceInterface iface, StateType const *val,
75  OSVR_ChannelCount sensor, OSVR_TimeValue const *timestamp) {
76  OSVR_PLUGIN_HANDLE_NULL_CONTEXT(method, iface);
77  OSVR_PLUGIN_HANDLE_NULL_CONTEXT(method, timestamp);
78  return useSendGuardVoid(iface, [&]() {
79  iface->tracker->sendVelReport(*val, sensor, *timestamp);
80  });
81 }
82 
83 template <typename StateType>
84 static inline OSVR_ReturnCode
85 osvrTrackerSendAccel(const char method[], OSVR_DeviceToken,
86  OSVR_TrackerDeviceInterface iface, StateType const *val,
87  OSVR_ChannelCount sensor,
88  OSVR_TimeValue const *timestamp) {
89  OSVR_PLUGIN_HANDLE_NULL_CONTEXT(method, iface);
90  OSVR_PLUGIN_HANDLE_NULL_CONTEXT(method, timestamp);
91 
92  return useSendGuardVoid(iface, [&]() {
93  iface->tracker->sendAccelReport(*val, sensor, *timestamp);
94  });
95 }
96 
97 OSVR_ReturnCode
99  OSVR_IN_PTR OSVR_TrackerDeviceInterface iface,
100  OSVR_IN_PTR OSVR_PoseState const *val,
101  OSVR_IN OSVR_ChannelCount sensor) {
102  OSVR_TimeValue now;
103  osvrTimeValueGetNow(&now);
104 
105  return osvrDeviceTrackerSendPoseTimestamped(dev, iface, val, sensor, &now);
106 }
107 
109  OSVR_IN_PTR OSVR_DeviceToken dev,
110  OSVR_IN_PTR OSVR_TrackerDeviceInterface iface,
111  OSVR_IN_PTR OSVR_PoseState const *val, OSVR_IN OSVR_ChannelCount sensor,
112  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
113  return osvrTrackerSend("osvrDeviceTrackerSendPoseTimestamped", dev, iface,
114  val, sensor, timestamp);
115 }
116 
117 OSVR_ReturnCode
119  OSVR_IN_PTR OSVR_TrackerDeviceInterface iface,
120  OSVR_IN_PTR OSVR_PositionState const *val,
121  OSVR_IN OSVR_ChannelCount sensor) {
122  OSVR_TimeValue now;
123  osvrTimeValueGetNow(&now);
124 
125  return osvrDeviceTrackerSendPositionTimestamped(dev, iface, val, sensor,
126  &now);
127 }
128 
130  OSVR_IN_PTR OSVR_DeviceToken dev,
131  OSVR_IN_PTR OSVR_TrackerDeviceInterface iface,
132  OSVR_IN_PTR OSVR_PositionState const *val, OSVR_IN OSVR_ChannelCount sensor,
133  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
134  return osvrTrackerSend("osvrDeviceTrackerSendPoseTimestamped", dev, iface,
135  val, sensor, timestamp);
136 }
137 
138 OSVR_ReturnCode
140  OSVR_IN_PTR OSVR_TrackerDeviceInterface iface,
141  OSVR_IN_PTR OSVR_OrientationState const *val,
142  OSVR_IN OSVR_ChannelCount sensor) {
143  OSVR_TimeValue now;
144  osvrTimeValueGetNow(&now);
145 
146  return osvrDeviceTrackerSendOrientationTimestamped(dev, iface, val, sensor,
147  &now);
148 }
149 
151  OSVR_IN_PTR OSVR_DeviceToken dev,
152  OSVR_IN_PTR OSVR_TrackerDeviceInterface iface,
153  OSVR_IN_PTR OSVR_OrientationState const *val,
154  OSVR_IN OSVR_ChannelCount sensor,
155  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
156  return osvrTrackerSend("osvrDeviceTrackerSendPoseTimestamped", dev, iface,
157  val, sensor, timestamp);
158 }
159 
161  OSVR_IN_PTR OSVR_DeviceToken dev,
162  OSVR_IN_PTR OSVR_TrackerDeviceInterface iface,
163  OSVR_IN_PTR OSVR_VelocityState const *val, OSVR_IN OSVR_ChannelCount sensor,
164  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
165  return osvrTrackerSendVel("osvrDeviceTrackerSendVelocityTimestamped", dev,
166  iface, val, sensor, timestamp);
167 }
168 
170  OSVR_IN_PTR OSVR_DeviceToken dev,
171  OSVR_IN_PTR OSVR_TrackerDeviceInterface iface,
172  OSVR_IN_PTR OSVR_LinearVelocityState const *val,
173  OSVR_IN OSVR_ChannelCount sensor,
174  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
175  return osvrTrackerSendVel("osvrDeviceTrackerSendLinearVelocityTimestamped",
176  dev, iface, val, sensor, timestamp);
177 }
178 
180  OSVR_IN_PTR OSVR_DeviceToken dev,
181  OSVR_IN_PTR OSVR_TrackerDeviceInterface iface,
182  OSVR_IN_PTR OSVR_AngularVelocityState const *val,
183  OSVR_IN OSVR_ChannelCount sensor,
184  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
185  return osvrTrackerSendVel("osvrDeviceTrackerSendAngularVelocityTimestamped",
186  dev, iface, val, sensor, timestamp);
187 }
188 
190  OSVR_IN_PTR OSVR_DeviceToken dev,
191  OSVR_IN_PTR OSVR_TrackerDeviceInterface iface,
192  OSVR_IN_PTR OSVR_AccelerationState const *val,
193  OSVR_IN OSVR_ChannelCount sensor,
194  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
195  return osvrTrackerSendAccel("osvrDeviceTrackerSendAccelerationTimestamped",
196  dev, iface, val, sensor, timestamp);
197 }
198 
200  OSVR_IN_PTR OSVR_DeviceToken dev,
201  OSVR_IN_PTR OSVR_TrackerDeviceInterface iface,
202  OSVR_IN_PTR OSVR_LinearAccelerationState const *val,
203  OSVR_IN OSVR_ChannelCount sensor,
204  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
205  return osvrTrackerSendAccel(
206  "osvrDeviceTrackerSendLinearAccelerationTimestamped", dev, iface, val,
207  sensor, timestamp);
208 }
209 
211  OSVR_IN_PTR OSVR_DeviceToken dev,
212  OSVR_IN_PTR OSVR_TrackerDeviceInterface iface,
213  OSVR_IN_PTR OSVR_AngularAccelerationState const *val,
214  OSVR_IN OSVR_ChannelCount sensor,
215  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
216  return osvrTrackerSendAccel(
217  "osvrDeviceTrackerSendAngularAccelerationTimestamped", dev, iface, val,
218  sensor, timestamp);
219 }
OSVR_ReturnCode osvrDeviceTrackerSendOrientationTimestamped(OSVR_DeviceToken dev, OSVR_TrackerDeviceInterface iface, OSVR_OrientationState const *val, OSVR_ChannelCount sensor, OSVR_TimeValue const *timestamp)
Report the orientation of a sensor that doesn't report position, using the supplied timestamp...
Struct for combined acceleration state.
typename FilterType::State StateType
Given a filter type, get the state type.
uint32_t OSVR_ChannelCount
The integer type specifying a number of channels/sensors or a channel/sensor index.
Definition: ChannelCountC.h:51
A DeviceToken connects the generic device interaction code in PluginKit's C API with the workings of ...
Definition: DeviceToken.h:56
A structure defining a 3D vector, often a position/translation.
Definition: Vec3C.h:48
void osvrTimeValueGetNow(OSVR_TimeValue *dest)
Gets the current time in the TimeValue. Parallel to gettimeofday.
Definition: TimeValueC.cpp:100
A structure defining a quaternion, often a unit quaternion representing 3D rotation.
Definition: QuaternionC.h:49
OSVR_ReturnCode useSendGuardVoid(InterfaceType &iface, F &&func)
Definition: UseSendGuard.h:59
OSVR_ReturnCode osvrDeviceTrackerSendPose(OSVR_DeviceToken dev, OSVR_TrackerDeviceInterface iface, OSVR_PoseState const *val, OSVR_ChannelCount sensor)
Report the full rigid body pose of a sensor, automatically generating a timestamp.
The quaternion represents the incremental rotation taking place over a period of dt seconds...
Structure used internally to construct the desired type of device.
#define OSVR_PLUGIN_HANDLE_NULL_CONTEXT(FUNC, CONTEXT_NAME)
Internal macro for use in C API function implementations to check the validity of a context parameter...
OSVR_ReturnCode osvrDeviceTrackerSendAngularAccelerationTimestamped(OSVR_DeviceToken dev, OSVR_TrackerDeviceInterface iface, OSVR_AngularAccelerationState const *val, OSVR_ChannelCount sensor, OSVR_TimeValue const *timestamp)
Report the angular acceleration of a sensor that doesn't report linear acceleration, using the supplied timestamp.
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:45
OSVR_ReturnCode osvrDeviceTrackerSendLinearAccelerationTimestamped(OSVR_DeviceToken dev, OSVR_TrackerDeviceInterface iface, OSVR_LinearAccelerationState const *val, OSVR_ChannelCount sensor, OSVR_TimeValue const *timestamp)
Report the linear acceleration of a sensor that doesn't report angular acceleration, using the supplied timestamp.
OSVR_ReturnCode osvrDeviceTrackerSendOrientation(OSVR_DeviceToken dev, OSVR_TrackerDeviceInterface iface, OSVR_OrientationState const *val, OSVR_ChannelCount sensor)
Report the orientation of a sensor that doesn't report position, automatically generating a timestamp...
OSVR_ReturnCode osvrDeviceTrackerSendPosition(OSVR_DeviceToken dev, OSVR_TrackerDeviceInterface iface, OSVR_PositionState const *val, OSVR_ChannelCount sensor)
Report the position of a sensor that doesn't report orientation, automatically generating a timestamp...
OSVR_ReturnCode osvrDeviceTrackerSendPositionTimestamped(OSVR_DeviceToken dev, OSVR_TrackerDeviceInterface iface, OSVR_PositionState const *val, OSVR_ChannelCount sensor, OSVR_TimeValue const *timestamp)
Report the position of a sensor that doesn't report orientation, using the supplied timestamp...
OSVR_ReturnCode osvrDeviceTrackerSendAccelerationTimestamped(OSVR_DeviceToken dev, OSVR_TrackerDeviceInterface iface, OSVR_AccelerationState const *val, OSVR_ChannelCount sensor, OSVR_TimeValue const *timestamp)
Report the linear and angular Acceleration of a sensor, using the supplied timestamp.
A structure defining a 3D (6DOF) rigid body pose: translation and rotation.
Definition: Pose3C.h:54
OSVR_ReturnCode osvrDeviceTrackerSendPoseTimestamped(OSVR_DeviceToken dev, OSVR_TrackerDeviceInterface iface, OSVR_PoseState const *val, OSVR_ChannelCount sensor, OSVR_TimeValue const *timestamp)
Report the full rigid body pose of a sensor, using the supplied timestamp.
OSVR_ReturnCode osvrDeviceTrackerConfigure(OSVR_DeviceInitOptions opts, OSVR_TrackerDeviceInterface *iface)
Specify that your device will implement the Tracker interface.
Struct for combined velocity state.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
OSVR_ReturnCode osvrDeviceTrackerSendAngularVelocityTimestamped(OSVR_DeviceToken dev, OSVR_TrackerDeviceInterface iface, OSVR_AngularVelocityState const *val, OSVR_ChannelCount sensor, OSVR_TimeValue const *timestamp)
Report the angular velocity of a sensor that doesn't report linear velocity, using the supplied times...
Base class for the DeviceInterfaceObjects retrieved by plugins to let them send data on an interface...
OSVR_ReturnCode osvrDeviceTrackerSendLinearVelocityTimestamped(OSVR_DeviceToken dev, OSVR_TrackerDeviceInterface iface, OSVR_LinearVelocityState const *val, OSVR_ChannelCount sensor, OSVR_TimeValue const *timestamp)
Report the linear velocity of a sensor that doesn't report angular velocity, using the supplied times...
OSVR_ReturnCode osvrDeviceTrackerSendVelocityTimestamped(OSVR_DeviceToken dev, OSVR_TrackerDeviceInterface iface, OSVR_VelocityState const *val, OSVR_ChannelCount sensor, OSVR_TimeValue const *timestamp)
Report the linear and angular velocity of a sensor, using the supplied timestamp. ...