vrpn 07.36
Virtual Reality Peripheral Network
Loading...
Searching...
No Matches
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/**************************************************************************************************/
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/**************************************************************************************************/
72
73/**************************************************************************************************/
74/* mainloop */
75/**************************************************************************************************/
76void
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
94 d_connection->mainloop();
95}
96
97/**************************************************************************************************/
98/* helper function for mainloop */
99/**************************************************************************************************/
100void
101vrpn_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( vrpn_uint32 i = 0; i < event_data.size(); ++i) {
119 struct vrpn_Event::input_event *iter = &(event_data.data()[i]);
120
121 switch ((*iter).type) {
122 case EV_REL:
123 switch ((*iter).code) {
124 case REL_X:
125 channel[0] = (signed int)(*iter).value;
126 break;
127 case REL_Y:
128 channel[1] = (signed int)(*iter).value;
129 break;
130 case REL_WHEEL:
131 channel[2] = (signed int)(*iter).value;
132 break;
133 }
134 break;
135 case EV_KEY:
136 switch ((*iter).code) {
137 case BTN_LEFT:
138 index = 0;
139 break;
140 case BTN_RIGHT:
141 index = 1;
142 break;
143 case BTN_MIDDLE:
144 index = 2;
145 break;
146 default:
147 return;
148 }
149 switch ((*iter).value) {
150 case 0:
151 case 1:
152 buttons[index]=(*iter).value;
153 break;
154 case 2:
155 break;
156 default:
157 return;
158 }
159 break;
160 }
161 } // end for loop
162
163 #ifdef DEBUG
164 {
165 int i;
166
167 printf("channel: ");
168 for (i = 0; i < vrpn_Analog::num_channel; ++i) {
169
170 //printf("float %4.2f ",channel[i]);
171 printf("channel %d mit %f; ",i, channel[i]);
172 }
173 printf("\n");
174
175 printf("buttons: ");
176 for (i = 0; i < vrpn_Button::num_buttons; ++i) {
177
178 //printf("float %4.2f ",buttons[i]);
179 printf("button %d mit %d; ",i,buttons[i]);
180 }
181 printf("\n");
182 }
183 #endif
184
185 #endif // if defined(LINUX)
186
187 vrpn_gettimeofday(&timestamp, 0);
188 vrpn_Analog::timestamp = timestamp;
189 vrpn_Button::timestamp = timestamp;
190}
191
192
193
194/**************************************************************************************************/
195/* clear values, reset to 0 */
196/**************************************************************************************************/
197void
198vrpn_Event_Mouse::clear_values() {
199
200 int i;
201 for ( i = 0; i < vrpn_Button::num_buttons; ++i) {
202
205 }
206
207 for ( i = 0; i < vrpn_Analog::num_channel; ++i) {
208
210 vrpn_Analog::last[i] = 0;
211 }
212}
vrpn_float64 last[vrpn_CHANNEL_MAX]
Definition vrpn_Analog.h:39
vrpn_float64 channel[vrpn_CHANNEL_MAX]
Definition vrpn_Analog.h:38
struct timeval timestamp
Definition vrpn_Analog.h:41
vrpn_int32 num_channel
Definition vrpn_Analog.h:40
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_Connection * d_connection
Connection that this object talks to.
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
vrpn_Button_Server(const char *name, vrpn_Connection *c, int numbuttons=1)
vrpn_int32 num_buttons
Definition vrpn_Button.h:48
struct timeval timestamp
Definition vrpn_Button.h:49
virtual void report_changes(void)
unsigned char lastbuttons[vrpn_BUTTON_MAX_BUTTONS]
Definition vrpn_Button.h:46
unsigned char buttons[vrpn_BUTTON_MAX_BUTTONS]
Definition vrpn_Button.h:45
vrpn_Event_Analog(const char *name, vrpn_Connection *connection, const char *evdev_name)
event_vector_t event_data
void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_Event_Mouse(const char *name, vrpn_Connection *c=0, const char *evdev_name="/dev/input/event0")
#define EV_REL
#define BTN_LEFT
#define REL_WHEEL
#define REL_Y
#define EV_KEY
#define REL_X
#define BTN_MIDDLE
#define BTN_RIGHT
class VRPN_API vrpn_Connection
#define vrpn_gettimeofday