12static const vrpn_uint16 MICROSOFT_VENDOR = 0x045e;
13static const vrpn_uint16 SIDEWINDER_PRECISION_2 = 0x0038;
14static const vrpn_uint16 SIDEWINDER = 0x003c;
15static const vrpn_uint16 XBOX_S = 0x0289;
16static const vrpn_uint16 XBOX_360 = 0x028e;
17static const vrpn_uint16 XBOX_360_WIRELESS = 0x02a1;
20static const vrpn_uint16 AFTERGLOW_VENDOR = 0x0e6f;
21static const vrpn_uint16 AX1_FOR_XBOX_360 = 0x0213;
23#if defined(VRPN_USE_HID)
27#define MS_GAMEPAD_LEFT_THUMB_DEADZONE 7849
28#define MS_GAMEPAD_RIGHT_THUMB_DEADZONE 8689
29#define MS_GAMEPAD_TRIGGER_THRESHOLD 30
34static vrpn_float64 normalize_dpad(
unsigned char up,
unsigned char right,
unsigned char down,
unsigned char left)
54 size_t index = ((x + 1) * 3) + (y + 1);
55 vrpn_float64 angles[] = {225, 270, 315, 180, -1, 0, 135, 90, 45};
56 return (angles[index]);
59static void normalize_axis(
const unsigned int value,
const short deadzone,
const vrpn_float64 scale, vrpn_float64& channel,
int wordSize = 16)
61 channel = (
static_cast<float>(value) - (float) (1 << (wordSize - 1)));
62 if (fabs(channel) < (deadzone * 3 / 4))
68 channel /= (float) (1 << (wordSize - 1));
71 if (channel < -1.0) { channel = -1.0; }
72 if (channel > 1.0) { channel = 1.0; }
75static 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)
80 float magnitude = (float) sqrt((
double) ((x * x) + (y * y)));
83 float normalizedX = ((magnitude > 0.0f) ? (x / magnitude) : 0.0f);
84 float normalizedY = ((magnitude > 0.0f) ? (y / magnitude) : 0.0f);
86 float normalizedMagnitude = 0.0f;
89 if (magnitude > deadzone)
92 if (magnitude > 32767)
98 magnitude -= deadzone;
102 normalizedMagnitude = magnitude / (32767.0f - deadzone);
107 normalizedMagnitude = 0.0f;
110 normalize_axis(x, deadzone, scale, channelX, wordSize);
111 normalize_axis(y, deadzone, scale, channelY, wordSize);
115static vrpn_float64 normalize_trigger(
unsigned int trigger)
118 int value = trigger - 0x80;
139 fprintf(stderr,
"vrpn_Microsoft_Controller_Raw::~vrpn_Microsoft_Controller_Raw(): delete failed\n");
187 struct timeval current_time;
252 normalize_axes(buffer[0], buffer[1], 0x08, 1.0f,
channel[0],
channel[1], 8);
253 normalize_axis(buffer[2], 0x08, 1.0f,
channel[2], 8);
254 normalize_axis(buffer[3], 0x08, 1.0f,
channel[3], 8);
256 vrpn_uint8 value, mask;
258 for (
int btn = 0; btn < 8; btn++)
260 mask =
static_cast<vrpn_uint8
>(1 << (btn % 8));
261 buttons[btn] = ((value & mask) != 0);
266 switch (buffer[5] >> 4)
301 fprintf(stderr,
"vrpn_Microsoft_SideWinder_Precision_2: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
327 struct timeval current_time;
390 normalize_axes(buffer[0], buffer[1], 0x08, 1.0f,
channel[0],
channel[1], 8);
391 normalize_axis(buffer[2], 0x08, 1.0f,
channel[2], 8);
393 vrpn_uint8 value, mask;
395 for (
int btn = 0; btn < 8; btn++)
397 mask =
static_cast<vrpn_uint8
>(1 << (btn % 8));
398 buttons[btn] = ((value & mask) != 0);
403 fprintf(stderr,
"vrpn_Microsoft_SideWinder: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
432 struct timeval current_time;
517 if (buffer[0] == 1) {
524 bufptr = &buffer[32];
527 bufptr = &buffer[34];
531 bufptr = &buffer[36];
534 bufptr = &buffer[38];
540 temp = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr) / 2;
541 x = temp + (1 << 15);
544 temp = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr) / 2;
545 y = temp + (1 << 15);
548 bufptr = &buffer[10];
549 temp = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr) / 2;
550 x = temp + (1 << 15);
551 bufptr = &buffer[12];
552 temp = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr) / 2;
553 y = temp + (1 << 15);
559 buttons[0] = (buffer[24] != 0);
561 buttons[1] = (buffer[25] != 0);
563 buttons[2] = (buffer[26] != 0);
565 buttons[3] = (buffer[27] != 0);
567 buttons[4] = (buffer[28] != 0);
569 buttons[5] = (buffer[29] != 0);
571 buttons[6] = ((buffer[22] & 0x10) != 0);
573 buttons[7] = ((buffer[22] & 0x20) != 0);
575 buttons[8] = ((buffer[22] & 0x40) != 0);
577 buttons[9] = ((buffer[22] & 0x80) != 0);
579 buttons[10] = (buffer[30] != 0);
581 buttons[11] = (buffer[31] != 0);
583 vrpn_uint8 value, mask;
585 for (
int btn = 0; btn < 8; btn++)
587 mask =
static_cast<vrpn_uint8
>(1 << (btn % 8));
588 buttons[btn] = ((value & mask) != 0);
591 for (
int btn = 0; btn < 4; btn++)
593 mask =
static_cast<vrpn_uint8
>(1 << (btn % 8));
594 buttons[8 + btn] = ((value & mask) != 0);
600 buttons[12] = ((buffer[22] & 0x01) != 0);
601 buttons[14] = ((buffer[22] & 0x02) != 0);
602 buttons[15] = ((buffer[22] & 0x04) != 0);
603 buttons[13] = ((buffer[22] & 0x08) != 0);
607 switch (buffer[18] & 0x0f)
641 fprintf(stderr,
"vrpn_Microsoft_Controller_Raw_Xbox_S: Unknown report = %u\n",
static_cast<unsigned>(buffer[0]));
644 fprintf(stderr,
"vrpn_Microsoft_Controller_Raw_Xbox_S: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
673 struct timeval current_time;
747 x = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr);
750 y = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr);
754 x = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr);
757 y = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr);
761 channel[4] = normalize_trigger(buffer[9]);
765 for (
int btn = 0; btn < 8; btn++) {
776 vrpn_uint8 mask =
static_cast<vrpn_uint8
>(1 << (btn % 8));
777 buttons[btn] = ((value & mask) != 0);
780 for (
int btn = 0; btn < 2; btn++) {
785 vrpn_uint8 mask =
static_cast<vrpn_uint8
>(1 << (btn % 8));
786 buttons[8 + btn] = ((value & mask) != 0);
834 fprintf(stderr,
"vrpn_Microsoft_Controvrpn_Microsoft_Controller_Raw_Xbox_360_baseller_Raw_Xbox_360: Unknown report = %u\n",
static_cast<unsigned>(buffer[0]));
837 fprintf(stderr,
"vrpn_Microsoft_Controller_Raw_Xbox_360_base: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
vrpn_Afterglow_Ax1_For_Xbox_360(const char *name, vrpn_Connection *c)
vrpn_float64 last[vrpn_CHANNEL_MAX]
vrpn_float64 channel[vrpn_CHANNEL_MAX]
vrpn_Analog(const char *name, vrpn_Connection *c=NULL)
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 ...
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...
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.
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
vrpn_BaseClass(const char *name, vrpn_Connection *c=NULL)
Names the device and assigns or opens connection, calls registration methods.
Generic connection class not specific to the transport mechanism.
virtual void report(void)
vrpn_Dial(const char *name, vrpn_Connection *c=NULL)
vrpn_uint16 product() const
Returns USB product ID of connected device May not contain valid if an already-open device was provid...
vrpn_HidInterface(vrpn_HidAcceptor *acceptor, vrpn_uint16 vendor=0, vrpn_uint16 product=0, hid_device *device=NULL)
Constructor If we already have a HID device from some other source, it can be passed and we'll take o...
virtual void update()
Polls the device buffers and causes on_data_received callbacks if appropriate You NEED to call this f...
vrpn_uint16 vendor() const
Returns USB vendor ID of connected device May not contain valid if an already-open device was provide...
Accepts any device with the given vendor and product IDs.
vrpn_Microsoft_Controller_Raw_Xbox_360_Wireless(const char *name, vrpn_Connection *c)
virtual void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
vrpn_Microsoft_Controller_Raw_Xbox_360_base(const char *name, vrpn_Connection *c=0, vrpn_uint16 vendor=0, vrpn_uint16 product=0)
vrpn_Microsoft_Controller_Raw_Xbox_360(const char *name, vrpn_Connection *c)
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 ...
vrpn_Microsoft_Controller_Raw_Xbox_S(const char *name, vrpn_Connection *c=0)
void on_data_received(size_t bytes, vrpn_uint8 *buffer)
Derived class reimplements this callback.
virtual ~vrpn_Microsoft_Controller_Raw(void)
static int VRPN_CALLBACK on_last_disconnect(void *thisPtr, vrpn_HANDLERPARAM p)
vrpn_HidAcceptor * _filter
static int VRPN_CALLBACK on_connect(void *thisPtr, vrpn_HANDLERPARAM p)
virtual void decodePacket(size_t bytes, vrpn_uint8 *buffer)=0
vrpn_Microsoft_Controller_Raw(vrpn_HidAcceptor *filter, const char *name, vrpn_Connection *c=0, vrpn_uint16 vendor=0, vrpn_uint16 product=0)
struct timeval _timestamp
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 ...
vrpn_Microsoft_SideWinder_Precision_2(const char *name, vrpn_Connection *c=0)
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 ...
vrpn_Microsoft_SideWinder(const char *name, vrpn_Connection *c=0)
This structure is what is passed to a vrpn_Connection message callback.
const char * vrpn_dropped_last_connection
const char * vrpn_got_connection
#define MS_GAMEPAD_TRIGGER_THRESHOLD
#define MS_GAMEPAD_LEFT_THUMB_DEADZONE
#define MS_GAMEPAD_RIGHT_THUMB_DEADZONE
VRPN_API int vrpn_unbuffer(const char **buffer, timeval *t)
Utility routine for taking a struct timeval from a buffer that was sent as a message.
unsigned long vrpn_TimevalDuration(struct timeval endT, struct timeval startT)
Return number of microseconds between startT and endT.
#define vrpn_gettimeofday