OSVR-Core  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
EyeTracker.cpp
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 // Internal Includes
26 #include <osvr/ClientKit/Context.h>
29 
30 // Library/third-party includes
31 
32 // Standard includes
33 #include <iostream>
34 #include <string>
35 
36 void printEyeTracker2DReport(const OSVR_EyeTracker2DReport *report) {
37 
38  std::cout << "2D Data:" << report->state.data[0] << "; "
39  << report->state.data[1] << std::endl;
40 }
41 
42 void printEyeTracker3DReport(const OSVR_EyeTracker3DReport *report) {
43 
44  std::cout << "3D Data Base Point:" << report->state.basePoint.data[0]
45  << "; " << report->state.basePoint.data[1] << "; "
46  << report->state.basePoint.data[2] << std::endl;
47  std::cout << "3D Data Direction:" << report->state.direction.data[0] << "; "
48  << report->state.direction.data[1] << "; "
49  << report->state.direction.data[2] << std::endl;
50 }
51 
52 void printEyeTrackerBlinkReport(const OSVR_EyeTrackerBlinkReport *report) {
53 
54  if (report->state == OSVR_EYE_BLINK) {
55  std::cout << "Blink occured" << std::endl;
56  } else {
57  std::cout << "No blink" << std::endl;
58  }
59 }
60 
61 void eyeTracker2DCallback(void * /*userdata*/,
62  const OSVR_TimeValue * /*timestamp*/,
63  const OSVR_EyeTracker2DReport *report) {
64  std::cout << "Got 2D Eye Tracker Report: for sensor #" << report->sensor
65  << std::endl;
66  printEyeTracker2DReport(report);
67 }
68 
69 void eyeTracker3DCallback(void * /*userdata*/,
70  const OSVR_TimeValue * /*timestamp*/,
71  const OSVR_EyeTracker3DReport *report) {
72  std::cout << "Got 3D Eye Tracker Report: for sensor #" << report->sensor
73  << std::endl;
74  printEyeTracker3DReport(report);
75 }
76 
77 void eyeTrackerBlinkCallback(void * /*userdata*/,
78  const OSVR_TimeValue * /*timestamp*/,
79  const OSVR_EyeTrackerBlinkReport *report) {
80  std::cout << "Got Eye Tracker Blink Report: for sensor #" << report->sensor
81  << std::endl;
82  printEyeTrackerBlinkReport(report);
83 }
84 
85 int main() {
87  "com.osvr.exampleclients.EyeTrackerCallback");
88 
89  osvr::clientkit::Interface eyetracker = context.getInterface(
90  "/com_osvr_example_EyeTracker/EyeTracker/eyetracker");
91 
92  eyetracker.registerCallback(&eyeTracker2DCallback, NULL);
93  eyetracker.registerCallback(&eyeTracker3DCallback, NULL);
94  eyetracker.registerCallback(&eyeTrackerBlinkCallback, NULL);
95 
96  // Pretend that this is your application's mainloop.
97  while (1) {
98  context.update();
99  }
100 
101  std::cout << "Library shut down, exiting." << std::endl;
102  return 0;
103 }
Interface handle object. Typically acquired from a ClientContext.
Client context object: Create and keep one in your application. Handles lifetime management and provi...
Definition: Context_decl.h:57
Header.
Report type for 2D location report.
double data[3]
Internal array data.
Definition: Vec3C.h:50
Report type for a blink event.
double data[2]
Internal array data.
Definition: Vec2C.h:50
#define OSVR_EYE_BLINK
OSVR_EyeTrackerBlinkState value indicating an eyes blink had occurred.
Report type for 3D gaze report.
Header containing the inline implementation of Interface.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81