15#define NAME_LENGTH 128
20#include <sys/select.h>
30#include <linux/joystick.h>
34 const char *portname):
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);
70 if ((fd = open(device, O_RDONLY)) < 0) {
71 fprintf(stderr,
"vrpn_Joylin constructor could not open %s", device);
72 perror(
" joystick device");
76 ioctl(fd, JSIOCGVERSION, &version);
79 ioctl(fd, JSIOCGNAME(namelen), devname);
82 printf(
"Joystick (%s) has %d axes and %d buttons. Driver version is %d.%d.%d.\n",
91 struct timeval zerotime;
101 if (fd < 0) {
return; }
105 got_response =
false;
108 select(fd+1, &fdset, NULL, NULL, &zerotime);
110 if (FD_ISSET(fd, &fdset)){
111 if (read(fd, &js,
sizeof(
struct js_event)) !=
sizeof(
struct js_event)) {
124 switch(js.type & ~JS_EVENT_INIT) {
125 case JS_EVENT_BUTTON:
131 channel[js.number] = js.value / 32767.0;
139 printf(
"%2d:%.3f ", i,
channel[i]);
145 printf(
"%2d:%s ", i,
buttons[i] ?
"on " :
"off");
155 }
while (got_response);
165 fprintf(stderr,
"vrpn_Joylin::vrpn_Joylin: Can't open Linux joystick on non-Linux machine\n");
vrpn_float64 channel[vrpn_CHANNEL_MAX]
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.
virtual int init(void)
Initialize things that the constructor can't. Returns 0 on success, -1 on failure.
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,...
void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_Joylin(const char *name, vrpn_Connection *c, const char *portname)
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
void vrpn_SleepMsecs(double dMilliSecs)
#define vrpn_gettimeofday