11 #if defined(VRPN_USE_HID) 14 static const vrpn_uint16 CHPRODUCTS_VENDOR = 0x068e;
15 static const vrpn_uint16 FIGHTERSTICK_USB = 0x00f3;
19 #define GAMEPAD_TRIGGER_THRESHOLD 30 25 static vrpn_float64 normalize_dpad(
unsigned char up,
unsigned char right,
unsigned char down,
unsigned char left)
41 size_t index = ((x + 1) * 3) + (y + 1);
42 vrpn_float64 angles[] = {225, 270, 315, 180, -1, 0, 135, 90, 45};
43 return (angles[index]);
46 static void normalize_axis(
const unsigned int value,
const short deadzone,
const vrpn_float64 scale, vrpn_float64& channel,
int wordSize = 16)
48 channel = (
static_cast<float>(value) - (
float) (1 << (wordSize - 1)));
49 if (fabs(channel) < (deadzone * 3 / 4))
55 channel /= (float) (1 << (wordSize - 1));
58 if (channel < -1.0) { channel = -1.0; }
59 if (channel > 1.0) { channel = 1.0; }
62 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)
64 normalize_axis(x, deadzone, scale, channelX, wordSize);
65 normalize_axis(y, deadzone, scale, channelY, wordSize);
68 static vrpn_float64 normalize_trigger(
unsigned int trigger)
71 int value = trigger - 0x80;
137 struct timeval current_time;
208 normalize_axes(buffer[0], buffer[1], 0x08, 1.0f,
channel[0],
channel[1], 8);
209 normalize_axis(buffer[2], 0x08, 1.0f,
channel[2], 8);
211 vrpn_uint8 value, mask;
212 value = (buffer[3] >> 4);
213 for (
int btn = 0; btn < 4; btn++)
215 mask =
static_cast<vrpn_uint8
>(1 << (btn % 8));
216 buttons[btn] = ((value & mask) != 0);
221 switch (buffer[3] & 0x0f)
256 switch (buffer[4] >> 4)
278 switch (buffer[4] & 0x0f)
302 switch (buffer[5] >> 4)
332 switch (buffer[5] & 0x0f)
355 fprintf(stderr,
"vrpn_CHProducts_Fighterstick_USB: Found a corrupted report; # total bytes = %u\n", static_cast<unsigned>(bytes));
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...
static int VRPN_CALLBACK on_last_disconnect(void *thisPtr, vrpn_HANDLERPARAM p)
vrpn_HidAcceptor * _filter
virtual void decodePacket(size_t bytes, vrpn_uint8 *buffer)=0
virtual void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
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 ...
#define GAMEPAD_TRIGGER_THRESHOLD
const char * vrpn_dropped_last_connection
virtual ~vrpn_CHProducts_Controller_Raw(void)
virtual void report(void)
static int VRPN_CALLBACK on_connect(void *thisPtr, vrpn_HANDLERPARAM p)
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.
const char * vrpn_got_connection
struct timeval _timestamp
void on_data_received(size_t bytes, vrpn_uint8 *buffer)
Derived class reimplements this callback.
#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...
vrpn_CHProducts_Controller_Raw(vrpn_HidAcceptor *filter, const char *name, vrpn_Connection *c=0)
vrpn_CHProducts_Fighterstick_USB(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)
vrpn_float64 last[vrpn_CHANNEL_MAX]