20#if defined(VRPN_USE_HID)
23static const vrpn_uint16 OCULUS_VENDOR = 0x2833;
24static const vrpn_uint16 DK1_PRODUCT = 0x0001;
25static const vrpn_uint16 DK2_PRODUCT = 0x0021;
50 fprintf(stderr,
"vrpn_Oculus::~vrpn_Oculus(): delete failed\n");
76 vector[0] = s.si = (p.i >> 3) & 0x001fffff;
83 vector[1] = s.si = (p.i >> 6) & 0x001fffff;
90 vector[2] = s.si = (p.i >> 1) & 0x001fffff;
99 size_t num_reports = buffer[1];
100 if (num_reports > 3) { num_reports = 3; }
104 vrpn_uint8 *bufptr = &buffer[2];
108 vrpn_uint16 report_index;
109 report_index = vrpn_unbuffer_from_little_endian<vrpn_uint16, vrpn_uint8>(bufptr);
114 skip = vrpn_unbuffer_from_little_endian<vrpn_uint16, vrpn_uint8>(bufptr);
117 vrpn_uint16 temperature;
118 const double temperature_scale = 0.01;
119 temperature = vrpn_unbuffer_from_little_endian<vrpn_uint16, vrpn_uint8>(bufptr);
120 channel[0] = temperature * temperature_scale;
124 vrpn_uint8 *magnetometer_ptr = &buffer[56];
125 vrpn_int16 magnetometer_raw[3];
126 for (
size_t i = 0; i < 3; i++) {
127 magnetometer_raw[i] = vrpn_unbuffer_from_little_endian
128 <vrpn_int16, vrpn_uint8>(magnetometer_ptr);
132 const double magnetometer_scale = 0.0001;
133 channel[8] = -magnetometer_raw[0] * magnetometer_scale;
134 channel[9] = -magnetometer_raw[1] * magnetometer_scale;
135 channel[10] = -magnetometer_raw[2] * magnetometer_scale;
139 for (
size_t i = 0; i < num_reports; i++) {
140 vrpn_int32 accelerometer_raw[3];
141 vrpn_int32 gyroscope_raw[3];
151 const double accelerometer_scale = 0.0001;
152 const double gyroscope_scale = 0.0001;
153 channel[2] = accelerometer_raw[0] * accelerometer_scale;
154 channel[3] = accelerometer_raw[1] * accelerometer_scale;
155 channel[4] = accelerometer_raw[2] * accelerometer_scale;
157 channel[5] = gyroscope_raw[0] * gyroscope_scale;
158 channel[6] = gyroscope_raw[1] * gyroscope_scale;
159 channel[7] = gyroscope_raw[2] * gyroscope_scale;
202 if ( (bytes != 62) && (bytes != 64) ) {
203 fprintf(stderr,
"vrpn_Oculus::on_data_received(): Unexpected message length %d, ignoring\n",
204 static_cast<int>(bytes));
215 fprintf(stderr,
"vrpn_Oculus::on_data_received(): Unexpected message type %d, ignoring\n",
225 name, c, keepAliveSeconds) {};
231 , vrpn_uint16 commandId)
234 vrpn_uint8 pktBuffer[5];
237 vrpn_uint8 *bufptr = pktBuffer;
238 vrpn_int32 buflen =
sizeof(pktBuffer);
249 double keepAliveSeconds)
251 name, c, keepAliveSeconds)
289 size_t num_reports = buffer[3];
290 if (num_reports > 2) { num_reports = 2; }
293 vrpn_uint8 *bufptr = &buffer[4];
297 vrpn_uint16 report_index, temperature;
298 report_index = vrpn_unbuffer_from_little_endian<vrpn_uint16, vrpn_uint8>(bufptr);
302 const double temperature_scale = 0.01;
303 temperature = vrpn_unbuffer_from_little_endian<vrpn_uint16, vrpn_uint8>(bufptr);
304 channel[0] = temperature * temperature_scale;
308 vrpn_uint32 microseconds;
309 microseconds = vrpn_unbuffer_from_little_endian<vrpn_uint32, vrpn_uint8>(bufptr);
310 channel[11] = microseconds * 1e-6;
315 for (
size_t i = 0; i < num_reports; i++) {
316 vrpn_int32 accelerometer_raw[3];
317 vrpn_int32 gyroscope_raw[3];
327 const double accelerometer_scale = 0.0001;
328 const double gyroscope_scale = 0.0001;
329 channel[2] = accelerometer_raw[0] * accelerometer_scale;
330 channel[3] = accelerometer_raw[1] * accelerometer_scale;
331 channel[4] = accelerometer_raw[2] * accelerometer_scale;
333 channel[5] = gyroscope_raw[0] * gyroscope_scale;
334 channel[6] = gyroscope_raw[1] * gyroscope_scale;
335 channel[7] = gyroscope_raw[2] * gyroscope_scale;
341 vrpn_uint8 *magnetometer_ptr = &buffer[44 + 8 * i];
342 vrpn_int16 magnetometer_raw[3];
343 for (
size_t i = 0; i < 3; i++) {
344 magnetometer_raw[i] = vrpn_unbuffer_from_little_endian
345 <vrpn_int16, vrpn_uint8>(magnetometer_ptr);
349 const double magnetometer_scale = - 0.0001;
350 channel[8] = -magnetometer_raw[0] * magnetometer_scale;
351 channel[9] = -magnetometer_raw[1] * magnetometer_scale;
352 channel[10] = -magnetometer_raw[2] * magnetometer_scale;
363 , vrpn_uint16 commandId)
366 vrpn_uint8 pktBuffer[6];
369 vrpn_uint8 *bufptr = pktBuffer;
370 vrpn_int32 buflen =
sizeof(pktBuffer);
vrpn_float64 last[vrpn_CHANNEL_MAX]
vrpn_float64 channel[vrpn_CHANNEL_MAX]
virtual void report_changes(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
Send a report only if something has changed (for servers) Optionally, tell what time to stamp the val...
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
Generic connection class not specific to the transport mechanism.
void send_feature_report(size_t bytes, const vrpn_uint8 *buffer)
Call this to send a feature report to the device - first byte must be Report ID (or 0x0 for devices w...
vrpn_HidAcceptor * m_acceptor
This is the HidAcceptor we use when reconnecting.
virtual void update()
Polls the device buffers and causes on_data_received callbacks if appropriate You NEED to call this f...
Accepts any device with the given vendor and product IDs.
vrpn_Oculus_DK1(const char *name, vrpn_Connection *c=NULL, double keepAliveSeconds=9.0)
Constructor.
virtual void writeKeepAlive(vrpn_uint16 interval=10000, vrpn_uint16 commandId=0)
bool d_enableLEDs
Whether to trigger the LEDs.
bool parse_message(std::size_t bytes, vrpn_uint8 *buffer)
vrpn_Oculus_DK2(bool enableLEDs, const char *name, vrpn_Connection *c=NULL, double keepAliveSeconds=9.0)
Protected constructor so you can't instantiate this base class.
virtual void writeKeepAlive(vrpn_uint16 interval=10000, vrpn_uint16 commandId=0)
void parse_message_type_11(std::size_t bytes, vrpn_uint8 *buffer)
Parse and send reports for type-11 message.
Oculus Rift head-mounted display base class.
void parse_message_type_1(std::size_t bytes, vrpn_uint8 *buffer)
Parse and send reports for type-1 message.
struct timeval d_lastKeepAlive
vrpn_Oculus(vrpn_uint16 product_id, vrpn_uint8 num_channels, const char *name, vrpn_Connection *c=NULL, double keepAliveSeconds=9.0)
Protected constructor so you can't instantiate this base class.
double d_keepAliveSeconds
How often to send the keepAlive message to the Rift (triggers the LEDs if available)
void on_data_received(std::size_t bytes, vrpn_uint8 *buffer)
Extracts the sensor values from each report and calls the appropriate parser.
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
struct timeval d_timestamp
Timestamp updated during mainloop()
virtual bool parse_message(std::size_t bytes, vrpn_uint8 *buffer)
virtual ~vrpn_Oculus()
Destructor.
virtual void writeKeepAlive(vrpn_uint16 interval=10000, vrpn_uint16 commandId=0)=0
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
void unpackVector(const vrpn_uint8 raw[8], int vector[3])
void unpackVector(const vrpn_uint8 raw[8], int vector[3])
Header for various Oculus devices.
double vrpn_TimevalDurationSeconds(struct timeval endT, struct timeval startT)
Return the number of seconds between startT and endT as a floating-point value.
#define vrpn_gettimeofday
int vrpn_buffer_to_little_endian(ByteT **insertPt, vrpn_int32 *buflen, const T inVal)
Function template to buffer values to a buffer stored in little- endian order. Specify the type to bu...