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
vrpn_Microsoft_Controller_Raw_Xbox_S
Definition: vrpn_Microsoft_Controller_Raw.h:93
vrpn_Microsoft_Controller_Raw::_filter
vrpn_HidAcceptor * _filter
Definition: vrpn_Microsoft_Controller_Raw.h:54
vrpn_Microsoft_Controller_Raw::on_last_disconnect
static int VRPN_CALLBACK on_last_disconnect(void *thisPtr, vrpn_HANDLERPARAM p)
Definition: vrpn_Microsoft_Controller_Raw.C:137
vrpn_Dial::report
virtual void report(void)
Definition: vrpn_Dial.C:82
vrpn_Microsoft_SideWinder::mainloop
virtual void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition: vrpn_Microsoft_Controller_Raw.C:311
vrpn_BaseClass.h
vrpn_Button_Filter::report_changes
virtual void report_changes(void)
Definition: vrpn_Button.C:382
vrpn_Dial.h
vrpn_Types.h
vrpn_HidInterface
Definition: vrpn_HumanInterface.h:68
vrpn_Microsoft_SideWinder::~vrpn_Microsoft_SideWinder
virtual ~vrpn_Microsoft_SideWinder(void)
Definition: vrpn_Microsoft_Controller_Raw.h:80
vrpn_Microsoft_SideWinder_Precision_2::mainloop
virtual void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition: vrpn_Microsoft_Controller_Raw.C:167
vrpn_Analog
Definition: vrpn_Analog.h:28
vrpn_Afterglow_Ax1_For_Xbox_360::~vrpn_Afterglow_Ax1_For_Xbox_360
virtual ~vrpn_Afterglow_Ax1_For_Xbox_360(void)
Definition: vrpn_Microsoft_Controller_Raw.h:135
vrpn_Microsoft_Controller_Raw::vrpn_Microsoft_Controller_Raw
vrpn_Microsoft_Controller_Raw(vrpn_HidAcceptor *filter, const char *name, vrpn_Connection *c=0)
Definition: vrpn_Microsoft_Controller_Raw.C:113
vrpn_Microsoft_Controller_Raw_Xbox_S::_lastDial
vrpn_uint8 _lastDial
Definition: vrpn_Microsoft_Controller_Raw.h:108
vrpn_HidAcceptor
Definition: vrpn_HumanInterface.h:54
vrpn_Microsoft_Controller_Raw_Xbox_360::decodePacket
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
Definition: vrpn_Microsoft_Controller_Raw.C:716
vrpn_Microsoft_SideWinder
Definition: vrpn_Microsoft_Controller_Raw.h:77
vrpn_Microsoft_SideWinder_Precision_2::decodePacket
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
Definition: vrpn_Microsoft_Controller_Raw.C:221
vrpn_Microsoft_Controller_Raw::~vrpn_Microsoft_Controller_Raw
virtual ~vrpn_Microsoft_Controller_Raw(void)
Definition: vrpn_Microsoft_Controller_Raw.C:121
vrpn_Microsoft_Controller_Raw::init_hid
void init_hid(void)
Definition: vrpn_Microsoft_Controller_Raw.C:126
vrpn_Afterglow_Ax1_For_Xbox_360::vrpn_Afterglow_Ax1_For_Xbox_360
vrpn_Afterglow_Ax1_For_Xbox_360(const char *name, vrpn_Connection *c)
Definition: vrpn_Microsoft_Controller_Raw.h:134
vrpn_CONNECTION_LOW_LATENCY
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
Definition: vrpn_Connection.h:122
vrpn_Dial
Definition: vrpn_Dial.h:21
vrpn_HANDLERPARAM
This structure is what is passed to a vrpn_Connection message callback.
Definition: vrpn_Connection.h:44
vrpn_Shared.h
vrpn_Microsoft_Controller_Raw::register_types
int register_types(void)
Register the types of messages this device sends/receives. Return 0 on success, -1 on fail.
Definition: vrpn_Microsoft_Controller_Raw.h:57
vrpn_Button.h
vrpn_Microsoft_Controller_Raw::on_data_received
void on_data_received(size_t bytes, vrpn_uint8 *buffer)
Derived class reimplements this callback.
Definition: vrpn_Microsoft_Controller_Raw.C:132
vrpn_Microsoft_Controller_Raw_Xbox_360::~vrpn_Microsoft_Controller_Raw_Xbox_360
virtual ~vrpn_Microsoft_Controller_Raw_Xbox_360(void)
Definition: vrpn_Microsoft_Controller_Raw.h:115
vrpn_Microsoft_SideWinder_Precision_2::~vrpn_Microsoft_SideWinder_Precision_2
virtual ~vrpn_Microsoft_SideWinder_Precision_2(void)
Definition: vrpn_Microsoft_Controller_Raw.h:64
vrpn_HumanInterface.h
vrpn_Microsoft_Controller_Raw::decodePacket
virtual void decodePacket(size_t bytes, vrpn_uint8 *buffer)=0
vrpn_Microsoft_Controller_Raw::mainloop
virtual void mainloop(void)=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_Microsoft_Controller_Raw_Xbox_S::mainloop
virtual void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition: vrpn_Microsoft_Controller_Raw.C:420
vrpn_Microsoft_SideWinder::decodePacket
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
Definition: vrpn_Microsoft_Controller_Raw.C:365
vrpn_Connection
Generic connection class not specific to the transport mechanism.
Definition: vrpn_Connection.h:510
vrpn_Connection.h
vrpn_Microsoft_Controller_Raw_Xbox_S::vrpn_Microsoft_Controller_Raw_Xbox_S
vrpn_Microsoft_Controller_Raw_Xbox_S(const char *name, vrpn_Connection *c=0)
Definition: vrpn_Microsoft_Controller_Raw.C:402
vrpn_Microsoft_Controller_Raw_Xbox_S::~vrpn_Microsoft_Controller_Raw_Xbox_S
virtual ~vrpn_Microsoft_Controller_Raw_Xbox_S(void)
Definition: vrpn_Microsoft_Controller_Raw.h:96
vrpn_Microsoft_Controller_Raw::on_connect
static int VRPN_CALLBACK on_connect(void *thisPtr, vrpn_HANDLERPARAM p)
Definition: vrpn_Microsoft_Controller_Raw.C:143
vrpn_Microsoft_Controller_Raw::_timestamp
struct timeval _timestamp
Definition: vrpn_Microsoft_Controller_Raw.h:53
vrpn_Microsoft_SideWinder::vrpn_Microsoft_SideWinder
vrpn_Microsoft_SideWinder(const char *name, vrpn_Connection *c=0)
Definition: vrpn_Microsoft_Controller_Raw.C:296
vrpn_Analog.h
VRPN_CALLBACK
#define VRPN_CALLBACK
Definition: vrpn_Configure.h:647
vrpn_Microsoft_Controller_Raw_Xbox_360::_lastDial
vrpn_uint8 _lastDial
Definition: vrpn_Microsoft_Controller_Raw.h:127
vrpn_Microsoft_Controller_Raw
Definition: vrpn_Microsoft_Controller_Raw.h:38
vrpn_Microsoft_Controller_Raw_Xbox_360::mainloop
virtual void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition: vrpn_Microsoft_Controller_Raw.C:665
vrpn_Microsoft_SideWinder_Precision_2
Definition: vrpn_Microsoft_Controller_Raw.h:61
vrpn_Microsoft_Controller_Raw_Xbox_360::vrpn_Microsoft_Controller_Raw_Xbox_360
vrpn_Microsoft_Controller_Raw_Xbox_360(const char *name, vrpn_Connection *c=0, vrpn_uint16 vendorId=MICROSOFT_VENDOR, vrpn_uint16 productId=XBOX_360)
Definition: vrpn_Microsoft_Controller_Raw.C:647
vrpn_Microsoft_Controller_Raw_Xbox_360
Definition: vrpn_Microsoft_Controller_Raw.h:112
vrpn_Configure.h
vrpn_Microsoft_SideWinder_Precision_2::vrpn_Microsoft_SideWinder_Precision_2
vrpn_Microsoft_SideWinder_Precision_2(const char *name, vrpn_Connection *c=0)
Definition: vrpn_Microsoft_Controller_Raw.C:152
vrpn_Afterglow_Ax1_For_Xbox_360
Definition: vrpn_Microsoft_Controller_Raw.h:132
vrpn_Microsoft_Controller_Raw_Xbox_S::decodePacket
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
Definition: vrpn_Microsoft_Controller_Raw.C:471
VRPN_API
#define VRPN_API
Definition: vrpn_Configure.h:646
vrpn_BaseClass
Class from which all user-level (and other) classes that communicate with vrpn_Connections should der...
Definition: vrpn_BaseClass.h:313
vrpn_Button_Filter
All button servers should derive from this class, which provides the ability to turn any of the butto...
Definition: vrpn_Button.h:65