13 #ifdef VRPN_USE_JOYLIN 15 #define NAME_LENGTH 128 20 #include <sys/select.h> 24 #include <sys/ioctl.h> 30 #include <linux/joystick.h> 42 devname = (
char *) calloc(namelen,
sizeof(
char));
43 if (devname == NULL) {
44 fprintf(stderr,
"vrpn_Joylin::vrpn_Joylin(): Out of memory\n");
48 device = strdup(portname);
54 if (devname != NULL) {
65 if ((fd = open(device, O_RDONLY)) < 0) {
66 fprintf(stderr,
"vrpn_Joylin constructor could not open %s", device);
67 perror(
" joystick device");
71 ioctl(fd, JSIOCGVERSION, &version);
74 ioctl(fd, JSIOCGNAME(namelen), devname);
77 printf(
"Joystick (%s) has %d axes and %d buttons. Driver version is %d.%d.%d.\n",
86 struct timeval zerotime;
97 if (fd < 0) {
return; }
101 got_response =
false;
104 select(fd+1, &fdset, NULL, NULL, &zerotime);
106 if (FD_ISSET(fd, &fdset)){
107 if (read(fd, &js,
sizeof(
struct js_event)) !=
sizeof(
struct js_event)) {
120 switch(js.type & ~JS_EVENT_INIT) {
121 case JS_EVENT_BUTTON:
127 channel[js.number] = js.value / 32767.0;
135 printf(
"%2d:%.3f ", i,
channel[i]);
141 printf(
"%2d:%s ", i,
buttons[i] ?
"on " :
"off");
151 }
while (got_response);
161 fprintf(stderr,
"vrpn_Joylin::vrpn_Joylin: Can't open Linux joystick on non-Linux machine\n");
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...
void vrpn_SleepMsecs(double dMsecs)
vrpn_float64 channel[vrpn_CHANNEL_MAX]
virtual int send_pending_reports(void)=0
send pending report, clear the buffer. This function was protected, now is public,...
vrpn_Joylin(char *name, vrpn_Connection *c, char *portname)
Generic connection class not specific to the transport mechanism.
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
virtual int init(void)
Initialize things that the constructor can't. Returns 0 on success, -1 on failure.
vrpn_Connection * d_connection
Connection that this object talks to.
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.
#define vrpn_gettimeofday
void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...