10#if defined(VRPN_USE_HID)
13static const vrpn_uint16 XKEYS_VENDOR = 0x05F3;
14static const vrpn_uint16 XKEYS_DESKTOP = 0x0281;
15static const vrpn_uint16 XKEYS_JOG_AND_SHUTTLE = 0x0241;
16static const vrpn_uint16 XKEYS_PRO = 0x0291;
17static const vrpn_uint16 XKEYS_JOYSTICK = 0x0251;
18static const vrpn_uint16 XKEYS_XK3 = 0x042C;
19static const vrpn_uint16 XKEYS_JOG_AND_SHUTTLE12 = 0x0426;
20static const vrpn_uint16 XKEYS_JOG_AND_SHUTTLE68 = 0x045a;
21static const vrpn_uint16 XKEYS_JOYSTICK12 = 0x0429;
29 , _toggle_light(toggle_light)
39 fprintf(stderr,
"vrpn_Xkeys::~vrpn_Xkeys(): delete failed\n");
78 vrpn_uint8 outputs[9] = {0};
87 fprintf(stderr,
"vrpn_Xkeys_v2::setLED(): Unrecognized state\n");
97 fprintf(stderr,
"vrpn_Xkeys_v2::setLED(): Unrecognized state\n");
106 vrpn_uint8 outputs[36] = {0};
122 fprintf(stderr,
"vrpn_Xkeys_v2::setLED(): Unrecognized state\n");
139 fprintf(stderr,
"vrpn_Xkeys_v2::setLED(): Unrecognized state\n");
184 for (
size_t i = 0; i < bytes / 11; i++) {
185 vrpn_uint8 *
report = buffer + (i * 11);
187 if (!(
report[10] & 0x08)) {
189 fprintf(stderr,
"vrpn_Xkeys_Desktop: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
197 for (
int btn = 0; btn < 20; btn++) {
198 vrpn_uint8 *offset, mask;
200 offset =
report + btn / 5;
201 mask =
static_cast<vrpn_uint8
>(1 << (btn % 5));
203 buttons[btn + 1] = (*offset & mask) != 0;
273 channel[0] =
static_cast<float>(
static_cast<signed char>(buffer[0])) / 7.0;
274 channel[1] =
static_cast<float>(buffer[1]);
289 for (
int btn = 0; btn < 35; btn++) {
290 vrpn_uint8 *offset, mask;
292 offset = buffer + btn / 7 + 3;
293 mask =
static_cast<vrpn_uint8
>(1 << (btn % 7));
295 buttons[btn + 1] = (*offset & mask) != 0;
298 }
else if (bytes == 6) {
300 if (!(buffer[5] & 0x08)) {
302 fprintf(stderr,
"vrpn_Xkeys: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
307 buttons[0] = (buffer[5] & 0x10) != 0;
313 for (
int btn = 35; btn < 58; btn++) {
314 vrpn_uint8 *offset, mask;
315 int local_btn = btn - 35;
317 offset = buffer + local_btn / 7;
318 mask =
static_cast<vrpn_uint8
>(1 << (local_btn % 7));
320 buttons[btn + 1] = (*offset & mask) != 0;
323 }
else if (bytes == 14) {
328 for (i = 0; i < bytes / 14; i++) {
329 vrpn_uint8 *
report = buffer + (i * 14);
331 if (!(
report[13] & 0x08)) {
333 fprintf(stderr,
"vrpn_Xkeys: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
343 for (
int btn = 0; btn < 58; btn++) {
344 vrpn_uint8 *offset, mask;
346 offset =
report + btn / 7 + 3;
347 mask =
static_cast<vrpn_uint8
>(1 << (btn % 7));
349 buttons[btn + 1] = (*offset & mask) != 0;
356 channel[0] =
static_cast<float>(
static_cast<signed char>(
report[0])) / 7.0;
368 fprintf(stderr,
"vrpn_Xkeys_Jog_And_Shuttle::decodePacket(): Unrecognized packet length (%u)\n",
static_cast<unsigned>(bytes));
447 if (bytes % 32 == 0) {
451 for (i = 0; i < bytes / 32; i++) {
452 vrpn_uint8 *
report = buffer + (i * 32);
457 fprintf(stderr,
"vrpn_Xkeys: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
460 for (
size_t j = 12; j < 32; j++) {
463 fprintf(stderr,
"vrpn_Xkeys: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
472 for (
int btn = 0; btn < 12; btn++) {
473 vrpn_uint8 *offset, mask;
475 offset =
report + btn / 3 + 2;
476 mask =
static_cast<vrpn_uint8
>(1 << (btn % 3));
478 buttons[btn + 1] = (*offset & mask) != 0;
487 dials[0] =
static_cast<vrpn_int8
>(
report[6]) / 10.0;
491 channel[0] =
static_cast<float>(
static_cast<signed char>(
report[7])) / 7.0;
499 fprintf(stderr,
"vrpn_Xkeys_Jog_And_Shuttle12::decodePacket(): Unrecognized packet length (%u)\n",
static_cast<unsigned>(bytes));
582 if (bytes % 32 == 0) {
586 for (i = 0; i < bytes / 32; i++) {
587 vrpn_uint8 *
report = buffer + (i * 32);
592 fprintf(stderr,
"vrpn_Xkeys: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
595 for (
size_t j = 22; j < 32; j++) {
598 fprintf(stderr,
"vrpn_Xkeys: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
607 for (
int btn = 0; btn < 68; btn++) {
613 if (btn > 28) { slot += 3; }
614 if (btn > 33) { slot += 3; }
615 if (btn > 38) { slot += 3; }
616 if (btn > 43) { slot += 3; }
617 vrpn_uint8 *offset, mask;
619 offset =
report + slot / 8 + 2;
620 mask =
static_cast<vrpn_uint8
>(1 << (slot % 8));
621 buttons[btn + 1] = (*offset & mask) != 0;
630 dials[0] =
static_cast<vrpn_int8
>(
report[16]) / 10.0;
634 channel[0] =
static_cast<float>(
static_cast<signed char>(
report[17])) / 7.0;
642 fprintf(stderr,
"vrpn_Xkeys_Jog_And_Shuttle68::decodePacket(): Unrecognized packet length (%u)\n",
static_cast<unsigned>(bytes));
710 channel[0] = (
static_cast<float>(buffer[0]) - 128) / 128.0;
711 channel[1] = (
static_cast<float>(buffer[1]) - 128) / 128.0;
712 channel[2] = (
static_cast<float>(buffer[2]) - 128) / 128.0;
720 for (
int btn = 0; btn < 35; btn++) {
721 vrpn_uint8 *offset, mask;
723 offset = buffer + btn / 7 + 3;
724 mask =
static_cast<vrpn_uint8
>(1 << (btn % 7));
726 buttons[btn + 1] = (*offset & mask) != 0;
729 }
else if (bytes == 6) {
731 if (!(buffer[5] & 0x08)) {
733 fprintf(stderr,
"vrpn_Xkeys: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
738 buttons[0] = (buffer[5] & 0x10) != 0;
744 for (
int btn = 35; btn < 58; btn++) {
745 vrpn_uint8 *offset, mask;
746 int local_btn = btn - 35;
748 offset = buffer + local_btn / 7;
749 mask =
static_cast<vrpn_uint8
>(1 << (local_btn % 7));
751 buttons[btn + 1] = (*offset & mask) != 0;
754 }
else if (bytes == 14) {
759 for (i = 0; i < bytes / 14; i++) {
760 vrpn_uint8 *
report = buffer + (i * 14);
762 if (!(
report[13] & 0x08)) {
764 fprintf(stderr,
"vrpn_Xkeys: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
774 for (
int btn = 0; btn < 58; btn++) {
775 vrpn_uint8 *offset, mask;
777 offset =
report + btn / 7 + 3;
778 mask =
static_cast<vrpn_uint8
>(1 << (btn % 7));
780 buttons[btn + 1] = (*offset & mask) != 0;
794 channel[0] =
static_cast<float>(
static_cast<signed char>(
report[6])) / 127.0;
795 channel[1] =
static_cast<float>(
static_cast<signed char>(
report[7])) / 127.0;
804 fprintf(stderr,
"vrpn_Xkeys_Joystick::decodePacket(): Unrecognized packet length (%u)\n",
static_cast<unsigned>(bytes));
880 if (bytes % 32 == 0) {
884 for (i = 0; i < bytes / 32; i++) {
885 vrpn_uint8 *
report = buffer + (i * 32);
890 fprintf(stderr,
"vrpn_Xkeys: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
893 for (
size_t j = 16; j < 32; j++) {
896 fprintf(stderr,
"vrpn_Xkeys: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
905 for (
int btn = 0; btn < 12; btn++) {
906 vrpn_uint8 *offset, mask;
908 offset =
report + btn / 3 + 2;
909 mask =
static_cast<vrpn_uint8
>(1 << (btn % 3));
911 buttons[btn + 1] = (*offset & mask) != 0;
924 channel[0] =
static_cast<float>(
static_cast<signed char>(
report[6])) / 127.0;
925 channel[1] = -
static_cast<float>(
static_cast<signed char>(
report[7])) / 127.0;
930 fprintf(stderr,
"vrpn_Xkeys_Joystick12::decodePacket(): Unrecognized packet length (%u)\n",
static_cast<unsigned>(bytes));
985 for (
int btn = 0; btn < 35; btn++) {
986 vrpn_uint8 *offset, mask;
988 offset = buffer + btn / 7 + 3;
989 mask =
static_cast<vrpn_uint8
>(1 << (btn % 7));
991 buttons[btn + 1] = (*offset & mask) != 0;
994 }
else if (bytes == 6) {
996 if (!(buffer[5] & 0x08)) {
998 fprintf(stderr,
"vrpn_Xkeys: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
1003 buttons[0] = (buffer[5] & 0x10) != 0;
1009 for (
int btn = 35; btn < 58; btn++) {
1010 vrpn_uint8 *offset, mask;
1011 int local_btn = btn - 35;
1013 offset = buffer + local_btn / 7;
1014 mask =
static_cast<vrpn_uint8
>(1 << (local_btn % 7));
1016 buttons[btn + 1] = (*offset & mask) != 0;
1019 }
else if (bytes == 14) {
1026 for (i = 0; i < bytes / 14; i++) {
1027 vrpn_uint8 *
report = buffer + (i * 14);
1029 if (!(
report[13] & 0x08)) {
1031 fprintf(stderr,
"vrpn_Xkeys: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
1041 for (
int btn = 0; btn < 58; btn++) {
1042 vrpn_uint8 *offset, mask;
1044 offset = buffer + btn / 7 + 3;
1045 mask =
static_cast<vrpn_uint8
>(1 << (btn % 7));
1047 buttons[btn + 1] = (*offset & mask) != 0;
1051 fprintf(stderr,
"vrpn_Xkeys_Pro::decodePacket(): Unrecognized packet length (%u)\n",
static_cast<unsigned>(bytes));
1093 for (
size_t i = 0; i < bytes / 32; i++) {
1094 vrpn_uint8 *
report = buffer + (i * 32);
1100 fprintf(stderr,
"vrpn_Xkeys_XK3: Found a corrupted report; # total bytes = %u\n",
static_cast<unsigned>(bytes));
vrpn_float64 last[vrpn_CHANNEL_MAX]
vrpn_float64 channel[vrpn_CHANNEL_MAX]
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...
Class from which all user-level (and other) classes that communicate with vrpn_Connections should der...
Generic connection class not specific to the transport mechanism.
virtual vrpn_int32 register_message_type(const char *name)
virtual void report_changes(void)
vrpn_float64 dials[vrpn_DIAL_MAX]
virtual void report(void)
virtual void update()
Polls the device buffers and causes on_data_received callbacks if appropriate You NEED to call this f...
void send_data(size_t bytes, const vrpn_uint8 *buffer)
Call this to send data to the device.
Accepts any device with the given vendor and product IDs.
vrpn_Xkeys_Desktop(const char *name, vrpn_Connection *c=0)
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
void report_changes(void)
vrpn_Xkeys_Jog_And_Shuttle12(const char *name, vrpn_Connection *c=0)
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_Xkeys_Jog_And_Shuttle68(const char *name, vrpn_Connection *c=0)
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
vrpn_Xkeys_Jog_And_Shuttle(const char *name, vrpn_Connection *c=0)
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_Xkeys_Joystick12(const char *name, vrpn_Connection *c=0)
vrpn_Xkeys_Joystick(const char *name, vrpn_Connection *c=0)
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
vrpn_Xkeys_Pro(const char *name, vrpn_Connection *c=0)
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
void report_changes(void)
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_Xkeys_XK3(const char *name, vrpn_Connection *c=0)
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
void report_changes(void)
virtual void setLEDs(LED_STATE red, LED_STATE green)
virtual void setLEDs(LED_STATE red, LED_STATE green)
struct timeval _timestamp
virtual void setLEDs(LED_STATE red, LED_STATE green)=0
vrpn_HidAcceptor * _filter
virtual void decodePacket(size_t bytes, vrpn_uint8 *buffer)=0
vrpn_Xkeys(vrpn_HidAcceptor *filter, const char *name, vrpn_Connection *c=0, vrpn_uint16 vendor=0, vrpn_uint16 product=0, bool toggle_light=true)
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.
static int VRPN_CALLBACK on_last_disconnect(void *thisPtr, vrpn_HANDLERPARAM p)
This structure is what is passed to a vrpn_Connection message callback.
const char * vrpn_dropped_last_connection
const char * vrpn_got_connection
#define vrpn_gettimeofday