vrpn  07.33
Virtual Reality Peripheral Network
vrpn_XInputGamepad.h
Go to the documentation of this file.
1 #ifndef VRPN_XINPUTGAMEPAD_H
2 #define VRPN_XINPUTGAMEPAD_H
3 
4 #include "vrpn_Configure.h" // IWYU pragma: keep
5 
6 #if defined(_WIN32) && defined(VRPN_USE_WINDOWS_XINPUT)
7 
8 #include "vrpn_Analog.h"
9 #include "vrpn_Analog_Output.h"
10 #include "vrpn_Button.h"
11 #include "vrpn_Connection.h"
12 
13 // This implements an XInput gamepad (read: Xbox 360 controller), which has
14 // analog outputs and button outputs but also enables the user to set a
15 // rumble magnitude using an Analog_Output (channel 0 controls the left motor,
16 // channel 1 controls the right motor).
17 
18 class VRPN_API vrpn_XInputGamepad: public vrpn_Analog, public vrpn_Button_Filter, public vrpn_Analog_Output {
19 public:
20  vrpn_XInputGamepad(const char *name, vrpn_Connection *c = NULL, unsigned int controllerIndex = 0);
21  ~vrpn_XInputGamepad();
22 
23  virtual void mainloop();
24 
25 protected:
26  // Handle requests to change rumble magnitude
27  static int VRPN_CALLBACK handle_request_message(void *selfPtr, vrpn_HANDLERPARAM data);
28  static int VRPN_CALLBACK handle_request_channels_message(void *selfPtr, vrpn_HANDLERPARAM data);
29  static int VRPN_CALLBACK handle_last_connection_dropped(void *selfPtr, vrpn_HANDLERPARAM data);
30 
31  // send report iff changed
32  void report_changes (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
33  // send report whether or not changed
34  void report (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
35  // NOTE: class_of_service is only applied to vrpn_Analog
36  // values, not vrpn_Button
37 
38  void update_vibration();
39 
40  // These functions may be overridden to disable the default filtering
41  virtual vrpn_float64 normalize_axis(SHORT axis, SHORT deadzone) const;
42  virtual vrpn_float64 normalize_trigger(BYTE trigger) const;
43  virtual vrpn_float64 normalize_dpad(WORD buttons) const;
44 
45 private:
46  unsigned int _controllerIndex;
47  timeval _timestamp;
48 
49  WORD _motorSpeed[2];
50 };
51 
52 #endif // _WIN32 && VRPN_USE_DIRECTINPUT
53 #endif // VRPN_XINPUTGAMEPAD_H
54 
vrpn_Analog_Output.h
vrpn_Analog::report
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
Send a report whether something has changed or not (for servers) Optionally, tell what time to stamp ...
Definition: vrpn_Analog.C:94
vrpn_Analog
Definition: vrpn_Analog.h:28
vrpn_Analog_Output
Definition: vrpn_Analog_Output.h:26
vrpn_CONNECTION_LOW_LATENCY
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
Definition: vrpn_Connection.h:122
vrpn_HANDLERPARAM
This structure is what is passed to a vrpn_Connection message callback.
Definition: vrpn_Connection.h:44
vrpn_Button.h
vrpn_BaseClass::mainloop
virtual void mainloop()=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_Connection
Generic connection class not specific to the transport mechanism.
Definition: vrpn_Connection.h:510
vrpn_Connection.h
vrpn_Analog.h
VRPN_CALLBACK
#define VRPN_CALLBACK
Definition: vrpn_Configure.h:647
vrpn_Configure.h
vrpn_Analog::report_changes
virtual void report_changes(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY, const struct timeval time=vrpn_ANALOG_NOW)
Send a report only if something has changed (for servers) Optionally, tell what time to stamp the val...
Definition: vrpn_Analog.C:71
VRPN_API
#define VRPN_API
Definition: vrpn_Configure.h:646
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