87 #define STATUS_RESETTING (-1) // Resetting the device 88 #define STATUS_SYNCING (0) // Looking for the first char of report 89 #define STATUS_READING (1) // Looking for the rest of the report 90 #define MAX_TIME_INTERVAL (2000000) // max time between reports (usec) 95 const char * port,
int baud):
135 const char *reset_str =
"CB\rNT\rFTp\rFRp\rP@r@r\rMSSV\rZ\rBcCcC\r";
178 unsigned char rawbuf[1024];
191 for (i=0; i<num; i++) {
193 if (rawbuf[i] ==
'^') {
216 printf(
"\nGot a bad escape sequence! 0x%02x", rawbuf[i]);
217 if (isprint(rawbuf[i]))
218 printf(
" (%c)", rawbuf[i]);
220 printf(
" (unprintable)");
302 printf(
"\nUnknown packet (1) [%d]: 0x%02x \n ", i, rawbuf[i]);
304 if (isprint(rawbuf[i]))
305 printf(
"%c", rawbuf[i]);
307 printf(
" (unprintable)");
320 if (rawbuf[i] !=
'\r')
328 if (rawbuf[i] !=
'\r')
350 intval = (
buf[nextchar++]) << 8;
351 intval |= (
buf[nextchar++]);
352 intval = (intval << 16) >> 16;
364 double realval = intval / 32768.0;
408 buttons[0] = static_cast<unsigned char>(((
buf[2] & 0x01) != 0) | ((
buf[2] & 0x10) != 0));
409 buttons[1] = static_cast<unsigned char>(((
buf[2] & 0x02) != 0) | ((
buf[2] & 0x20) != 0));
410 buttons[2] = static_cast<unsigned char>(((
buf[2] & 0x04) != 0));
411 buttons[3] = static_cast<unsigned char>(((
buf[2] & 0x08) != 0));
414 buttons[4] = static_cast<unsigned char>(((
buf[1] & 0x01) != 0));
415 buttons[5] = static_cast<unsigned char>(((
buf[1] & 0x02) != 0));
416 buttons[6] = static_cast<unsigned char>(((
buf[1] & 0x04) != 0));
423 buttons[7] = static_cast<unsigned char>(((
buf[1] & 0x20) != 0) | ((
buf[1] & 0x08) != 0));
428 buttons[8] = static_cast<unsigned char>(((
buf[1] & 0x10) != 0));
438 if (
buf[3] !=
'\r') {
445 printf(
"\nDetected a Spaceball 4000 FLX\n");
478 printf(
"\nSpaceball 4000 mode changed to: %s\n",
479 (((
buf[1] & 0x20) == 0) ?
"left handed" :
"right handed"));
482 if ((
buf[1] & 0x20) == 0)
500 printf(
"Spaceball reset: ");
503 printf(
"%c",
buf[j]);
518 printf(
"\nSpaceball Error!! ");
519 printf(
"Error code: ");
521 printf(
" 0x%02x ",
buf[j]);
533 printf(
"Unknown packet (2): 0x%02x\n",
packtype);
538 printf(
" (unprintable)");
597 fprintf(stderr,
"vrpn_Spaceball: Unknown mode (internal error)\n");
virtual int reset(void)
Set device back to starting config.
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...
int erroroccured
A device error has occurred.
int escapedchar
We're processing an escaped char.
int packtype
What kind of packet we are decoding.
int vrpn_flush_input_buffer(int comm)
Throw out any characters within the input buffer.
vrpn_Spaceball(const char *name, vrpn_Connection *c, const char *port, int baud)
vrpn_Serial: Pulls all the serial port routines into one file to make porting to new operating system...
struct timeval timestamp
Time of the last report from the device.
vrpn_float64 channel[vrpn_CHANNEL_MAX]
int _numchannels
How many analog channels to open.
int null_radius
range where no motion should be reported
Generic connection class not specific to the transport mechanism.
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 mainloop()
Called once through each main loop iteration to handle updates.
int vrpn_write_slowly(int comm, const unsigned char *buffer, size_t bytes, int millisec_delay)
int vrpn_read_available_characters(int comm, unsigned char *buffer, size_t bytes)
unsigned char buf[512]
Buffer of characters in report,.
int bufpos
Current char pos in buffer.
int _numbuttons
How many buttons to open.
int resetoccured
A reset event has occurred.
virtual void clear_values(void)
Set all buttons, analogs and encoders back to 0.
#define vrpn_gettimeofday
int spaceball4000
We found a Spaceball 4000.
int leftymode4000
Spaceball 4000 is in lefty mode.
virtual int get_report(void)
Try to read reports from the device. Returns 1 if a complete report received, 0 otherwise....
int packlen
Expected packet length.
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY)
send report whether or not changed
vrpn_float64 last[vrpn_CHANNEL_MAX]