vrpn
07.33
Virtual Reality Peripheral Network
|
Go to the documentation of this file.
10 #if defined(VRPN_USE_HID)
15 static const vrpn_uint16 RETROLINK_VENDOR = 0x0079;
16 static const vrpn_uint16 RETROLINK_GAMECUBE = 0x0006;
22 static vrpn_float64 normalize_axis(
const vrpn_uint8 value)
24 vrpn_float64 offset = static_cast<vrpn_float64>(value) - 128;
25 vrpn_float64 scaled = offset / 127;
26 if (scaled > 1) { scaled = 1; }
27 if (scaled < -1) { scaled = -1; }
32 static void angle_and_buttons_from_rocker(
const vrpn_uint8 value,
34 bool *up,
bool *right,
bool *down,
bool *left)
37 case 0: *angle = 0; *up =
true; *right =
false; *down =
false; *left =
false;
break;
38 case 1: *angle = 45; *up =
true; *right =
true; *down =
false; *left =
false;
break;
39 case 2: *angle = 90; *up =
false; *right =
true; *down =
false; *left =
false;
break;
40 case 3: *angle = 135; *up =
false; *right =
true; *down =
true; *left =
false;
break;
41 case 4: *angle = 180; *up =
false; *right =
false; *down =
true; *left =
false;
break;
42 case 5: *angle = 225; *up =
false; *right =
false; *down =
true; *left =
true;
break;
43 case 6: *angle = 270; *up =
false; *right =
false; *down =
false; *left =
true;
break;
44 case 7: *angle = 315; *up =
true; *right =
false; *down =
false; *left =
true;
break;
45 default: *angle = -1; *up =
false; *right =
false; *down =
false; *left =
false;
break;
103 struct timeval current_time;
186 channel[0] = normalize_axis(buffer[0]);
187 channel[1] = normalize_axis(buffer[1]);
188 channel[2] = normalize_axis(buffer[3]);
189 channel[3] = normalize_axis(buffer[4]);
192 buttons[0] = (buffer[5] & (1 << 4)) != 0;
193 buttons[1] = (buffer[5] & (1 << 5)) != 0;
194 buttons[2] = (buffer[5] & (1 << 6)) != 0;
195 buttons[3] = (buffer[5] & (1 << 7)) != 0;
196 buttons[4] = (buffer[6] & (1 << 0)) != 0;
197 buttons[5] = (buffer[6] & (1 << 1)) != 0;
198 buttons[6] = (buffer[6] & (1 << 2)) != 0;
199 buttons[7] = (buffer[6] & (1 << 5)) != 0;
202 vrpn_uint8 rocker = buffer[5] & 0x0f;
204 bool up, right, down, left;
205 angle_and_buttons_from_rocker(rocker, &angle, &up, &right, &down, &left);
212 fprintf(stderr,
"vrpn_Retrolink_GameCube: Found a corrupted report; # total bytes = %u\n", static_cast<unsigned>(bytes));
int register_autodeleted_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
Registers a handler with the connection, and remembers to delete at destruction.
virtual void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
struct timeval _timestamp
const char * vrpn_got_connection
vrpn_Retrolink(vrpn_HidAcceptor *filter, const char *name, vrpn_Connection *c=0)
unsigned long vrpn_TimevalDuration(struct timeval endT, struct timeval startT)
Return number of microseconds between startT and endT.
vrpn_float64 channel[vrpn_CHANNEL_MAX]
const char * vrpn_dropped_last_connection
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 ...
static int VRPN_CALLBACK on_connect(void *thisPtr, vrpn_HANDLERPARAM p)
vrpn_HidAcceptor * _filter
void on_data_received(size_t bytes, vrpn_uint8 *buffer)
Derived class reimplements this callback.
virtual void update()
Polls the device buffers and causes on_data_received callbacks if appropriate You NEED to call this f...
vrpn_Connection * d_connection
Connection that this object talks to.
virtual vrpn_int32 register_message_type(const char *name)
virtual ~vrpn_Retrolink(void)
This structure is what is passed to a vrpn_Connection message callback.
Accepts any device with the given vendor and product IDs.
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
Generic connection class not specific to the transport mechanism.
void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY)
#define vrpn_gettimeofday
static int VRPN_CALLBACK on_last_disconnect(void *thisPtr, vrpn_HANDLERPARAM p)
virtual void decodePacket(size_t bytes, vrpn_uint8 *buffer)=0
vrpn_Retrolink_GameCube(const char *name, vrpn_Connection *c=0)
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
Class from which all user-level (and other) classes that communicate with vrpn_Connections should der...