11 #if defined(VRPN_USE_HID) 15 #define MS_GAMEPAD_LEFT_THUMB_DEADZONE 7849 16 #define MS_GAMEPAD_RIGHT_THUMB_DEADZONE 8689 17 #define MS_GAMEPAD_TRIGGER_THRESHOLD 30 22 static vrpn_float64 normalize_dpad(
unsigned char up,
unsigned char right,
unsigned char down,
unsigned char left)
42 size_t index = ((x + 1) * 3) + (y + 1);
43 vrpn_float64 angles[] = {225, 270, 315, 180, -1, 0, 135, 90, 45};
44 return (angles[index]);
47 static void normalize_axis(
const unsigned int value,
const short deadzone,
const vrpn_float64 scale, vrpn_float64& channel,
int wordSize = 16)
49 channel = (static_cast<float>(value) - (float) (1 << (wordSize - 1)));
50 if (fabs(channel) < (deadzone * 3 / 4))
56 channel /= (float) (1 << (wordSize - 1));
59 if (channel < -1.0) { channel = -1.0; }
60 if (channel > 1.0) { channel = 1.0; }
63 static void normalize_axes(
const unsigned int x,
const unsigned int y,
const short deadzone,
const vrpn_float64 scale, vrpn_float64& channelX, vrpn_float64& channelY,
int wordSize = 16)
68 float magnitude = (float) sqrt((
double) ((x * x) + (y * y)));
71 float normalizedX = ((magnitude > 0.0f) ? (x / magnitude) : 0.0f);
72 float normalizedY = ((magnitude > 0.0f) ? (y / magnitude) : 0.0f);
74 float normalizedMagnitude = 0.0f;
77 if (magnitude > deadzone)
80 if (magnitude > 32767)
86 magnitude -= deadzone;
90 normalizedMagnitude = magnitude / (32767.0f - deadzone);
95 normalizedMagnitude = 0.0f;
98 normalize_axis(x, deadzone, scale, channelX, wordSize);
99 normalize_axis(y, deadzone, scale, channelY, wordSize);
103 static vrpn_float64 normalize_trigger(
unsigned int trigger)
106 int value = trigger - 0x80;
171 struct timeval current_time;
240 normalize_axes(buffer[0], buffer[1], 0x08, 1.0f,
channel[0],
channel[1], 8);
241 normalize_axis(buffer[2], 0x08, 1.0f,
channel[2], 8);
242 normalize_axis(buffer[3], 0x08, 1.0f,
channel[3], 8);
244 vrpn_uint8 value, mask;
246 for (
int btn = 0; btn < 8; btn++)
248 mask = static_cast<vrpn_uint8>(1 << (btn % 8));
249 buttons[btn] = ((value & mask) != 0);
254 switch (buffer[5] >> 4)
289 fprintf(stderr,
"vrpn_Microsoft_SideWinder_Precision_2: Found a corrupted report; # total bytes = %u\n", static_cast<unsigned>(bytes));
315 struct timeval current_time;
382 normalize_axes(buffer[0], buffer[1], 0x08, 1.0f,
channel[0],
channel[1], 8);
383 normalize_axis(buffer[2], 0x08, 1.0f,
channel[2], 8);
385 vrpn_uint8 value, mask;
387 for (
int btn = 0; btn < 8; btn++)
389 mask = static_cast<vrpn_uint8>(1 << (btn % 8));
390 buttons[btn] = ((value & mask) != 0);
395 fprintf(stderr,
"vrpn_Microsoft_SideWinder: Found a corrupted report; # total bytes = %u\n", static_cast<unsigned>(bytes));
424 struct timeval current_time;
513 if (buffer[0] == 1) {
520 bufptr = &buffer[32];
521 x = vrpn_unbuffer<vrpn_int16>(bufptr);
523 bufptr = &buffer[34];
524 y = vrpn_unbuffer<vrpn_int16>(bufptr);
527 bufptr = &buffer[36];
528 x = vrpn_unbuffer<vrpn_int16>(bufptr);
530 bufptr = &buffer[38];
531 y = vrpn_unbuffer<vrpn_int16>(bufptr);
536 temp = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr) / 2;
537 x = temp + (1 << 15);
540 temp = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr) / 2;
541 y = temp + (1 << 15);
544 bufptr = &buffer[10];
545 temp = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr) / 2;
546 x = temp + (1 << 15);
547 bufptr = &buffer[12];
548 temp = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr) / 2;
549 y = temp + (1 << 15);
555 buttons[0] = (buffer[24] != 0);
557 buttons[1] = (buffer[25] != 0);
559 buttons[2] = (buffer[26] != 0);
561 buttons[3] = (buffer[27] != 0);
563 buttons[4] = (buffer[28] != 0);
565 buttons[5] = (buffer[29] != 0);
567 buttons[6] = ((buffer[22] & 0x10) != 0);
569 buttons[7] = ((buffer[22] & 0x20) != 0);
571 buttons[8] = ((buffer[22] & 0x40) != 0);
573 buttons[9] = ((buffer[22] & 0x80) != 0);
575 buttons[10] = (buffer[30] != 0);
577 buttons[11] = (buffer[31] != 0);
579 vrpn_uint8 value, mask;
581 for (
int btn = 0; btn < 8; btn++)
583 mask = static_cast<vrpn_uint8>(1 << (btn % 8));
584 buttons[btn] = ((value & mask) != 0);
587 for (
int btn = 0; btn < 4; btn++)
589 mask = static_cast<vrpn_uint8>(1 << (btn % 8));
590 buttons[8 + btn] = ((value & mask) != 0);
596 buttons[12] = ((buffer[22] & 0x01) != 0);
597 buttons[14] = ((buffer[22] & 0x02) != 0);
598 buttons[15] = ((buffer[22] & 0x04) != 0);
599 buttons[13] = ((buffer[22] & 0x08) != 0);
603 switch (buffer[18] & 0x0f)
637 fprintf(stderr,
"vrpn_Microsoft_Controller_Raw_Xbox_S: Unknown report = %u\n", static_cast<unsigned>(buffer[0]));
640 fprintf(stderr,
"vrpn_Microsoft_Controller_Raw_Xbox_S: Found a corrupted report; # total bytes = %u\n", static_cast<unsigned>(bytes));
669 struct timeval current_time;
746 x = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr);
749 y = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr);
753 x = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr);
756 y = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr);
760 channel[4] = normalize_trigger(buffer[9]);
764 for (
int btn = 0; btn < 8; btn++) {
775 vrpn_uint8 mask = static_cast<vrpn_uint8>(1 << (btn % 8));
776 buttons[btn] = ((value & mask) != 0);
779 for (
int btn = 0; btn < 2; btn++) {
784 vrpn_uint8 mask = static_cast<vrpn_uint8>(1 << (btn % 8));
785 buttons[8 + btn] = ((value & mask) != 0);
802 int lowerBtn = (10 + (value >> 3)) & 0x03;
833 fprintf(stderr,
"vrpn_Microsoft_Controller_Raw_Xbox_360: Unknown report = %u\n", static_cast<unsigned>(buffer[0]));
836 fprintf(stderr,
"vrpn_Microsoft_Controller_Raw_Xbox_360: Found a corrupted report; # total bytes = %u\n", static_cast<unsigned>(bytes));
virtual void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
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...
vrpn_Microsoft_Controller_Raw(vrpn_HidAcceptor *filter, const char *name, vrpn_Connection *c=0)
#define MS_GAMEPAD_TRIGGER_THRESHOLD
vrpn_Microsoft_Controller_Raw_Xbox_360(const char *name, vrpn_Connection *c=0, vrpn_uint16 vendorId=MICROSOFT_VENDOR, vrpn_uint16 productId=XBOX_360)
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
vrpn_Microsoft_SideWinder(const char *name, vrpn_Connection *c=0)
vrpn_float64 channel[vrpn_CHANNEL_MAX]
Accepts any device with the given vendor and product IDs.
Generic connection class not specific to the transport mechanism.
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 ...
const char * vrpn_dropped_last_connection
struct timeval _timestamp
#define MS_GAMEPAD_LEFT_THUMB_DEADZONE
virtual void report(void)
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.
vrpn_Connection * d_connection
Connection that this object talks to.
This structure is what is passed to a vrpn_Connection message callback.
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
vrpn_Microsoft_Controller_Raw_Xbox_S(const char *name, vrpn_Connection *c=0)
virtual ~vrpn_Microsoft_Controller_Raw(void)
const char * vrpn_got_connection
static int VRPN_CALLBACK on_last_disconnect(void *thisPtr, vrpn_HANDLERPARAM p)
virtual void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
#define vrpn_gettimeofday
virtual void update()
Polls the device buffers and causes on_data_received callbacks if appropriate You NEED to call this f...
Class from which all user-level (and other) classes that communicate with vrpn_Connections should der...
virtual void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
#define MS_GAMEPAD_RIGHT_THUMB_DEADZONE
vrpn_HidAcceptor * _filter
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
virtual void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
static int VRPN_CALLBACK on_connect(void *thisPtr, vrpn_HANDLERPARAM p)
void on_data_received(size_t bytes, vrpn_uint8 *buffer)
Derived class reimplements this callback.
vrpn_Microsoft_SideWinder_Precision_2(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.
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
virtual vrpn_int32 register_message_type(const char *name)
virtual void decodePacket(size_t bytes, vrpn_uint8 *buffer)=0
vrpn_float64 last[vrpn_CHANNEL_MAX]