vrpn 07.35
Virtual Reality Peripheral Network
Loading...
Searching...
No Matches
vrpn_DirectXRumblePad.h
Go to the documentation of this file.
1#ifndef VRPN_RUMBLEPAD_H
2
3#include "vrpn_Configure.h" // IWYU pragma: keep
4
5#if defined(_WIN32) && defined(VRPN_USE_DIRECTINPUT)
6
7#include "vrpn_Analog.h"
9#include "vrpn_Button.h"
10#include "vrpn_Connection.h"
11
12#ifndef DIRECTINPUT_VERSION
13#define DIRECTINPUT_VERSION 0x0800
14#endif
15#include "vrpn_Shared.h"
16#include <dinput.h>
17#include <windows.h>
18
19// This implements a RumblePad, which has analog outputs and button outputs
20// but also enables the user to set a rumble magnitude using an Analog_Output
21// (channel zero controls the rumble magnitude).
22
23class VRPN_API vrpn_DirectXRumblePad: public vrpn_Analog, public vrpn_Button_Filter, public vrpn_Analog_Output {
24public:
25 vrpn_DirectXRumblePad(const char *name, vrpn_Connection *c = NULL,
26 GUID device_guid = GUID_NULL);
27
28 ~vrpn_DirectXRumblePad();
29
30 virtual void mainloop();
31
32protected:
33 // Handle the rumble-magnitude setting (channel 0).
34 static int VRPN_CALLBACK handle_request_message( void *userdata,
36 static int VRPN_CALLBACK handle_request_channels_message( void* userdata,
38 static int VRPN_CALLBACK handle_last_connection_dropped(void *selfPtr, vrpn_HANDLERPARAM data);
39
40 //static void FAIL(vrpn_DirectXRumblePad *obj, const char *msg) { struct timeval now; vrpn_gettimeofday(&now, NULL); obj->send_text_message(msg, now, vrpn_TEXT_ERROR); }
41
42private:
43 time_t last_error;
44
45 // Windows enumeration/window callback functions
46 static BOOL CALLBACK joystick_enum_cb(LPCDIDEVICEINSTANCE lpddi, LPVOID ref);
47 static DWORD CALLBACK thread_proc(LPVOID ref);
48 static LRESULT CALLBACK window_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
49 static BOOL CALLBACK axis_enum_cb(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID ref);
50
51 // Error-handling procedure (spit out a message and die)
52 inline void FAIL(const char *msg) {
53 struct timeval now;
54 vrpn_gettimeofday(&now, NULL);
56 d_connection = NULL;
57 }
58
59 // send report iff changed
60 void report_changes (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
61 // send report whether or not changed
62 void report (vrpn_uint32 class_of_service = vrpn_CONNECTION_LOW_LATENCY);
63 // NOTE: class_of_service is only applied to vrpn_Analog
64 // values, not vrpn_Button
65
66 // Create basic rumble effect and load onto device
67 HRESULT init_force();
68
69 // Data storage
70
71 // Identifies the specific joystick device GUID the user is connected to
72 GUID _target_device;
73
74 // Window and thread handles for inter-thread communication
75 HWND _wnd;
76 HANDLE _thread;
77
78 // Root IDirectInput8 instance
79 LPDIRECTINPUT8 _directInput;
80
81 // Various DirectInput COM objects
82 LPDIRECTINPUTDEVICE8 _gamepad;
83 LPDIRECTINPUTEFFECT _effect;
84 timeval _timestamp;
85 DIPERIODIC _diPeriodic;
86 DIEFFECT _diEffect;
87};
88
89#endif // _WIN32 and VRPN_USE_DIRECTINPUT
90
91#define VRPN_RUMBLEPAD_H
92#endif
93
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
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
int send_text_message(const char *msg, struct timeval timestamp, vrpn_TEXT_SEVERITY type=vrpn_TEXT_NORMAL, vrpn_uint32 level=0)
Sends a NULL-terminated text message from the device d_sender_id.
virtual void mainloop()=0
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
All button servers should derive from this class, which provides the ability to turn any of the butto...
Definition: vrpn_Button.h:66
Generic connection class not specific to the transport mechanism.
This structure is what is passed to a vrpn_Connection message callback.
@ vrpn_TEXT_ERROR
#define VRPN_API
#define VRPN_CALLBACK
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
#define vrpn_gettimeofday
Definition: vrpn_Shared.h:99