vrpn  07.33
Virtual Reality Peripheral Network
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:
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.
29 //
30 // For the X-Keys Joystick Pro:
31 // Analog channel 0 is the joystick X axis (-1 to 1).
32 // Analog channel 1 is the joystick Y axis (-1 to 1).
33 // Analog channel 2 is the joystick RZ axis (-1 to 1).
34 
35 class vrpn_Xkeys: public vrpn_BaseClass, protected vrpn_HidInterface {
36 public:
37  vrpn_Xkeys(vrpn_HidAcceptor *filter, const char *name, vrpn_Connection *c = 0, bool toggle_light = true);
38  virtual ~vrpn_Xkeys();
39 
40  virtual void mainloop() = 0;
41 
42 protected:
43  // Set up message handlers, etc.
44  void init_hid();
45  void on_data_received(size_t bytes, vrpn_uint8 *buffer);
46 
47  static int VRPN_CALLBACK on_connect(void *thisPtr, vrpn_HANDLERPARAM p);
48  static int VRPN_CALLBACK on_last_disconnect(void *thisPtr, vrpn_HANDLERPARAM p);
49 
50  virtual void decodePacket(size_t bytes, vrpn_uint8 *buffer) = 0;
51  struct timeval _timestamp;
54 
55  // No actual types to register, derived classes will be buttons, analogs, and/or dials
56  int register_types(void) { return 0; }
57 };
58 
60 public:
61  vrpn_Xkeys_Desktop(const char *name, vrpn_Connection *c = 0);
62  virtual ~vrpn_Xkeys_Desktop() {};
63 
64  virtual void mainloop();
65 
66 protected:
67  // Send report iff changed
68  void report_changes (void);
69  // Send report whether or not changed
70  void report (void);
71 
72  void decodePacket(size_t bytes, vrpn_uint8 *buffer);
73 };
74 
75 class vrpn_Xkeys_Pro: protected vrpn_Xkeys, public vrpn_Button_Filter {
76 public:
77  vrpn_Xkeys_Pro(const char *name, vrpn_Connection *c = 0);
78  virtual ~vrpn_Xkeys_Pro() {};
79 
80  virtual void mainloop();
81 
82 protected:
83  // Send report iff changed
84  void report_changes (void);
85  // Send report whether or not changed
86  void report (void);
87 
88  void decodePacket(size_t bytes, vrpn_uint8 *buffer);
89 };
90 
92 public:
93  vrpn_Xkeys_Joystick(const char *name, vrpn_Connection *c = 0);
94  virtual ~vrpn_Xkeys_Joystick() {};
95 
96  virtual void mainloop();
97 
98 protected:
99  // Send report iff changed
100  void report_changes (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
101  // Send report whether or not changed
102  void report (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
103  // NOTE: class_of_service is only applied to vrpn_Analog
104  // values, not vrpn_Button or vrpn_Dial
105 
106  void decodePacket(size_t bytes, vrpn_uint8 *buffer);
107 };
108 
110 public:
111  vrpn_Xkeys_Jog_And_Shuttle(const char *name, vrpn_Connection *c = 0);
113 
114  virtual void mainloop();
115 
116 protected:
117  // Send report iff changed
118  void report_changes (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
119  // Send report whether or not changed
120  void report (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
121  // NOTE: class_of_service is only applied to vrpn_Analog
122  // values, not vrpn_Button or vrpn_Dial
123 
124  void decodePacket(size_t bytes, vrpn_uint8 *buffer);
125 
126  // Previous dial value, used to determine delta to send when it changes.
127  vrpn_uint8 _lastDial;
128 };
129 
130 class vrpn_Xkeys_XK3: protected vrpn_Xkeys, public vrpn_Button_Filter {
131 public:
132  vrpn_Xkeys_XK3(const char *name, vrpn_Connection *c = 0);
133  virtual ~vrpn_Xkeys_XK3() {};
134 
135  virtual void mainloop();
136 
137 protected:
138  // Send report iff changed
139  void report_changes (void);
140  // Send report whether or not changed
141  void report (void);
142 
143  void decodePacket(size_t bytes, vrpn_uint8 *buffer);
144 };
145 
146 // end of VRPN_USE_HID
147 #else
148 class VRPN_API vrpn_Xkeys;
154 #endif
155 
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
static int VRPN_CALLBACK on_connect(void *thisPtr, vrpn_HANDLERPARAM p)
Definition: vrpn_Xkeys.C:72
virtual void decodePacket(size_t bytes, vrpn_uint8 *buffer)=0
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition: vrpn_Xkeys.C:97
void init_hid()
Definition: vrpn_Xkeys.C:42
void report_changes(void)
Definition: vrpn_Xkeys.C:597
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition: vrpn_Xkeys.C:582
static int VRPN_CALLBACK on_last_disconnect(void *thisPtr, vrpn_HANDLERPARAM p)
Definition: vrpn_Xkeys.C:60
void report(void)
Definition: vrpn_Xkeys.C:107
void report_changes(void)
Definition: vrpn_Xkeys.C:112
vrpn_Xkeys_XK3(const char *name, vrpn_Connection *c=0)
Definition: vrpn_Xkeys.C:570
vrpn_Xkeys_Pro(const char *name, vrpn_Connection *c=0)
Definition: vrpn_Xkeys.C:450
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
Definition: vrpn_Xkeys.C:353
virtual ~vrpn_Xkeys_Joystick()
Definition: vrpn_Xkeys.h:94
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition: vrpn_Xkeys.C:163
void on_data_received(size_t bytes, vrpn_uint8 *buffer)
Derived class reimplements this callback.
Definition: vrpn_Xkeys.C:55
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
Definition: vrpn_Xkeys.C:117
bool _toggle_light
Definition: vrpn_Xkeys.h:53
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
Definition: vrpn_Xkeys.C:602
int register_types(void)
Register the types of messages this device sends/receives. Return 0 on success, -1 on fail...
Definition: vrpn_Xkeys.h:56
Generic connection class not specific to the transport mechanism.
virtual ~vrpn_Xkeys_Jog_And_Shuttle()
Definition: vrpn_Xkeys.h:112
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition: vrpn_Xkeys.C:461
#define VRPN_CALLBACK
virtual ~vrpn_Xkeys()
Definition: vrpn_Xkeys.C:29
vrpn_Xkeys_Desktop(const char *name, vrpn_Connection *c=0)
Definition: vrpn_Xkeys.C:85
#define VRPN_API
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
Definition: vrpn_Xkeys.C:195
virtual void report_changes(void)
Definition: vrpn_Button.C:382
virtual ~vrpn_Xkeys_XK3()
Definition: vrpn_Xkeys.h:133
vrpn_Xkeys_Jog_And_Shuttle(const char *name, vrpn_Connection *c=0)
Definition: vrpn_Xkeys.C:145
virtual void report(void)
Definition: vrpn_Dial.C:82
virtual ~vrpn_Xkeys_Pro()
Definition: vrpn_Xkeys.h:78
This structure is what is passed to a vrpn_Connection message callback.
vrpn_Xkeys(vrpn_HidAcceptor *filter, const char *name, vrpn_Connection *c=0, bool toggle_light=true)
Definition: vrpn_Xkeys.C:20
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
Definition: vrpn_Xkeys.C:481
void report(void)
Definition: vrpn_Xkeys.C:592
void report_changes(void)
Definition: vrpn_Xkeys.C:476
vrpn_HidAcceptor * _filter
Definition: vrpn_Xkeys.h:52
vrpn_Xkeys_Joystick(const char *name, vrpn_Connection *c=0)
Definition: vrpn_Xkeys.C:311
struct timeval _timestamp
Definition: vrpn_Xkeys.h:51
Class from which all user-level (and other) classes that communicate with vrpn_Connections should der...
All button servers should derive from this class, which provides the ability to turn any of the butto...
Definition: vrpn_Button.h:65
void report(void)
Definition: vrpn_Xkeys.C:471
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition: vrpn_Xkeys.C:326
void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY)
Definition: vrpn_Xkeys.C:337
virtual void mainloop()=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
virtual ~vrpn_Xkeys_Desktop()
Definition: vrpn_Xkeys.h:62