vrpn  07.33
Virtual Reality Peripheral Network
vrpn_Event_Mouse.C
Go to the documentation of this file.
1 /**************************************************************************************************/
2 /* */
3 /* Copyright (C) 2004 Bauhaus University Weimar */
4 /* Released into the public domain on 6/23/2007 as part of the VRPN project */
5 /* by Jan P. Springer. */
6 /* */
7 /**************************************************************************************************/
8 /* */
9 /* module : vrpn_Event_Mouse.h */
10 /* project : */
11 /* description: mouse input using the event interface */
12 /* */
13 /***************************************************************************************************/
14 
15 
16 #include "vrpn_Shared.h" // for vrpn_gettimeofday
17 #include <vector> // for vector
18 
19 #include "vrpn_Analog.h" // for vrpn_Analog
20 #include "vrpn_Connection.h" // for vrpn_Connection
21 #include "vrpn_Event.h" // for input_event
22 // includes, file
23 #include "vrpn_Event_Mouse.h"
24 #include "vrpn_Types.h" // for vrpn_float64
25 
26 // includes, system
27 
28 // includes, project
29 
30 #ifndef _WIN32
31 
32  // defines, local
33  #define EV_KEY 0x01
34  #define EV_REL 0x02
35  #define REL_X 0x00
36  #define REL_Y 0x01
37  #define REL_Z 0x02
38  #define BTN_LEFT 0x110
39  #define BTN_RIGHT 0x111
40  #define BTN_MIDDLE 0x112
41  #define REL_WHEEL 0x08
42 
43 #endif
44 
45 
46 /**************************************************************************************************/
47 /* constructor (private) */
48 /**************************************************************************************************/
50  vrpn_Connection *c,
51  const char* evdev_name) :
52  vrpn_Event_Analog( name, c, evdev_name),
53  vrpn_Button_Server(name,c)
54 {
57 
58  vrpn_gettimeofday(&timestamp, 0);
59  vrpn_Analog::timestamp = timestamp;
60  vrpn_Button::timestamp = timestamp;
61 
62  clear_values();
63 }
64 
65 /**************************************************************************************************/
66 /* destructor */
67 /* the work is done in the destructor of the base class */
68 /**************************************************************************************************/
70 
71 }
72 
73 /**************************************************************************************************/
74 /* mainloop */
75 /**************************************************************************************************/
76 void
78 
80 
81  if ( ! d_connection->connected()) {
82 
83  return;
84  }
85 
86  // read and interpret data from the event interface
87  process_mouse_data();
88 
89  // update message buffer
92 
93  // send messages
95 }
96 
97 /**************************************************************************************************/
98 /* helper function for mainloop */
99 /**************************************************************************************************/
100 void
101 vrpn_Event_Mouse::process_mouse_data() {
102 
103  // try to read data
105 
106  return;
107  }
108 
109  #if defined(_WIN32)
110 
111  fprintf( stderr, "vrpn_Event_Mouse::process_mouse_data(): Not yet implemented on this architecture.");
112 
113  #else // if defined(LINUX)
114 
115  int index;
116 
117  // process data stored by the base class
118  for( event_iter_t iter = event_data.begin(); iter != event_data.end(); ++iter) {
119 
120  switch ((*iter).type) {
121  case EV_REL:
122  switch ((*iter).code) {
123  case REL_X:
124  channel[0] = (signed int)(*iter).value;
125  break;
126  case REL_Y:
127  channel[1] = (signed int)(*iter).value;
128  break;
129  case REL_WHEEL:
130  channel[2] = (signed int)(*iter).value;
131  break;
132  }
133  break;
134  case EV_KEY:
135  switch ((*iter).code) {
136  case BTN_LEFT:
137  index = 0;
138  break;
139  case BTN_RIGHT:
140  index = 1;
141  break;
142  case BTN_MIDDLE:
143  index = 2;
144  break;
145  default:
146  return;
147  }
148  switch ((*iter).value) {
149  case 0:
150  case 1:
151  buttons[index]=(*iter).value;
152  break;
153  case 2:
154  break;
155  default:
156  return;
157  }
158  break;
159  }
160  } // end for loop
161 
162  #ifdef DEBUG
163  {
164  int i;
165 
166  printf("channel: ");
167  for (i = 0; i < vrpn_Analog::num_channel; ++i) {
168 
169  //printf("float %4.2f ",channel[i]);
170  printf("channel %d mit %f; ",i, channel[i]);
171  }
172  printf("\n");
173 
174  printf("buttons: ");
175  for (i = 0; i < vrpn_Button::num_buttons; ++i) {
176 
177  //printf("float %4.2f ",buttons[i]);
178  printf("button %d mit %d; ",i,buttons[i]);
179  }
180  printf("\n");
181  }
182  #endif
183 
184  #endif // if defined(LINUX)
185 
186  vrpn_gettimeofday(&timestamp, 0);
187  vrpn_Analog::timestamp = timestamp;
188  vrpn_Button::timestamp = timestamp;
189 }
190 
191 
192 
193 /**************************************************************************************************/
194 /* clear values, reset to 0 */
195 /**************************************************************************************************/
196 void
197 vrpn_Event_Mouse::clear_values() {
198 
199  int i;
200  for ( i = 0; i < vrpn_Button::num_buttons; ++i) {
201 
202  vrpn_Button::buttons[i] = 0;
204  }
205 
206  for ( i = 0; i < vrpn_Analog::num_channel; ++i) {
207 
208  vrpn_Analog::channel[i] = 0;
209  vrpn_Analog::last[i] = 0;
210  }
211 }
virtual int mainloop(const struct timeval *timeout=NULL)=0
Call each time through program main loop to handle receiving any incoming messages and sending any pa...
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
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
#define REL_WHEEL
vrpn_int32 num_buttons
Definition: vrpn_Button.h:47
#define EV_REL
vrpn_float64 channel[vrpn_CHANNEL_MAX]
Definition: vrpn_Analog.h:38
#define REL_X
Generic connection class not specific to the transport mechanism.
#define BTN_MIDDLE
vrpn_Event_Mouse(const char *name, vrpn_Connection *c=0, const char *evdev_name="/dev/input/event0")
#define BTN_RIGHT
virtual void report_changes(void)
Definition: vrpn_Button.C:422
vrpn_int32 num_channel
Definition: vrpn_Analog.h:40
event_vector_t event_data
vrpn_Connection * d_connection
Connection that this object talks to.
virtual vrpn_bool connected(void) const
Returns vrpn_true if the connection has been established, vrpn_false if not (For a networkless connec...
#define BTN_LEFT
struct timeval timestamp
Definition: vrpn_Button.h:48
event_vector_t::iterator event_iter_t
#define vrpn_gettimeofday
Definition: vrpn_Shared.h:89
#define REL_Y
unsigned char lastbuttons[vrpn_BUTTON_MAX_BUTTONS]
Definition: vrpn_Button.h:45
unsigned char buttons[vrpn_BUTTON_MAX_BUTTONS]
Definition: vrpn_Button.h:44
struct timeval timestamp
Definition: vrpn_Analog.h:41
vrpn_float64 last[vrpn_CHANNEL_MAX]
Definition: vrpn_Analog.h:39
#define EV_KEY
void mainloop(void)
Called once each time through the server program&#39;s mainloop to handle various functions (like setting...