45 #include <boost/lexical_cast.hpp>
46 #include <boost/any.hpp>
47 #include <boost/variant/get.hpp>
48 #include <boost/lexical_cast.hpp>
49 #include <boost/optional.hpp>
50 #include <json/value.h>
51 #include <json/reader.h>
64 : reportDirection(
false), reportBasePoint(
false),
65 reportLocation2D(
false), reportBlink(
false), dirIface() {}
68 bool reportLocation2D;
77 std::string
const &deviceName,
79 boost::optional<OSVR_ChannelCount> sensor,
80 common::InterfaceList &ifaces)
82 m_internals(ifaces), m_all(!sensor.is_initialized()),
83 m_opts(options), m_sensor(sensor) {
85 m_dev->addComponent(eyetracker);
86 eyetracker->registerEyeHandler(
89 m_handleEyeTracking(data, timestamp);
91 OSVR_DEV_VERBOSE(
"Constructed an Eye Handler for " << deviceName);
95 EyeTrackerRemoteHandler &
96 operator=(EyeTrackerRemoteHandler
const &) =
delete;
102 virtual void update() { m_dev->update(); }
109 report.sensor = data.sensor;
110 report.state.directionValid =
false;
111 report.state.basePointValid =
false;
113 if (m_opts.reportDirection) {
114 report.state.directionValid =
116 timest, report.state.direction);
118 if (m_opts.reportBasePoint) {
119 report.state.basePointValid =
121 timest, report.state.basePoint);
123 if (!(report.state.basePointValid || report.state.directionValid)) {
134 void m_handleEyeTracking2d(common::OSVR_EyeNotification
const &data,
137 if (!m_opts.reportLocation2D) {
141 report.sensor = data.sensor;
142 bool locationValid =
false;
147 reportTime, report.state);
148 if (!locationValid) {
159 void m_handleEyeBlink(common::OSVR_EyeNotification
const &data,
162 if (!m_opts.reportBlink) {
166 report.sensor = data.sensor;
167 bool haveBlink =
false;
171 blinkTimestamp, report.state);
182 void m_handleEyeTracking(common::OSVR_EyeNotification
const &data,
184 if (!m_all && *m_sensor != data.sensor) {
189 m_handleEyeTracking3d(data, timestamp);
190 m_handleEyeTracking2d(data, timestamp);
191 m_handleEyeBlink(data, timestamp);
194 common::BaseDevicePtr m_dev;
195 RemoteHandlerInternals m_internals;
198 boost::optional<OSVR_ChannelCount> m_sensor;
201 EyeTrackerRemoteFactory::EyeTrackerRemoteFactory(
202 VRPNConnectionCollection
const &conns)
209 shared_ptr<RemoteHandler> ret;
213 auto const &myDescriptor = source.getDeviceElement().getDescriptor();
216 if (myDescriptor[
"interfaces"][
"eyetracker"].isMember(
"direction")) {
217 opts.reportDirection =
true;
218 const std::string iface = devicePath +
"/direction";
223 if (myDescriptor[
"interfaces"][
"eyetracker"].isMember(
"tracker")) {
224 opts.reportBasePoint =
true;
225 const std::string iface = devicePath +
"/tracker/";
231 if (myDescriptor[
"interfaces"][
"eyetracker"].isMember(
"location2D")) {
232 opts.reportLocation2D =
true;
233 const std::string iface = devicePath +
"/location2D/";
238 if (myDescriptor[
"interfaces"][
"eyetracker"].isMember(
"button")) {
239 opts.reportBlink =
true;
240 const std::string iface = devicePath +
"/button/";
246 if (source.hasTransform()) {
249 "Ignoring transform found on route for Eye Tracker data!");
252 auto const &devElt = source.getDeviceElement();
255 m_conns.getConnection(devElt), devElt.getFullDeviceName(), opts,
256 source.getSensorNumberAsChannelCount(), ifaces));
The result of resolving a tree node to a device: either an original source to connect to...
shared_ptr< ClientInterface > ClientInterfacePtr
Pointer for holding ClientInterface objects safely.
BaseDevicePtr createClientDevice(std::string const &name, vrpn_ConnectionPtr const &conn)
Factory function for a bare client device with no components/interfaces registered by default...
Header including PathTree.h and all additional headers needed to define related types.
Header to bring unique_ptr into the osvr namespace.
Report type for 2D location report.
osvr::common::ClientInterfacePtr getInterface(const char path[])
Creates an interface object for the given path. The context retains shared ownership.
::OSVR_TimeValue TimeValue
C++-friendly typedef for the OSVR_TimeValue structure.
std::string getDevicePath() const
Gets the full path of the device node.
static shared_ptr< EyeTrackerComponent > create(OSVR_ChannelCount numSensor=2)
Factory method.
Report type for 3D Direction vector.
Report type for a blink event.
EyeTrackerRemoteHandler & operator=(EyeTrackerRemoteHandler const &)=delete
Deleted assignment operator.
Report type for 2D location.
void setStateAndTriggerCallbacks(const OSVR_TimeValue ×tamp, ReportType const &report)
Set state and call callbacks for a report type.
virtual ~EyeTrackerRemoteHandler()
Report type for 3D gaze report.
Internal, configured header file for verbosity macros.
Report type for a position callback on a tracker interface.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Base class for remote device handler classes.
shared_ptr< RemoteHandler > operator()(common::OriginalSource const &source, common::InterfaceList &ifaces, common::ClientContext &ctx)