vrpn  07.33
Virtual Reality Peripheral Network
vrpn_Tracker_OSVRHackerDevKit.C
Go to the documentation of this file.
1 
12 
14 #include "vrpn_BaseClass.h" // for ::vrpn_TEXT_NORMAL, etc
15 #include "vrpn_FixedPoint.h" // for vrpn::FixedPoint
16 #include <quat.h> // for Q_W, Q_X, etc.
17 
18 #include <cstring> // for memset
19 #include <stdexcept> // for logic_error
20 
22 
23 #if defined(VRPN_USE_HID)
24 
25 // USB vendor and product IDs for the models we support
26 static const vrpn_uint16 vrpn_OSVR_VENDOR = 0x1532;
27 static const vrpn_uint16 vrpn_OSVR_HACKER_DEV_KIT_HMD = 0x0b00;
28 
30 static const vrpn_uint16 vrpn_OSVR_ALT_VENDOR = 0x03EB;
31 static const vrpn_uint16 vrpn_OSVR_ALT_HACKER_DEV_KIT_HMD = 0x2421;
32 
34  vrpn_Connection *c)
35  : vrpn_Tracker(name, c)
37  new vrpn_HidProductAcceptor(vrpn_OSVR_VENDOR,
38  vrpn_OSVR_HACKER_DEV_KIT_HMD),
39  new vrpn_HidProductAcceptor(vrpn_OSVR_ALT_VENDOR,
40  vrpn_OSVR_ALT_HACKER_DEV_KIT_HMD)))
41  , _wasConnected(false)
42 {
43  vrpn_Tracker::num_sensors = 1; // only orientation
44 
45  // Initialize the state
46  std::memset(d_quat, 0, sizeof(d_quat));
47  d_quat[Q_W] = 1.0;
48 
49  // Set the timestamp
51 }
52 
54 {
55  delete _acceptor;
56 }
57 
59  vrpn_uint8 *buffer)
60 {
61  if (bytes != 32) {
63  << "Received a report " << bytes
64  << " in length, but expected it to be 32 bytes. Discarding.";
65  return;
66  }
67 
68  vrpn_uint8 version = vrpn_unbuffer_from_little_endian<vrpn_uint8>(buffer);
70  vrpn_uint8 msg_seq = vrpn_unbuffer_from_little_endian<vrpn_uint8>(buffer);
71 
72  // Signed, 16-bit, fixed-point numbers in Q1.14 format.
73  typedef vrpn::FixedPoint<1, 14> FixedPointValue;
74  d_quat[Q_X] =
75  FixedPointValue(vrpn_unbuffer_from_little_endian<vrpn_int16>(buffer))
76  .get<vrpn_float64>();
77  d_quat[Q_Y] =
78  FixedPointValue(vrpn_unbuffer_from_little_endian<vrpn_int16>(buffer))
79  .get<vrpn_float64>();
80  d_quat[Q_Z] =
81  FixedPointValue(vrpn_unbuffer_from_little_endian<vrpn_int16>(buffer))
82  .get<vrpn_float64>();
83  d_quat[Q_W] =
84  FixedPointValue(vrpn_unbuffer_from_little_endian<vrpn_int16>(buffer))
85  .get<vrpn_float64>();
86 
88  char msgbuf[512];
89  int len = vrpn_Tracker::encode_to(msgbuf);
91  msgbuf, vrpn_CONNECTION_LOW_LATENCY)) {
92  fprintf(
93  stderr,
94  "vrpn_Tracker_OSVRHackerDevKit: cannot write message: tossing\n");
95  }
96 }
97 
99 {
101 
102  update();
103 
104  if (connected() && !_wasConnected) {
105  send_text_message("Successfully connected to OSVR Hacker Dev Kit HMD.",
107  }
109 
110  server_mainloop();
111 }
112 
113 #endif
vrpn_HidInterface::connected
virtual bool connected() const
Returns true iff the last device I/O succeeded.
Definition: vrpn_HumanInterface.C:23
vrpn_Connection::pack_message
virtual int pack_message(vrpn_uint32 len, struct timeval time, vrpn_int32 type, vrpn_int32 sender, const char *buffer, vrpn_uint32 class_of_service)
Pack a message that will be sent the next time mainloop() is called. Turn off the RELIABLE flag if yo...
Definition: vrpn_Connection.C:4632
vrpn_Tracker
Definition: vrpn_Tracker.h:49
vrpn_Tracker_OSVRHackerDevKit.h
header for OSVR Hacker Dev Kit
vrpn_HidBooleanOrAcceptor
Accepts devices meeting at least one of two criteria. NOT SHORT-CIRCUIT. Another demonstration of acc...
Definition: vrpn_HumanInterface.h:258
vrpn_BaseClass.h
vrpn_Tracker::encode_to
virtual int encode_to(char *buf)
Definition: vrpn_Tracker.C:533
vrpn_HidInterface
Definition: vrpn_HumanInterface.h:68
vrpn_Tracker::d_quat
vrpn_float64 d_quat[4]
Definition: vrpn_Tracker.h:95
vrpn_Tracker::timestamp
struct timeval timestamp
Definition: vrpn_Tracker.h:100
vrpn_HidInterface::update
virtual void update()
Polls the device buffers and causes on_data_received callbacks if appropriate You NEED to call this f...
Definition: vrpn_HumanInterface.C:140
vrpn_Tracker_OSVRHackerDevKit::on_data_received
void on_data_received(std::size_t bytes, vrpn_uint8 *buffer)
Extracts the sensor values from each report.
Definition: vrpn_Tracker_OSVRHackerDevKit.C:58
vrpn_SendTextMessageStreamProxy.h
Header allowing use of a output stream-style method of sending text messages from devices....
vrpn_Tracker_OSVRHackerDevKit::_timestamp
struct timeval _timestamp
Timestamp updated during mainloop()
Definition: vrpn_Tracker_OSVRHackerDevKit.h:85
vrpn_FixedPoint.h
Header.
vrpn_CONNECTION_LOW_LATENCY
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
Definition: vrpn_Connection.h:122
vrpn_BaseClassUnique::d_connection
vrpn_Connection * d_connection
Connection that this object talks to.
Definition: vrpn_BaseClass.h:224
vrpn_Tracker_OSVRHackerDevKit::~vrpn_Tracker_OSVRHackerDevKit
virtual ~vrpn_Tracker_OSVRHackerDevKit()
Destructor.
Definition: vrpn_Tracker_OSVRHackerDevKit.C:53
vrpn_Tracker_OSVRHackerDevKit::mainloop
virtual void mainloop()
Standard VRPN mainloop method.
Definition: vrpn_Tracker_OSVRHackerDevKit.C:98
vrpn_Tracker_OSVRHackerDevKit::_wasConnected
bool _wasConnected
Flag indicating whether we were connected last time through the mainloop. Used to send a "normal"-sev...
Definition: vrpn_Tracker_OSVRHackerDevKit.h:90
vrpn_HidProductAcceptor
Accepts any device with the given vendor and product IDs.
Definition: vrpn_HumanInterface.h:150
vrpn_TEXT_WARNING
Definition: vrpn_BaseClass.h:102
vrpn_BaseClassUnique::d_sender_id
vrpn_int32 d_sender_id
Sender ID registered with the connection.
Definition: vrpn_BaseClass.h:228
vrpn_Tracker_OSVRHackerDevKit::vrpn_Tracker_OSVRHackerDevKit
vrpn_Tracker_OSVRHackerDevKit(const char *name, vrpn_Connection *c=NULL)
Constructor.
Definition: vrpn_Tracker_OSVRHackerDevKit.C:33
vrpn_Tracker::position_m_id
vrpn_int32 position_m_id
Definition: vrpn_Tracker.h:80
vrpn::FixedPoint
A fixed-point value class.
Definition: vrpn_FixedPoint.h:80
vrpn_Connection
Generic connection class not specific to the transport mechanism.
Definition: vrpn_Connection.h:510
vrpn_gettimeofday
#define vrpn_gettimeofday
Definition: vrpn_Shared.h:89
vrpn_TEXT_NORMAL
Definition: vrpn_BaseClass.h:101
vrpn_BaseClassUnique::send_text_message
int send_text_message(const char *msg, struct timeval timestamp, vrpn_TEXT_SEVERITY type=vrpn_TEXT_NORMAL, vrpn_uint32 level=0)
Sends a NULL-terminated text message from the device d_sender_id.
Definition: vrpn_BaseClass.C:568
vrpn_Tracker::num_sensors
vrpn_int32 num_sensors
Definition: vrpn_Tracker.h:114
VRPN_SUPPRESS_EMPTY_OBJECT_WARNING
#define VRPN_SUPPRESS_EMPTY_OBJECT_WARNING()
Definition: vrpn_Configure.h:495
vrpn_HidInterface::_acceptor
vrpn_HidAcceptor * _acceptor
This is the HidAcceptor we use when reconnecting.
Definition: vrpn_HumanInterface.h:127
vrpn_BaseClassUnique::server_mainloop
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
Definition: vrpn_BaseClass.C:603