RflySimSDK v3.05
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_Xkeys.h
1#pragma once
2
3#include <stddef.h> // for size_t
4
5#include "vrpn_Analog.h" // for vrpn_Analog
6#include "vrpn_BaseClass.h" // for vrpn_BaseClass
7#include "vrpn_Button.h" // for vrpn_Button_Filter
8#include "vrpn_Configure.h" // for VRPN_CALLBACK, VRPN_USE_HID
9#include "vrpn_Connection.h" // for vrpn_CONNECTION_LOW_LATENCY, etc
10#include "vrpn_Dial.h" // for vrpn_Dial
11#include "vrpn_HumanInterface.h" // for vrpn_HidAcceptor (ptr only), etc
12#include "vrpn_Shared.h" // for timeval
13#include "vrpn_Types.h" // for vrpn_uint8, vrpn_uint32
14
15#if defined(VRPN_USE_HID)
16
17// Device drivers for the X-Keys USB line of products from P.I. Engineering
18// Currently supported: X-Keys Desktop, X-Keys Jog & Shuttle Pro.
19// Theoretically working but untested: X-Keys Professional, X-Keys Joystick Pro.
20//
21// Exposes three major VRPN device classes: Button, Analog, Dial (as appropriate).
22// All models expose Buttons for the keys on the device.
23// Button 0 is the programming switch; it is set if the switch is in the "red" position.
24//
25// For the X-Keys Jog & Shuttle (58-button version):
26// Analog channel 0 is the shuttle position (-1 to 1). There are 15 levels.
27// Analog channel 1 is the dial orientation (0 to 255).
28// Dial channel 0 sends deltas on the dial (in single-tick values, XXX should be 1/10th revs).
29//
30// For the X-Keys Jog & Shuttle (12- and 68-button versions):
31// Analog channel 0 is the shuttle position (-1 to 1). There are 15 levels.
32// Analog channel 1 is the dial orientation (total revolutions turned).
33// Dial channel 0 sends deltas on the dial (in 1/10th revolution increments).
34// (Note that moving the dial too fast can miss updates.)
35//
36// For the X-Keys Joystick Pro and 12-button version:
37// Analog channel 0 is the joystick X axis (-1 to 1).
38// Analog channel 1 is the joystick Y axis (-1 to 1).
39// Analog channel 2 is the joystick RZ axis (unbounded, since it can spin freely).
40// The Z axis of the joystick is also exported as a dial (a single tick is 1/255th revolution).
42public:
43 vrpn_Xkeys(vrpn_HidAcceptor *filter, const char *name,
44 vrpn_Connection *c = 0, vrpn_uint16 vendor = 0, vrpn_uint16 product = 0,
45 bool toggle_light = true);
46 virtual ~vrpn_Xkeys();
47
48 virtual void mainloop() = 0;
49
50protected:
51 // Set up message handlers, etc.
52 void init_hid();
53 void on_data_received(size_t bytes, vrpn_uint8 *buffer);
54
55 static int VRPN_CALLBACK on_connect(void *thisPtr, vrpn_HANDLERPARAM p);
56 static int VRPN_CALLBACK on_last_disconnect(void *thisPtr, vrpn_HANDLERPARAM p);
57
58 // Decode the packet of data in a way that is appropriate to the
59 // actual device.
60 virtual void decodePacket(size_t bytes, vrpn_uint8 *buffer) = 0;
61
62 // Set the LEDs on the device in a way that is appropriate for the
63 // particular device.
64 typedef enum { Off, On, Flash } LED_STATE;
65 virtual void setLEDs(LED_STATE red, LED_STATE green) = 0;
66
67 struct timeval _timestamp;
68 vrpn_HidAcceptor *_filter;
69 bool _toggle_light;
70
71 // No actual types to register, derived classes will be buttons, analogs, and/or dials
72 int register_types(void) { return 0; }
73};
74
75// Xkeys devices that have no LEDs. To avoid confusing them, we don't send them
76// any commands.
78public:
79 vrpn_Xkeys_noLEDs(vrpn_HidAcceptor *filter, const char *name,
80 vrpn_Connection *c = 0, vrpn_uint16 vendor = 0, vrpn_uint16 product = 0,
81 bool toggle_light = true)
82 : vrpn_Xkeys(filter, name, c, vendor, product, toggle_light) { };
83
84protected:
85 virtual void setLEDs(LED_STATE, LED_STATE) {};
86};
87
88// Original devices that used one method to turn the LEDs on and off.
90public:
91 vrpn_Xkeys_v1(vrpn_HidAcceptor *filter, const char *name,
92 vrpn_Connection *c = 0, vrpn_uint16 vendor = 0, vrpn_uint16 product = 0,
93 bool toggle_light = true)
94 : vrpn_Xkeys(filter, name, c, vendor, product, toggle_light) {
95 // Indicate we're waiting for a connection by turning on the red LED
96 if (_toggle_light) { setLEDs(On, Off); }
97 };
98
99 ~vrpn_Xkeys_v1() { if (_toggle_light) setLEDs(Off, Off); };
100
101protected:
102 virtual void setLEDs(LED_STATE red, LED_STATE green);
103};
104
105// Next generation devices that used another method to turn the LEDs on and off.
107public:
108 vrpn_Xkeys_v2(vrpn_HidAcceptor *filter, const char *name,
109 vrpn_Connection *c = 0, vrpn_uint16 vendor = 0, vrpn_uint16 product = 0,
110 bool toggle_light = true)
111 : vrpn_Xkeys(filter, name, c, vendor, product, toggle_light) {
112 // Indicate we're waiting for a connection by turning on the red LED
113 if (_toggle_light) { setLEDs(On, Off); }
114 };
115
116 ~vrpn_Xkeys_v2() { if (_toggle_light) setLEDs(Off, Off); };
117
118protected:
119 virtual void setLEDs(LED_STATE red, LED_STATE green);
120};
121
123public:
124 vrpn_Xkeys_Desktop(const char *name, vrpn_Connection *c = 0);
125 virtual ~vrpn_Xkeys_Desktop() {};
126
127 virtual void mainloop();
128
129protected:
130 // Send report iff changed
131 void report_changes (void);
132 // Send report whether or not changed
133 void report (void);
134
135 void decodePacket(size_t bytes, vrpn_uint8 *buffer);
136};
137
139public:
140 vrpn_Xkeys_Pro(const char *name, vrpn_Connection *c = 0);
141 virtual ~vrpn_Xkeys_Pro() {};
142
143 virtual void mainloop();
144
145protected:
146 // Send report iff changed
147 void report_changes (void);
148 // Send report whether or not changed
149 void report (void);
150
151 void decodePacket(size_t bytes, vrpn_uint8 *buffer);
152};
153
154// Original unit with 58 buttons
156public:
157 vrpn_Xkeys_Joystick(const char *name, vrpn_Connection *c = 0);
158 virtual ~vrpn_Xkeys_Joystick() {};
159
160 virtual void mainloop();
161
162protected:
163 // Send report iff changed
164 void report_changes (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
165 // Send report whether or not changed
166 void report (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
167 // NOTE: class_of_service is only applied to vrpn_Analog
168 // values, not vrpn_Button or vrpn_Dial
169
170 void decodePacket(size_t bytes, vrpn_uint8 *buffer);
171
172 // Previous dial value, used to determine delta to send when it changes.
173 bool _gotDial;
174 vrpn_uint8 _lastDial;
175};
176
177// 12-button version of the above unit.
179public:
180 vrpn_Xkeys_Joystick12(const char *name, vrpn_Connection *c = 0);
181 virtual ~vrpn_Xkeys_Joystick12() {};
182
183 virtual void mainloop();
184
185protected:
186 // Send report iff changed
187 void report_changes(vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
188 // Send report whether or not changed
189 void report(vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
190 // NOTE: class_of_service is only applied to vrpn_Analog
191 // values, not vrpn_Button or vrpn_Dial
192
193 void decodePacket(size_t bytes, vrpn_uint8 *buffer);
194
195 // Previous dial value, used to determine delta to send when it changes.
196 bool _gotDial;
197 vrpn_uint8 _lastDial;
198};
199
200// Original unit with 58 buttons.
202public:
203 vrpn_Xkeys_Jog_And_Shuttle(const char *name, vrpn_Connection *c = 0);
204 virtual ~vrpn_Xkeys_Jog_And_Shuttle() {};
205
206 virtual void mainloop();
207
208protected:
209 // Send report iff changed
210 void report_changes (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
211 // Send report whether or not changed
212 void report (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
213 // NOTE: class_of_service is only applied to vrpn_Analog
214 // values, not vrpn_Button or vrpn_Dial
215
216 void decodePacket(size_t bytes, vrpn_uint8 *buffer);
217
218 // Previous dial value, used to determine delta to send when it changes.
219 vrpn_uint8 _lastDial;
220};
221
222// 12-button version of the above unit.
224public:
225 vrpn_Xkeys_Jog_And_Shuttle12(const char *name, vrpn_Connection *c = 0);
227
228 virtual void mainloop();
229
230protected:
231 // Send report iff changed
232 void report_changes(vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
233 // Send report whether or not changed
234 void report(vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
235 // NOTE: class_of_service is only applied to vrpn_Analog
236 // values, not vrpn_Button or vrpn_Dial
237
238 void decodePacket(size_t bytes, vrpn_uint8 *buffer);
239
240 // Previous dial value, used to determine delta to send when it changes.
241 vrpn_uint8 _lastDial;
242};
243
244// 68-button version of the above unit.
246public:
247 vrpn_Xkeys_Jog_And_Shuttle68(const char *name, vrpn_Connection *c = 0);
249
250 virtual void mainloop();
251
252protected:
253 // Send report iff changed
254 void report_changes(vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
255 // Send report whether or not changed
256 void report(vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
257 // NOTE: class_of_service is only applied to vrpn_Analog
258 // values, not vrpn_Button or vrpn_Dial
259
260 void decodePacket(size_t bytes, vrpn_uint8 *buffer);
261
262 // Previous dial value, used to determine delta to send when it changes.
263 vrpn_uint8 _lastDial;
264};
265
267public:
268 vrpn_Xkeys_XK3(const char *name, vrpn_Connection *c = 0);
269 virtual ~vrpn_Xkeys_XK3() {};
270
271 virtual void mainloop();
272
273protected:
274 // Send report iff changed
275 void report_changes (void);
276 // Send report whether or not changed
277 void report (void);
278
279 void decodePacket(size_t bytes, vrpn_uint8 *buffer);
280};
281
282// end of VRPN_USE_HID
283#else
284class VRPN_API vrpn_Xkeys;
285class VRPN_API vrpn_Xkeys_Desktop;
286class VRPN_API vrpn_Xkeys_Pro;
287class VRPN_API vrpn_Xkeys_Joystick;
288class VRPN_API vrpn_Xkeys_Joystick12;
289class VRPN_API vrpn_Xkeys_Jog_And_Shuttle;
290class VRPN_API vrpn_Xkeys_Jog_And_Shuttle12;
291class VRPN_API vrpn_Xkeys_Jog_And_Shuttle68;
292class VRPN_API vrpn_Xkeys_XK3;
293#endif
294
定义 vrpn_Analog.h:28
定义 vrpn_BaseClass.h:310
定义 vrpn_Button.h:66
Generic connection class not specific to the transport mechanism.
定义 vrpn_Connection.h:562
定义 vrpn_Dial.h:21
定义 vrpn_HumanInterface.h:56
定义 vrpn_HumanInterface.h:70
vrpn_uint16 product() const
vrpn_uint16 vendor() const
定义 vrpn_Xkeys.h:122
virtual void mainloop()
定义 vrpn_Xkeys.h:223
定义 vrpn_Xkeys.h:245
定义 vrpn_Xkeys.h:201
定义 vrpn_Xkeys.h:178
virtual void mainloop()
定义 vrpn_Xkeys.h:155
virtual void mainloop()
定义 vrpn_Xkeys.h:138
virtual void mainloop()
定义 vrpn_Xkeys.h:266
virtual void mainloop()
定义 vrpn_Xkeys.h:77
定义 vrpn_Xkeys.h:89
定义 vrpn_Xkeys.h:106
定义 vrpn_Xkeys.h:41
void on_data_received(size_t bytes, vrpn_uint8 *buffer)
Derived class reimplements this callback. It is called whenever a read returns some data.
virtual void mainloop()=0
int register_types(void)
定义 vrpn_Xkeys.h:72
This structure is what is passed to a vrpn_Connection message callback.
定义 vrpn_Connection.h:41