OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
EyeTrackerInterfaceC.cpp
Go to the documentation of this file.
1 
12 // Copyright 2015 Sensics, Inc.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "License");
15 // you may not use this file except in compliance with the License.
16 // You may obtain a copy of the License at
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 // See the License for the specific language governing permissions and
24 // limitations under the License.
25 
26 // Internal Includes
32 #include "HandleNullContext.h"
33 #include <osvr/Util/Verbosity.h>
40 
41 // Library/third-party includes
42 // - none
43 
44 // Standard includes
45 // - none
46 
48 
56 };
57 
59  OSVR_INOUT_PTR OSVR_DeviceInitOptions opts,
60  OSVR_OUT_PTR OSVR_EyeTrackerDeviceInterface *iface,
61  OSVR_IN OSVR_ChannelCount numChan) {
62 
63  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceEyeTrackerConfigure", opts);
64  OSVR_PLUGIN_HANDLE_NULL_CONTEXT("osvrDeviceEyeTrackerConfigure", iface);
65  auto ifaceObj =
66  opts->makeInterfaceObject<OSVR_EyeTrackerDeviceInterfaceObject>();
67  *iface = ifaceObj;
68 
70  ifaceObj->location = location.get();
71  opts->addComponent(location);
72 
74  ifaceObj->direction = direction.get();
75  opts->addComponent(direction);
76 
78  ifaceObj->eyetracker = eyetracker.get();
79  opts->addComponent(eyetracker);
80 
81  opts->setButtons(numChan, ifaceObj->button);
82  opts->setTracker(ifaceObj->tracker);
83 
84  return OSVR_RETURN_SUCCESS;
85 }
86 
88  OSVR_IN_PTR OSVR_EyeTrackerDeviceInterface iface,
89  OSVR_IN OSVR_EyeGazePosition2DState gazePosition,
90  OSVR_IN OSVR_ChannelCount sensor,
91  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
92 
93  auto guard = iface->getSendGuard();
94  if (guard->lock()) {
95  iface->location->sendLocationData(gazePosition, sensor, *timestamp);
96  iface->eyetracker->sendNotification(sensor, *timestamp);
97  return OSVR_RETURN_SUCCESS;
98  }
99 
100  return OSVR_RETURN_FAILURE;
101 }
102 
104  OSVR_IN_PTR OSVR_EyeTrackerDeviceInterface iface,
105  OSVR_IN OSVR_EyeGazeDirectionState gazeDirection,
106  OSVR_IN OSVR_EyeGazeBasePoint3DState gazeBasePoint,
107  OSVR_IN OSVR_ChannelCount sensor,
108  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
109  auto guard = iface->getSendGuard();
110  if (guard->lock()) {
111  iface->direction->sendDirectionData(gazeDirection, sensor, *timestamp);
112  iface->tracker->sendReport(gazeBasePoint, sensor, *timestamp);
113  iface->eyetracker->sendNotification(sensor, *timestamp);
114  return OSVR_RETURN_SUCCESS;
115  }
116 
117  return OSVR_RETURN_FAILURE;
118 }
119 
121  OSVR_IN_PTR OSVR_EyeTrackerDeviceInterface iface,
122  OSVR_IN OSVR_EyeGazeDirectionState gazeDirection,
123  OSVR_IN OSVR_ChannelCount sensor,
124  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
125 
126  auto guard = iface->getSendGuard();
127  if (guard->lock()) {
128  iface->direction->sendDirectionData(gazeDirection, sensor, *timestamp);
129  iface->eyetracker->sendNotification(sensor, *timestamp);
130  return OSVR_RETURN_SUCCESS;
131  }
132 
133  return OSVR_RETURN_FAILURE;
134 }
135 
136 OSVR_ReturnCode
138  OSVR_IN OSVR_EyeGazePosition2DState gazePosition,
139  OSVR_IN OSVR_EyeGazeDirectionState gazeDirection,
141  gazeBasePoint,
142  OSVR_IN OSVR_ChannelCount sensor,
143  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
144 
145  auto guard = iface->getSendGuard();
146  if (guard->lock()) {
147  iface->location->sendLocationData(gazePosition, sensor, *timestamp);
148  iface->tracker->sendReport(gazeBasePoint, sensor, *timestamp);
149  iface->direction->sendDirectionData(gazeDirection, sensor, *timestamp);
150  iface->eyetracker->sendNotification(sensor, *timestamp);
151  return OSVR_RETURN_SUCCESS;
152  }
153 
154  return OSVR_RETURN_FAILURE;
155 }
156 
158  OSVR_IN_PTR OSVR_EyeTrackerDeviceInterface iface,
159  OSVR_IN OSVR_EyeTrackerBlinkState blink, OSVR_IN OSVR_ChannelCount sensor,
160  OSVR_IN_PTR OSVR_TimeValue const *timestamp) {
161 
162  auto guard = iface->getSendGuard();
163  if (guard->lock()) {
164  iface->button->setValue(blink, sensor, *timestamp);
165  iface->eyetracker->sendNotification(sensor, *timestamp);
166  return OSVR_RETURN_SUCCESS;
167  }
168  return OSVR_RETURN_FAILURE;
169 }
uint32_t OSVR_ChannelCount
The integer type specifying a number of channels/sensors or a channel/sensor index.
Definition: ChannelCountC.h:51
A structure defining a 3D vector, often a position/translation.
Definition: Vec3C.h:48
OSVR_ReturnCode osvrDeviceEyeTrackerReportBlink(OSVR_EyeTrackerDeviceInterface iface, OSVR_EyeTrackerBlinkState blink, OSVR_ChannelCount sensor, OSVR_TimeValue const *timestamp)
Report the blink state.
static shared_ptr< DirectionComponent > create(OSVR_ChannelCount numSensor=1)
Factory method.
OSVR_ReturnCode osvrDeviceEyeTrackerReport3DGazeDirection(OSVR_EyeTrackerDeviceInterface iface, OSVR_EyeGazeDirectionState gazeDirection, OSVR_ChannelCount sensor, OSVR_TimeValue const *timestamp)
3D gaze direction for an eye
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...
static shared_ptr< EyeTrackerComponent > create(OSVR_ChannelCount numSensor=2)
Factory method.
#define OSVR_RETURN_FAILURE
The "failure" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:47
A structure defining a 2D vector, which represents position.
Definition: Vec2C.h:48
OSVR_ReturnCode osvrDeviceEyeTrackerConfigure(OSVR_DeviceInitOptions opts, OSVR_EyeTrackerDeviceInterface *iface, OSVR_ChannelCount numChan)
Specify that your device will implement the Eye Tracker interface.
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:45
OSVR_ReturnCode osvrDeviceEyeTrackerReportGaze(OSVR_EyeTrackerDeviceInterface iface, OSVR_EyeGazePosition2DState gazePosition, OSVR_EyeGazeDirectionState gazeDirection, OSVR_EyeGazeBasePoint3DState gazeBasePoint, OSVR_ChannelCount sensor, OSVR_TimeValue const *timestamp)
Report both 2D and 3D gaze for an eye.
OSVR_ReturnCode osvrDeviceEyeTrackerReport3DGaze(OSVR_EyeTrackerDeviceInterface iface, OSVR_EyeGazeDirectionState gazeDirection, OSVR_EyeGazeBasePoint3DState gazeBasePoint, OSVR_ChannelCount sensor, OSVR_TimeValue const *timestamp)
Report 3D gaze ray for an eye.
static shared_ptr< Location2DComponent > create(OSVR_ChannelCount numSensor=1)
Factory method.
Internal, configured header file for verbosity macros.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
OSVR_ButtonState OSVR_EyeTrackerBlinkState
State for a blink event.
Base class for the DeviceInterfaceObjects retrieved by plugins to let them send data on an interface...
A wrapper to easily define structures that exist just to hold a pointer.
OSVR_ReturnCode osvrDeviceEyeTrackerReport2DGaze(OSVR_EyeTrackerDeviceInterface iface, OSVR_EyeGazePosition2DState gazePosition, OSVR_ChannelCount sensor, OSVR_TimeValue const *timestamp)
Report gaze position 2D for a sensor (eye) - each component normalized from 0 to 1, lower-left corner of the screen is (0, 0) with the screen extending along the positive axes.