RflySimSDK v3.05
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_Button.h
1#ifndef VRPN_BUTTON_H
2#define VRPN_BUTTON_H
3#include <stddef.h> // for NULL
4
5#include "vrpn_BaseClass.h" // for vrpn_Callback_List, etc
6#include "vrpn_Configure.h" // for VRPN_API, VRPN_CALLBACK
7#include "vrpn_Shared.h" // for timeval
8#include "vrpn_Types.h" // for vrpn_int32, vrpn_float64, etc
9
10class VRPN_API vrpn_Connection;
12
13const int vrpn_BUTTON_MAX_BUTTONS = 256;
14const int VRPN_BUTTON_BUF_SIZE = 256;
15
16// Base class for buttons. Definition
17// of remote button class for the user is at the end.
18
19const int vrpn_BUTTON_MOMENTARY = 10;
20const int vrpn_BUTTON_TOGGLE_OFF = 20;
21const int vrpn_BUTTON_TOGGLE_ON = 21;
22//const int vrpn_BUTTON_LIGHT_OFF = 30;
23//const int vrpn_BUTTON_LIGHT_ON = 31;
24const int vrpn_ALL_ID = -99;
25
31class VRPN_API vrpn_Button : public vrpn_BaseClass {
32public:
33 vrpn_Button(const char *name, vrpn_Connection *c = NULL);
34 virtual ~vrpn_Button(void);
35
36 // Print the status of the button
37 void print(void);
38
39 virtual void set_momentary(vrpn_int32 which_button);
40 virtual void set_toggle(vrpn_int32 which_button, vrpn_int32 current_state);
41 virtual void set_all_momentary(void);
42 virtual void set_all_toggle(vrpn_int32 default_state);
43
44protected:
45 unsigned char buttons[vrpn_BUTTON_MAX_BUTTONS];
46 unsigned char lastbuttons[vrpn_BUTTON_MAX_BUTTONS];
47 vrpn_int32 minrate[vrpn_BUTTON_MAX_BUTTONS];
48 vrpn_int32 num_buttons;
49 struct timeval timestamp;
50 vrpn_int32 change_message_id; // ID of change button message to connection
51 vrpn_int32 states_message_id; // ID of button-states message to connection
52 vrpn_int32 admin_message_id; // ID of admin button message to connection
53
54 virtual int register_types(void);
55 virtual void report_changes(void);
56 virtual void report_states(void); // Calls Button or Button_Filter encode
57 virtual vrpn_int32 encode_to(char *buf, vrpn_int32 button,
58 vrpn_int32 state);
59 virtual vrpn_int32 encode_states_to(char *buf);
60};
61
66class VRPN_API vrpn_Button_Filter : public vrpn_Button {
67public:
68 vrpn_int32 buttonstate[vrpn_BUTTON_MAX_BUTTONS];
69 virtual void set_momentary(vrpn_int32 which_button);
70 virtual void set_toggle(vrpn_int32 which_button, vrpn_int32 current_state);
71 virtual void set_all_momentary(void);
72 virtual void set_all_toggle(vrpn_int32 default_state);
73 void set_alerts(vrpn_int32);
74
75protected:
76 int send_alerts;
77 vrpn_Button_Filter(const char *, vrpn_Connection *c = NULL);
78 vrpn_int32
79 alert_message_id; // used to send back to alert button box for lights
80 virtual vrpn_int32 encode_states_to(char *buf);
81 virtual void report_changes(void);
82
83 // This method makes sure we send a states message whenever we get a ping
84 // from
85 // a client object or a new connection.
86 static int VRPN_CALLBACK
87 handle_ping_message(void *userdata, vrpn_HANDLERPARAM p);
88};
89
90#ifndef VRPN_CLIENT_ONLY
91
92// Button server that lets you set the values for the buttons directly and
93// then have it update if needed. This class should be used by devices that
94// can have several sets of buttons in them and don't want to derive from the
95// Button class themselves. An example is the InterSense 900 features found in
96// the Fastrak server (which may have several button devices, one for each
97// sensor).
98
99class VRPN_API vrpn_Button_Server : public vrpn_Button_Filter {
100public:
101 vrpn_Button_Server(const char *name, vrpn_Connection *c,
102 int numbuttons = 1);
103
106
109 virtual void mainloop();
110
112 int set_button(int button, int new_value);
113};
114
115// Example button server code. This button device causes its buttons to
116// be pressed and released at the interval specified (default 1/sec). It
117// has the specified number of buttons (default 1).
118// This class is derived from the vrpn_Button_Filter class, so that it
119// can be made to toggle its buttons using messages from the client.
120
122public:
123 vrpn_Button_Example_Server(const char *name, vrpn_Connection *c,
124 int numbuttons = 1, vrpn_float64 rate = 1.0);
125
126 virtual void mainloop();
127
128protected:
129 vrpn_float64 _update_rate; // How often to toggle
130};
131
132// Button device that is connected to a parallel port and uses the
133// status bits to read from the buttons. There can be up to 5 buttons
134// read this way.
136public:
137 // Open a button connected to the local machine, talk to the
138 // outside world through the connection.
139 vrpn_Button_Parallel(const char *name, vrpn_Connection *connection,
140 int portno, unsigned porthex = 0);
142
143protected:
144 int port;
145 int status;
146
147 virtual void read(void) = 0;
148#ifdef _WIN32
149 int openGiveIO(void);
150#endif // _WIN32
151};
152
153// Open a Python (or Hiball Button) that is connected to a parallel port.
154// See www.vrpn.org/UNC_python.html for a description of how to make
155// a connector that uses the parallel port this way. Note that this
156// use of a parallel port can result in damage to the motherboard if
157// voltage spikes (static) are passed through if care is not taken.
158// This interface is intended for use at UNC. No warranty is expressed
159// or implied for use elsewhere (use at your own risk).
161public:
162 vrpn_Button_Python(const char *name, vrpn_Connection *c, int p);
163 vrpn_Button_Python(const char *name, vrpn_Connection *c, int p,
164 unsigned ph);
165
166 virtual void mainloop();
167
168protected:
169 virtual void read(void);
170 bool d_first_fail;
171};
172
173// Button device that is connected to the serial port.
174class VRPN_API vrpn_Button_Serial : public vrpn_Button_Filter {
175public:
176 vrpn_Button_Serial(const char *name, vrpn_Connection *c,
177 const char *port = "/dev/ttyS1/", long baud = 38400);
178 virtual ~vrpn_Button_Serial();
179
180protected:
181 char portname[VRPN_BUTTON_BUF_SIZE];
182 long baudrate;
183 int serial_fd;
184 int status;
185
186 unsigned char
187 buffer[VRPN_BUTTON_BUF_SIZE]; // char read from the button so far
188 vrpn_uint32 bufcount; // number of char in the buffer
189
190 virtual void read() = 0;
191};
192
193// Open a Fakespace Pinch Glove System that is connected to a serial port. There
194// are total of 10 buttons. Buttons 0-4 are fingers for the right hand-thumb
195// first and pinkie last-while buttons 5-9 are for the left hand-thumb first.
196// The report you get back is the finger is touching. So you will not have a
197// state where only one button is ON.
199public:
200 vrpn_Button_PinchGlove(const char *name, vrpn_Connection *c,
201 const char *port = "/dev/ttyS1/", long baud = 38400);
202
203 virtual void mainloop();
204
205protected:
206 bool reported_failure;
207 virtual void read();
208 void
209 report_no_timestamp(); // set the glove to report data without timestamp
210};
211
212#endif // VRPN_CLIENT_ONLY
213
214//----------------------------------------------------------
215//************** Users deal with the following *************
216
217// User routine to handle a change in button state. This is called when
218// the button callback is called (when a message from its counterpart
219// across the connection arrives). The pinch glove has 5 different states of on
220// since it knows which fingers are touching. This pinch glove behavior is
221// non-standard and will be removed in a future version. Button states should
222// be considered like booleans.
223#define VRPN_BUTTON_OFF (0)
224#define VRPN_BUTTON_ON (1)
225
226typedef struct _vrpn_BUTTONCB {
227 struct timeval msg_time; // Time of button press/release
228 vrpn_int32 button; // Which button (numbered from zero)
229 vrpn_int32 state; // button state (0 = off, 1 = on)
231typedef void(VRPN_CALLBACK *vrpn_BUTTONCHANGEHANDLER)(void *userdata,
232 const vrpn_BUTTONCB info);
233
234// This is a new button callback type that was added in VRPN 7.31. It
235// tells the current state of all of the buttons on the device. It is
236// called whenever a button server receives a new connection request. It
237// is intended to deal with the issue of not knowing what state toggled
238// buttons are in when a client connects.
239typedef struct _vrpn_BUTTONSTATECB {
240 struct timeval msg_time; // Timestamp of analog data
241 vrpn_int32 num_buttons; // how many buttons
242 vrpn_int32 states[vrpn_BUTTON_MAX_BUTTONS]; // button state values
244typedef void(VRPN_CALLBACK *vrpn_BUTTONSTATESHANDLER)(
245 void *userdata, const vrpn_BUTTONSTATESCB info);
246
247// Open a button that is on the other end of a connection
248// and handle updates from it. This is the type of button that user code will
249// deal with.
250
251class VRPN_API vrpn_Button_Remote : public vrpn_Button {
252public:
253 // The name of the button device to connect to. Optional second
254 // argument is used when you already have an open connection you
255 // want it to listen on.
256 vrpn_Button_Remote(const char *name, vrpn_Connection *cn = NULL);
257 virtual ~vrpn_Button_Remote(void);
258
259 // This routine calls the mainloop of the connection it's on
260 virtual void mainloop();
261
262 // (un)Register a callback handler to handle a button state change
263 virtual int register_change_handler(void *userdata,
264 vrpn_BUTTONCHANGEHANDLER handler)
265 {
266 return d_callback_list.register_handler(userdata, handler);
267 };
268 virtual int unregister_change_handler(void *userdata,
269 vrpn_BUTTONCHANGEHANDLER handler)
270 {
271 return d_callback_list.unregister_handler(userdata, handler);
272 }
273
274 // (un)Register a callback handler to handle buttons states reports
275 virtual int register_states_handler(void *userdata,
276 vrpn_BUTTONSTATESHANDLER handler)
277 {
278 return d_states_callback_list.register_handler(userdata, handler);
279 };
280 virtual int unregister_states_handler(void *userdata,
281 vrpn_BUTTONSTATESHANDLER handler)
282 {
283 return d_states_callback_list.unregister_handler(userdata, handler);
284 }
285
286protected:
287 vrpn_Callback_List<vrpn_BUTTONCB> d_callback_list;
288 static int VRPN_CALLBACK
289 handle_change_message(void *userdata, vrpn_HANDLERPARAM p);
290
291 vrpn_Callback_List<vrpn_BUTTONSTATESCB> d_states_callback_list;
292 static int VRPN_CALLBACK
293 handle_states_message(void *userdata, vrpn_HANDLERPARAM p);
294};
295
296#endif
定义 vrpn_BaseClass.h:310
定义 vrpn_Button.h:121
定义 vrpn_Button.h:66
定义 vrpn_Button.h:135
定义 vrpn_Button.h:198
virtual void mainloop()
定义 vrpn_Button.h:160
virtual void mainloop()
定义 vrpn_Button.h:251
virtual void mainloop()
定义 vrpn_Button.h:174
定义 vrpn_Button.h:99
int number_of_buttons(void)
Tells how many buttons there are (may be clipped to MAX_BUTTONS)
virtual void mainloop()
int set_button(int button, int new_value)
Allows the server program to set current button states (to 0 or 1)
定义 vrpn_Button.h:31
virtual int register_types(void)
定义 vrpn_BaseClass.h:361
Generic connection class not specific to the transport mechanism.
定义 vrpn_Connection.h:562
定义 vrpn_Button.h:226
定义 vrpn_Button.h:239
This structure is what is passed to a vrpn_Connection message callback.
定义 vrpn_Connection.h:41