vrpn
07.35
Virtual Reality Peripheral Network
Toggle main menu visibility
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
/**************************************************************************************************/
49
vrpn_Event_Mouse::vrpn_Event_Mouse
(
const
char
*name,
50
vrpn_Connection
*c,
51
const
char
* evdev_name) :
52
vrpn_Event_Analog
( name, c, evdev_name),
53
vrpn_Button_Server
(name,c)
54
{
55
vrpn_Button::num_buttons
= 3;
56
vrpn_Analog::num_channel
= 3;
57
58
vrpn_gettimeofday
(×tamp, 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
/**************************************************************************************************/
69
vrpn_Event_Mouse::~vrpn_Event_Mouse
() {
70
71
}
72
73
/**************************************************************************************************/
74
/* mainloop */
75
/**************************************************************************************************/
76
void
77
vrpn_Event_Mouse::mainloop
() {
78
79
server_mainloop
();
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
90
vrpn_Analog::report_changes
();
91
vrpn_Button::report_changes
();
92
93
// send messages
94
d_connection
->mainloop();
95
}
96
97
/**************************************************************************************************/
98
/* helper function for mainloop */
99
/**************************************************************************************************/
100
void
101
vrpn_Event_Mouse::process_mouse_data() {
102
103
// try to read data
104
if
( 0 ==
vrpn_Event_Analog::read_available_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
(×tamp, 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;
203
vrpn_Button::lastbuttons
[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
}
vrpn_Analog::last
vrpn_float64 last[vrpn_CHANNEL_MAX]
Definition
vrpn_Analog.h:39
vrpn_Analog::channel
vrpn_float64 channel[vrpn_CHANNEL_MAX]
Definition
vrpn_Analog.h:38
vrpn_Analog::timestamp
struct timeval timestamp
Definition
vrpn_Analog.h:41
vrpn_Analog::num_channel
vrpn_int32 num_channel
Definition
vrpn_Analog.h:40
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_BaseClassUnique::d_connection
vrpn_Connection * d_connection
Connection that this object talks to.
Definition
vrpn_BaseClass.h:227
vrpn_BaseClassUnique::server_mainloop
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
Definition
vrpn_BaseClass.C:604
vrpn_Button_Server::vrpn_Button_Server
vrpn_Button_Server(const char *name, vrpn_Connection *c, int numbuttons=1)
Definition
vrpn_Button.C:457
vrpn_Button::num_buttons
vrpn_int32 num_buttons
Definition
vrpn_Button.h:48
vrpn_Button::timestamp
struct timeval timestamp
Definition
vrpn_Button.h:49
vrpn_Button::report_changes
virtual void report_changes(void)
Definition
vrpn_Button.C:423
vrpn_Button::lastbuttons
unsigned char lastbuttons[vrpn_BUTTON_MAX_BUTTONS]
Definition
vrpn_Button.h:46
vrpn_Button::buttons
unsigned char buttons[vrpn_BUTTON_MAX_BUTTONS]
Definition
vrpn_Button.h:45
vrpn_Event_Analog::vrpn_Event_Analog
vrpn_Event_Analog(const char *name, vrpn_Connection *connection, const char *evdev_name)
Definition
vrpn_Event_Analog.C:29
vrpn_Event_Analog::event_data
event_vector_t event_data
Definition
vrpn_Event_Analog.h:59
vrpn_Event_Analog::event_iter_t
event_vector_t::iterator event_iter_t
Definition
vrpn_Event_Analog.h:50
vrpn_Event_Analog::read_available_data
int read_available_data()
Definition
vrpn_Event_Analog.C:95
vrpn_Event_Mouse::mainloop
void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition
vrpn_Event_Mouse.C:77
vrpn_Event_Mouse::~vrpn_Event_Mouse
~vrpn_Event_Mouse()
Definition
vrpn_Event_Mouse.C:69
vrpn_Event_Mouse::vrpn_Event_Mouse
vrpn_Event_Mouse(const char *name, vrpn_Connection *c=0, const char *evdev_name="/dev/input/event0")
Definition
vrpn_Event_Mouse.C:49
vrpn_Analog.h
vrpn_Connection.h
vrpn_Event.h
EV_REL
#define EV_REL
Definition
vrpn_Event_Mouse.C:34
BTN_LEFT
#define BTN_LEFT
Definition
vrpn_Event_Mouse.C:38
REL_WHEEL
#define REL_WHEEL
Definition
vrpn_Event_Mouse.C:41
REL_Y
#define REL_Y
Definition
vrpn_Event_Mouse.C:36
EV_KEY
#define EV_KEY
Definition
vrpn_Event_Mouse.C:33
REL_X
#define REL_X
Definition
vrpn_Event_Mouse.C:35
BTN_MIDDLE
#define BTN_MIDDLE
Definition
vrpn_Event_Mouse.C:40
BTN_RIGHT
#define BTN_RIGHT
Definition
vrpn_Event_Mouse.C:39
vrpn_Event_Mouse.h
vrpn_Connection
class VRPN_API vrpn_Connection
Definition
vrpn_Event_Mouse.h:25
vrpn_Shared.h
vrpn_gettimeofday
#define vrpn_gettimeofday
Definition
vrpn_Shared.h:99
vrpn_Types.h
vrpn_Event_Mouse.C
Generated by
1.17.0