10#if defined(linux) && !defined(VRPN_USE_HID)
11#define VRPN_USING_3DCONNEXION_EVENT_IFACE
12#include <linux/input.h>
17typedef struct input_devinfo {
22} XXX_should_have_been_in_system_includes;
25static const vrpn_uint16 vrpn_3DCONNEXION_VENDOR = 0x046d;
26static const vrpn_uint16 vrpn_SPACEMOUSEWIRELESS_VENDOR = 9583;
27static const vrpn_uint16 vrpn_3DCONNEXION_TRAVELER = 50723;
28static const vrpn_uint16 vrpn_3DCONNEXION_NAVIGATOR = 50726;
29static const vrpn_uint16 vrpn_3DCONNEXION_NAVIGATOR_FOR_NOTEBOOKS = 0xc628;
30static const vrpn_uint16 vrpn_3DCONNEXION_SPACEEXPLORER = 0xc627;
31static const vrpn_uint16 vrpn_3DCONNEXION_SPACEMOUSE = 50691;
32static const vrpn_uint16 vrpn_3DCONNEXION_SPACEMOUSEPRO = 50731;
33static const vrpn_uint16 vrpn_3DCONNEXION_SPACEMOUSECOMPACT = 50741;
34static const vrpn_uint16 vrpn_3DCONNEXION_SPACEMOUSEWIRELESS = 50735;
35static const vrpn_uint16 vrpn_3DCONNEXION_SPACEMOUSEPROWIRELESS = 0xC631;
36static const vrpn_uint16 vrpn_3DCONNEXION_SPACEBALL5000 = 0xc621;
37static const vrpn_uint16 vrpn_3DCONNEXION_SPACEPILOT = 0xc625;
38static const vrpn_uint16 vrpn_3DCONNEXION_SPACEPILOTPRO = 0xc629;
42 vrpn_uint16 vendor, vrpn_uint16 product)
65#if defined(VRPN_USING_3DCONNEXION_EVENT_IFACE)
74 char *fname = (
char *)malloc(1000*
sizeof(
char));
76 sprintf(fname,
"/dev/input/event%d", i++);
77 f = fopen(fname,
"r+b");
81 struct input_devinfo ID;
82 ioctl(fileno(f), EVIOCGID, &ID);
98 perror(
"Could not open the device");
109 fprintf(stderr,
"vrpn_3DConnexion::vrpn_3DConnexion(): No implementation compiled in "
110 "to open this device. Please recompile.\n");
117#if defined(VRPN_USING_3DCONNEXION_EVENT_IFACE)
123 fprintf(stderr,
"vrpn_3DConnexion::~vrpn_3DConnexion(): delete failed\n");
128#if defined(VRPN_USE_HID)
137#if defined(VRPN_USE_HID)
142#elif defined(VRPN_USING_3DCONNEXION_EVENT_IFACE)
143 struct timeval zerotime;
145 struct input_event ev;
149 zerotime.tv_usec = 0;
157 if (FD_ISSET(fd, &fdset)) {
159 if (
vrpn_noint_block_read(fd,
reinterpret_cast<char*
>(&ev),
sizeof(
struct input_event)) !=
sizeof(
struct input_event)) {
167 buttons[ev.code & 0x0ff] = ev.value;
176 channel[ev.code] =
static_cast<double>(i)/400.0;
184 }
while (moreData == 1);
209#if defined(linux) && !defined(VRPN_USE_HID)
210int vrpn_3DConnexion::set_led(
int led_state)
212 struct input_event event;
216 event.code = LED_MISC;
217 event.value = led_state;
219 ret = write(fd, &event,
sizeof(
struct input_event));
221 perror (
"setting led state failed");
223 return ret < static_cast<int>(
sizeof(
struct input_event));
227#if defined(VRPN_USE_HID)
237 fprintf(stderr,
"vrpn_3DConnexion::decodePacket(): Long packet (%d bytes), may mis-parse\n",
238 static_cast<int>(bytes));
244 for (
size_t i = 0; i < bytes / 7; i++) {
245 vrpn_uint8 *
report = buffer + (i * 7);
249 char report_type =
report[0];
250 vrpn_uint8 *bufptr = &
report[1];
251 const float scale = 1.0f/400.0f;
252 switch (report_type) {
263 channel[0] = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr) * scale;
266 channel[1] = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr) * scale;
269 channel[2] = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr) * scale;
275 channel[3] = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr) * scale;
278 channel[4] = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr) * scale;
281 channel[5] = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr) * scale;
312 vrpn_uint8 *location, mask;
313 location =
report + 1 + (btn / 8);
314 mask = 1 << (btn % 8);
315 buttons[btn] = ( (*location) & mask) != 0;
336 :
vrpn_3DConnexion(new
vrpn_HidProductAcceptor(vrpn_3DCONNEXION_VENDOR, vrpn_3DCONNEXION_NAVIGATOR_FOR_NOTEBOOKS), 2, name, c, vrpn_3DCONNEXION_VENDOR, vrpn_3DCONNEXION_NAVIGATOR_FOR_NOTEBOOKS)
356 :
vrpn_3DConnexion(new
vrpn_HidProductAcceptor(vrpn_SPACEMOUSEWIRELESS_VENDOR, vrpn_3DCONNEXION_SPACEMOUSECOMPACT), 2, name, c, vrpn_SPACEMOUSEWIRELESS_VENDOR, vrpn_3DCONNEXION_SPACEMOUSECOMPACT)
361 :
vrpn_3DConnexion(new
vrpn_HidProductAcceptor(vrpn_SPACEMOUSEWIRELESS_VENDOR, vrpn_3DCONNEXION_SPACEMOUSEWIRELESS), 2, name, c, vrpn_SPACEMOUSEWIRELESS_VENDOR, vrpn_3DCONNEXION_SPACEMOUSEWIRELESS)
383 vrpn_3DCONNEXION_SPACEPILOTPRO),
384 31, name, c, vrpn_3DCONNEXION_VENDOR,
385 vrpn_3DCONNEXION_SPACEPILOTPRO)
390 :
vrpn_3DConnexion(new
vrpn_HidProductAcceptor(vrpn_SPACEMOUSEWIRELESS_VENDOR, vrpn_3DCONNEXION_SPACEMOUSEPROWIRELESS), 32, name, c, vrpn_SPACEMOUSEWIRELESS_VENDOR, vrpn_3DCONNEXION_SPACEMOUSEPROWIRELESS)
397 if ((bytes % 13) != 0) {
401 for (
size_t i = 0; i < bytes / 13; i++) {
403 vrpn_uint8 *
report = buffer + (i * 13);
404 char report_type =
report[0];
405 vrpn_uint8 *bufptr = &
report[1];
406 const float scale = 1.0f / 350.f;
408 switch (report_type) {
412 for (
int c = 0; c < 6; c++) {
414 channel[c] = vrpn_unbuffer_from_little_endian<vrpn_int16>(bufptr) * scale;
426 vrpn_uint8 *location =
report + 1 + (btn / 8);
427 vrpn_uint8 mask = 1 << (btn % 8);
428 buttons[btn] = ((*location) & mask) != 0;
vrpn_3DConnexion_Navigator_for_Notebooks(const char *name, vrpn_Connection *c=0)
vrpn_3DConnexion_Navigator(const char *name, vrpn_Connection *c=0)
vrpn_3DConnexion_SpaceBall5000(const char *name, vrpn_Connection *c=0)
vrpn_3DConnexion_SpaceExplorer(const char *name, vrpn_Connection *c=0)
vrpn_3DConnexion_SpaceMouseCompact(const char *name, vrpn_Connection *c=0)
void decodePacket(size_t bytes, vrpn_uint8 *buffer)
vrpn_3DConnexion_SpaceMouseProWireless(const char *name, vrpn_Connection *c=0)
vrpn_3DConnexion_SpaceMousePro(const char *name, vrpn_Connection *c=0)
vrpn_3DConnexion_SpaceMouseWireless(const char *name, vrpn_Connection *c=0)
vrpn_3DConnexion_SpaceMouse(const char *name, vrpn_Connection *c=0)
vrpn_3DConnexion_SpacePilotPro(const char *name, vrpn_Connection *c=0)
vrpn_3DConnexion_SpacePilot(const char *name, vrpn_Connection *c=0)
vrpn_3DConnexion_Traveler(const char *name, vrpn_Connection *c=0)
vrpn_HidAcceptor * _filter
void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY)
struct timeval _timestamp
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
void on_data_received(size_t bytes, vrpn_uint8 *buffer)
Derived class reimplements this callback.
virtual ~vrpn_3DConnexion()
vrpn_3DConnexion(vrpn_HidAcceptor *filter, unsigned num_buttons, const char *name, vrpn_Connection *c=0, vrpn_uint16 vendor=0, vrpn_uint16 product=0)
virtual void decodePacket(size_t bytes, vrpn_uint8 *buffer)
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...
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...
int send_text_message(const char *msg, struct timeval timestamp, vrpn_TEXT_SEVERITY type=vrpn_TEXT_NORMAL, vrpn_uint32 level=0)
Sends a NULL-terminated text message from the device d_sender_id.
Generic connection class not specific to the transport mechanism.
virtual int send_pending_reports(void)=0
send pending report, clear the buffer. This function was protected, now is public,...
virtual bool accept(const vrpn_HIDDEVINFO &device)=0
virtual void update()
Polls the device buffers and causes on_data_received callbacks if appropriate You NEED to call this f...
Accepts any device with the given vendor and product IDs.
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
int vrpn_noint_select(int width, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
This routine will perform like a normal select() call, but it will restart if it quit because of an i...
int vrpn_noint_block_read(int infile, char buffer[], size_t length)
#define vrpn_gettimeofday