RflySimSDK v3.08
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_Oculus.h
浏览该文件的文档.
1/** @file vrpn_Oculus.h
2 @brief Header for various Oculus devices. Initially, just the DK1 & DK2.
3
4 @date 2015
5 @copyright 2015 ReliaSolve.com
6 @author ReliaSolve.com russ@reliasolve.com
7 @license Standard VRPN license.
8*/
9
10// Based on the OSVR hacker dev kit driver by Kevin Godby.
11// Based on Oliver Kreylos' OculusRiftHIDReports.cpp.
12
13#pragma once
14
15#include "vrpn_HumanInterface.h"
16#include "vrpn_Analog.h"
17
18#if defined(VRPN_USE_HID)
19
20/// @brief Oculus Rift head-mounted display base class
21class VRPN_API vrpn_Oculus : public vrpn_Analog, protected vrpn_HidInterface {
22public:
23 /**
24 * @brief Destructor.
25 */
26 virtual ~vrpn_Oculus();
27
28 virtual void mainloop();
29
30protected:
31 /**
32 * @brief Protected constructor so you can't instantiate this base class.
33 *
34 * @param product_id USB Device ID for this device.
35 * @param num_channels Number of analog channels on the device.
36 * @param name Name of the device.
37 * @param c Optional vrpn_Connection pointer to use as our connection.
38 * @param keepAliveSeconds How often to send keepalive message
39 */
40 vrpn_Oculus(vrpn_uint16 product_id, vrpn_uint8 num_channels,
41 const char *name, vrpn_Connection *c = NULL, double keepAliveSeconds = 9.0);
42
43 vrpn_HidAcceptor *m_filter;
44
45 //-------------------------------------------------------------
46 // Parsers for different report types.
47 // Override to define more parsers
48 virtual bool parse_message(std::size_t bytes, vrpn_uint8 *buffer);
49
50 /// Parse and send reports for type-1 message
51 void parse_message_type_1(std::size_t bytes, vrpn_uint8 *buffer);
52
53 /// Extracts the sensor values from each report and calls the
54 /// appropriate parser.
55 void on_data_received(std::size_t bytes, vrpn_uint8 *buffer);
56
57 /// Timestamp updated during mainloop()
58 struct timeval d_timestamp;
59
60 /// How often to send the keepAlive message to the Rift (triggers
61 /// the LEDs if available)
63 struct timeval d_lastKeepAlive;
64
65 // Send a KeepAlive feature report to the Rift.
66 virtual void writeKeepAlive(
67 vrpn_uint16 interval = 10000 //< KeepAlive time in milliseconds
68 , vrpn_uint16 commandId = 0 //< Should always be zero
69 ) = 0;
70};
71
72/// @brief Oculus Rift DK1 head-mounted display
73class VRPN_API vrpn_Oculus_DK1 : public vrpn_Oculus {
74public:
75 /**
76 * @brief Constructor
77 *
78 * @param name Name of this device.
79 * @param c Optional vrpn_Connection pointer to use as our connection.
80 * @param keepAliveSeconds How often to re-trigger the LED flashing
81 */
82 vrpn_Oculus_DK1(const char *name, vrpn_Connection *c = NULL,
83 double keepAliveSeconds = 9.0);
84
85protected:
86
87 // Send a KeepAlive feature report to the Rift.
88 virtual void writeKeepAlive(
89 vrpn_uint16 interval = 10000 //< KeepAlive time in milliseconds
90 , vrpn_uint16 commandId = 0 //< Should always be zero
91 );
92};
93
94/// @brief Oculus Rift DK2 head-mounted display base class for both intertial-
95/// only and LED-enabled version.
96class VRPN_API vrpn_Oculus_DK2 : public vrpn_Oculus {
97protected:
98 /**
99 * @brief Protected constructor so you can't instantiate this base class.
100 *
101 * @param name Name of this device.
102 * @param c Optional vrpn_Connection pointer to use as our connection.
103 * @param keepAliveSeconds How often to re-trigger the LED flashing
104 */
105 vrpn_Oculus_DK2(bool enableLEDs, const char *name, vrpn_Connection *c = NULL,
106 double keepAliveSeconds = 9.0);
107
108 //-------------------------------------------------------------
109 // Parsers for different report types. The DK2 sends type-1
110 // reports in response to inertial-only keep-alive messages
111 // and type-11 reports in response to LED-enabled keep-alive
112 // messages.
113 //
114 bool parse_message(std::size_t bytes, vrpn_uint8 *buffer);
115
116 /// Parse and send reports for type-11 message
117 void parse_message_type_11(std::size_t bytes, vrpn_uint8 *buffer);
118
119 /// Whether to trigger the LEDs
121
122 // Send a KeepAlive feature report to the Rift.
123 virtual void writeKeepAlive(
124 vrpn_uint16 interval = 10000 //< KeepAlive time in milliseconds
125 , vrpn_uint16 commandId = 0 //< Should always be zero
126 );
127};
128
129/// @brief Oculus Rift DK2 head-mounted display (inertial measurement unit only)
131public:
132 /**
133 * @brief Constructor
134 *
135 * @param name Name of this device.
136 * @param c Optional vrpn_Connection pointer to use as our connection.
137 * @param keepAliveSeconds How often to re-trigger the LED flashing
138 */
139 vrpn_Oculus_DK2_inertial(const char *name, vrpn_Connection *c = NULL,
140 double keepAliveSeconds = 9.0)
141 : vrpn_Oculus_DK2(false, name, c, keepAliveSeconds) {};
142};
143
144/// @brief Oculus Rift DK2 head-mounted display (LEDs enabled)
145class VRPN_API vrpn_Oculus_DK2_LEDs : public vrpn_Oculus_DK2 {
146public:
147 /**
148 * @brief Constructor
149 *
150 * @param name Name of this device.
151 * @param c Optional vrpn_Connection pointer to use as our connection.
152 * @param keepAliveSeconds How often to re-trigger the LED flashing
153 */
154 vrpn_Oculus_DK2_LEDs(const char *name, vrpn_Connection *c = NULL,
155 double keepAliveSeconds = 9.0)
156 : vrpn_Oculus_DK2(true, name, c, keepAliveSeconds) {};
157};
158
159#endif // VRPN_USE_HID
定义 vrpn_Analog.h:28
Generic connection class not specific to the transport mechanism.
定义 vrpn_Connection.h:562
定义 vrpn_HumanInterface.h:56
定义 vrpn_HumanInterface.h:70
Oculus Rift DK1 head-mounted display
定义 vrpn_Oculus.h:73
vrpn_Oculus_DK1(const char *name, vrpn_Connection *c=NULL, double keepAliveSeconds=9.0)
Constructor
Oculus Rift DK2 head-mounted display (LEDs enabled)
定义 vrpn_Oculus.h:145
vrpn_Oculus_DK2_LEDs(const char *name, vrpn_Connection *c=NULL, double keepAliveSeconds=9.0)
Constructor
定义 vrpn_Oculus.h:154
Oculus Rift DK2 head-mounted display (inertial measurement unit only)
定义 vrpn_Oculus.h:130
vrpn_Oculus_DK2_inertial(const char *name, vrpn_Connection *c=NULL, double keepAliveSeconds=9.0)
Constructor
定义 vrpn_Oculus.h:139
Oculus Rift DK2 head-mounted display base class for both intertial- only and LED-enabled version.
定义 vrpn_Oculus.h:96
bool d_enableLEDs
Whether to trigger the LEDs
定义 vrpn_Oculus.h:120
void parse_message_type_11(std::size_t bytes, vrpn_uint8 *buffer)
Parse and send reports for type-11 message
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.
Oculus Rift head-mounted display base class
定义 vrpn_Oculus.h:21
virtual ~vrpn_Oculus()
Destructor.
void on_data_received(std::size_t bytes, vrpn_uint8 *buffer)
double d_keepAliveSeconds
定义 vrpn_Oculus.h:62
void parse_message_type_1(std::size_t bytes, vrpn_uint8 *buffer)
Parse and send reports for type-1 message
virtual void mainloop()
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.