87#define STATUS_RESETTING (-1)
88#define STATUS_SYNCING (0)
89#define STATUS_READING (1)
90#define MAX_TIME_INTERVAL (2000000)
95 const char * port,
int baud):
144 const char *reset_str =
"CB\rNT\rFTp\rFRp\rP@r@r\rMSSV\rZ\rBcCcC\r";
187 unsigned char rawbuf[1024];
200 for (i=0; i<num; i++) {
202 if (rawbuf[i] ==
'^') {
225 printf(
"\nGot a bad escape sequence! 0x%02x", rawbuf[i]);
226 if (isprint(rawbuf[i]))
227 printf(
" (%c)", rawbuf[i]);
229 printf(
" (unprintable)");
311 printf(
"\nUnknown packet (1) [%d]: 0x%02x \n ", i, rawbuf[i]);
313 if (isprint(rawbuf[i]))
314 printf(
"%c", rawbuf[i]);
316 printf(
" (unprintable)");
329 if (rawbuf[i] !=
'\r')
337 if (rawbuf[i] !=
'\r')
359 intval = (
buf[nextchar++]) << 8;
360 intval |= (
buf[nextchar++]);
372 double realval = intval / 32768.0;
416 buttons[0] =
static_cast<unsigned char>(((
buf[2] & 0x01) != 0) | ((
buf[2] & 0x10) != 0));
417 buttons[1] =
static_cast<unsigned char>(((
buf[2] & 0x02) != 0) | ((
buf[2] & 0x20) != 0));
418 buttons[2] =
static_cast<unsigned char>(((
buf[2] & 0x04) != 0));
419 buttons[3] =
static_cast<unsigned char>(((
buf[2] & 0x08) != 0));
422 buttons[4] =
static_cast<unsigned char>(((
buf[1] & 0x01) != 0));
423 buttons[5] =
static_cast<unsigned char>(((
buf[1] & 0x02) != 0));
424 buttons[6] =
static_cast<unsigned char>(((
buf[1] & 0x04) != 0));
431 buttons[7] =
static_cast<unsigned char>(((
buf[1] & 0x20) != 0) | ((
buf[1] & 0x08) != 0));
436 buttons[8] =
static_cast<unsigned char>(((
buf[1] & 0x10) != 0));
446 if (
buf[3] !=
'\r') {
453 printf(
"\nDetected a Spaceball 4000 FLX\n");
486 printf(
"\nSpaceball 4000 mode changed to: %s\n",
487 (((
buf[1] & 0x20) == 0) ?
"left handed" :
"right handed"));
490 if ((
buf[1] & 0x20) == 0)
508 printf(
"Spaceball reset: ");
511 printf(
"%c",
buf[j]);
526 printf(
"\nSpaceball Error!! ");
527 printf(
"Error code: ");
529 printf(
" 0x%02x ",
buf[j]);
541 printf(
"Unknown packet (2): 0x%02x\n",
packtype);
546 printf(
" (unprintable)");
605 fprintf(stderr,
"vrpn_Spaceball: Unknown mode (internal error)\n");
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...
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
Generic connection class not specific to the transport mechanism.
int packtype
What kind of packet we are decoding.
vrpn_Spaceball(const char *name, vrpn_Connection *c, const char *port, int baud)
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY)
send report whether or not changed
int packlen
Expected packet length.
int spaceball4000
We found a Spaceball 4000.
virtual void mainloop()
Called once through each main loop iteration to handle updates.
virtual int get_report(void)
Try to read reports from the device. Returns 1 if a complete report received, 0 otherwise....
virtual int reset(void)
Set device back to starting config.
int _numchannels
How many analog channels to open.
unsigned char buf[512]
Buffer of characters in report,.
int leftymode4000
Spaceball 4000 is in lefty mode.
int resetoccured
A reset event has occurred.
int bufpos
Current char pos in buffer.
int escapedchar
We're processing an escaped char.
int _numbuttons
How many buttons to open.
virtual void clear_values(void)
Set all buttons, analogs and encoders back to 0.
int null_radius
range where no motion should be reported
struct timeval timestamp
Time of the last report from the device.
int erroroccured
A device error has occurred.
int vrpn_write_slowly(int comm, const unsigned char *buffer, size_t bytes, int millisec_delay)
int vrpn_flush_input_buffer(int comm)
Throw out any characters within the input buffer.
int vrpn_read_available_characters(int comm, unsigned char *buffer, size_t bytes)
vrpn_Serial: Pulls all the serial port routines into one file to make porting to new operating system...
#define vrpn_gettimeofday