vrpn 07.35
Virtual Reality Peripheral Network
 
Loading...
Searching...
No Matches
vrpn_Xkeys.h
Go to the documentation of this file.
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;
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
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
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);
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);
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.
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);
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.
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);
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;
293#endif
294
vrpn_Analog(const char *name, vrpn_Connection *c=NULL)
Definition vrpn_Analog.C:14
vrpn_BaseClass(const char *name, vrpn_Connection *c=NULL)
Names the device and assigns or opens connection, calls registration methods.
virtual void report_changes(void)
vrpn_Button_Filter(const char *, vrpn_Connection *c=NULL)
Generic connection class not specific to the transport mechanism.
virtual void report(void)
Definition vrpn_Dial.C:82
vrpn_Dial(const char *name, vrpn_Connection *c=NULL)
Definition vrpn_Dial.C:8
vrpn_uint16 product() const
Returns USB product ID of connected device May not contain valid if an already-open device was provid...
vrpn_HidInterface(vrpn_HidAcceptor *acceptor, vrpn_uint16 vendor=0, vrpn_uint16 product=0, hid_device *device=NULL)
Constructor If we already have a HID device from some other source, it can be passed and we'll take o...
vrpn_uint16 vendor() const
Returns USB vendor ID of connected device May not contain valid if an already-open device was provide...
vrpn_Xkeys_Desktop(const char *name, vrpn_Connection *c=0)
Definition vrpn_Xkeys.C:144
virtual ~vrpn_Xkeys_Desktop()
Definition vrpn_Xkeys.h:125
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition vrpn_Xkeys.C:156
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
Definition vrpn_Xkeys.C:179
void report(void)
Definition vrpn_Xkeys.C:167
void report_changes(void)
Definition vrpn_Xkeys.C:173
vrpn_Xkeys_Jog_And_Shuttle12(const char *name, vrpn_Connection *c=0)
Definition vrpn_Xkeys.C:373
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition vrpn_Xkeys.C:391
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
Definition vrpn_Xkeys.C:422
virtual ~vrpn_Xkeys_Jog_And_Shuttle12()
Definition vrpn_Xkeys.h:226
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
Definition vrpn_Xkeys.C:555
virtual ~vrpn_Xkeys_Jog_And_Shuttle68()
Definition vrpn_Xkeys.h:248
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition vrpn_Xkeys.C:522
vrpn_Xkeys_Jog_And_Shuttle68(const char *name, vrpn_Connection *c=0)
Definition vrpn_Xkeys.C:504
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
Definition vrpn_Xkeys.C:257
virtual ~vrpn_Xkeys_Jog_And_Shuttle()
Definition vrpn_Xkeys.h:204
vrpn_Xkeys_Jog_And_Shuttle(const char *name, vrpn_Connection *c=0)
Definition vrpn_Xkeys.C:208
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition vrpn_Xkeys.C:226
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
Definition vrpn_Xkeys.C:859
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition vrpn_Xkeys.C:828
vrpn_Xkeys_Joystick12(const char *name, vrpn_Connection *c=0)
Definition vrpn_Xkeys.C:809
virtual ~vrpn_Xkeys_Joystick12()
Definition vrpn_Xkeys.h:181
vrpn_Xkeys_Joystick(const char *name, vrpn_Connection *c=0)
Definition vrpn_Xkeys.C:647
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition vrpn_Xkeys.C:666
vrpn_uint8 _lastDial
Definition vrpn_Xkeys.h:174
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
Definition vrpn_Xkeys.C:697
virtual ~vrpn_Xkeys_Joystick()
Definition vrpn_Xkeys.h:158
virtual ~vrpn_Xkeys_Pro()
Definition vrpn_Xkeys.h:141
vrpn_Xkeys_Pro(const char *name, vrpn_Connection *c=0)
Definition vrpn_Xkeys.C:935
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition vrpn_Xkeys.C:946
void report(void)
Definition vrpn_Xkeys.C:957
void report_changes(void)
Definition vrpn_Xkeys.C:962
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
Definition vrpn_Xkeys.C:967
virtual ~vrpn_Xkeys_XK3()
Definition vrpn_Xkeys.h:269
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_Xkeys_XK3(const char *name, vrpn_Connection *c=0)
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
void report(void)
void report_changes(void)
vrpn_Xkeys_noLEDs(vrpn_HidAcceptor *filter, const char *name, vrpn_Connection *c=0, vrpn_uint16 vendor=0, vrpn_uint16 product=0, bool toggle_light=true)
Definition vrpn_Xkeys.h:79
virtual void setLEDs(LED_STATE, LED_STATE)
Definition vrpn_Xkeys.h:85
virtual void setLEDs(LED_STATE red, LED_STATE green)
Definition vrpn_Xkeys.C:76
vrpn_Xkeys_v1(vrpn_HidAcceptor *filter, const char *name, vrpn_Connection *c=0, vrpn_uint16 vendor=0, vrpn_uint16 product=0, bool toggle_light=true)
Definition vrpn_Xkeys.h:91
virtual void setLEDs(LED_STATE red, LED_STATE green)
Definition vrpn_Xkeys.C:104
vrpn_Xkeys_v2(vrpn_HidAcceptor *filter, const char *name, vrpn_Connection *c=0, vrpn_uint16 vendor=0, vrpn_uint16 product=0, bool toggle_light=true)
Definition vrpn_Xkeys.h:108
int register_types(void)
Register the types of messages this device sends/receives. Return 0 on success, -1 on fail.
Definition vrpn_Xkeys.h:72
virtual ~vrpn_Xkeys()
Definition vrpn_Xkeys.C:34
struct timeval _timestamp
Definition vrpn_Xkeys.h:67
virtual void setLEDs(LED_STATE red, LED_STATE green)=0
vrpn_HidAcceptor * _filter
Definition vrpn_Xkeys.h:68
virtual void decodePacket(size_t bytes, vrpn_uint8 *buffer)=0
bool _toggle_light
Definition vrpn_Xkeys.h:69
vrpn_Xkeys(vrpn_HidAcceptor *filter, const char *name, vrpn_Connection *c=0, vrpn_uint16 vendor=0, vrpn_uint16 product=0, bool toggle_light=true)
Definition vrpn_Xkeys.C:23
virtual void mainloop()=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
static int VRPN_CALLBACK on_connect(void *thisPtr, vrpn_HANDLERPARAM p)
Definition vrpn_Xkeys.C:65
void init_hid()
Definition vrpn_Xkeys.C:44
void on_data_received(size_t bytes, vrpn_uint8 *buffer)
Derived class reimplements this callback.
Definition vrpn_Xkeys.C:50
static int VRPN_CALLBACK on_last_disconnect(void *thisPtr, vrpn_HANDLERPARAM p)
Definition vrpn_Xkeys.C:55
This structure is what is passed to a vrpn_Connection message callback.
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
#define VRPN_API
#define VRPN_CALLBACK
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY