vrpn  07.33
Virtual Reality Peripheral Network
vrpn_Microsoft_Controller_Raw.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 // USB vendor and product IDs for the models we support
18 static const vrpn_uint16 MICROSOFT_VENDOR = 0x045e;
19 static const vrpn_uint16 SIDEWINDER_PRECISION_2 = 0x0038;
20 static const vrpn_uint16 SIDEWINDER = 0x003c;
21 static const vrpn_uint16 XBOX_S = 0x0289;
22 static const vrpn_uint16 XBOX_360 = 0x028e;
23 //static const vrpn_uint16 XBOX_360_WIRELESS = 0x028f; // does not seem to be an HID-compliant device
24 
25 // and generic controllers that act the same as the above
26 static const vrpn_uint16 AFTERGLOW_VENDOR = 0x0e6f;
27 static const vrpn_uint16 AX1_FOR_XBOX_360 = 0x0213;
28 
29 // Device drivers for the Microsoft Controller Raw USB line of products
30 // Currently supported: Xbox Controller S, Xbox 360 Controller
31 //
32 // Exposes three major VRPN device classes: Button, Analog, Dial (as appropriate).
33 // All models expose Buttons for the keys on the device.
34 // Button 0 is the programming switch; it is set if the switch is in the "red" position.
35 //
36 
38 {
39 public:
40  vrpn_Microsoft_Controller_Raw(vrpn_HidAcceptor *filter, const char *name, vrpn_Connection *c = 0);
41  virtual ~vrpn_Microsoft_Controller_Raw(void);
42 
43  virtual void mainloop(void) = 0;
44 protected:
45  // Set up message handlers, etc.
46  void init_hid(void);
47  void on_data_received(size_t bytes, vrpn_uint8 *buffer);
48 
49  static int VRPN_CALLBACK on_connect(void *thisPtr, vrpn_HANDLERPARAM p);
50  static int VRPN_CALLBACK on_last_disconnect(void *thisPtr, vrpn_HANDLERPARAM p);
51 
52  virtual void decodePacket(size_t bytes, vrpn_uint8 *buffer) = 0;
53  struct timeval _timestamp;
55 
56  // No actual types to register, derived classes will be buttons, analogs, and/or dials
57  int register_types(void) { return (0); }
58 };
59 
61 {
62 public:
65 
66  virtual void mainloop(void);
67 protected:
68  // Send report iff changed
69  void report_changes (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
70  // Send report whether or not changed
71  void report (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
72 
73  void decodePacket(size_t bytes, vrpn_uint8 *buffer);
74 };
75 
77 {
78 public:
79  vrpn_Microsoft_SideWinder(const char *name, vrpn_Connection *c = 0);
80  virtual ~vrpn_Microsoft_SideWinder(void) {};
81 
82  virtual void mainloop(void);
83 protected:
84  // Send report iff changed
85  void report_changes (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
86  // Send report whether or not changed
87  void report (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
88 
89  void decodePacket(size_t bytes, vrpn_uint8 *buffer);
90 };
91 
93 {
94 public:
95  vrpn_Microsoft_Controller_Raw_Xbox_S(const char *name, vrpn_Connection *c = 0);
97 
98  virtual void mainloop(void);
99 protected:
100  // Send report iff changed
101  void report_changes (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
102  // Send report whether or not changed
103  void report (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
104 
105  void decodePacket(size_t bytes, vrpn_uint8 *buffer);
106 
107  // Previous dial value, used to determine delta to send when it changes.
108  vrpn_uint8 _lastDial;
109 };
110 
112 {
113 public:
114  vrpn_Microsoft_Controller_Raw_Xbox_360(const char *name, vrpn_Connection *c = 0, vrpn_uint16 vendorId = MICROSOFT_VENDOR, vrpn_uint16 productId = XBOX_360);
116 
117  virtual void mainloop(void);
118 protected:
119  // Send report iff changed
120  void report_changes (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
121  // Send report whether or not changed
122  void report (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
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 // Generic Xbox 360, same as actual Xbox 360, but other IDs
132 {
133 public:
134  vrpn_Afterglow_Ax1_For_Xbox_360(const char *name, vrpn_Connection *c) : vrpn_Microsoft_Controller_Raw_Xbox_360(name, c, AFTERGLOW_VENDOR, AX1_FOR_XBOX_360) {};
136 };
137 
138 // end of VRPN_USE_HID
139 #else
145 #endif
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
vrpn_Microsoft_Controller_Raw(vrpn_HidAcceptor *filter, const char *name, vrpn_Connection *c=0)
int register_types(void)
Register the types of messages this device sends/receives. Return 0 on success, -1 on fail...
virtual void mainloop(void)=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_Afterglow_Ax1_For_Xbox_360(const char *name, vrpn_Connection *c)
Generic connection class not specific to the transport mechanism.
#define VRPN_CALLBACK
#define VRPN_API
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
This structure is what is passed to a vrpn_Connection message callback.
static int VRPN_CALLBACK on_last_disconnect(void *thisPtr, vrpn_HANDLERPARAM p)
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
static int VRPN_CALLBACK on_connect(void *thisPtr, vrpn_HANDLERPARAM p)
void on_data_received(size_t bytes, vrpn_uint8 *buffer)
Derived class reimplements this callback.
virtual void decodePacket(size_t bytes, vrpn_uint8 *buffer)=0