vrpn
07.33
Virtual Reality Peripheral Network
|
Go to the documentation of this file.
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");
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 int get_report(void)
Try to read reports from the device. Returns 1 if a complete report received, 0 otherwise....
vrpn_Serial: Pulls all the serial port routines into one file to make porting to new operating system...
int escapedchar
We're processing an escaped char.
int vrpn_flush_input_buffer(int comm)
Throw out any characters within the input buffer.
int _numbuttons
How many buttons to open.
struct timeval timestamp
Time of the last report from the device.
virtual int reset(void)
Set device back to starting config.
int spaceball4000
We found a Spaceball 4000.
vrpn_Spaceball(const char *name, vrpn_Connection *c, const char *port, int baud)
int vrpn_write_slowly(int comm, const unsigned char *buffer, size_t bytes, int millisec_delay)
int erroroccured
A device error has occurred.
int _numchannels
How many analog channels to open.
int bufpos
Current char pos in buffer.
virtual void report(vrpn_uint32 class_of_service=vrpn_CONNECTION_LOW_LATENCY)
send report whether or not changed
int leftymode4000
Spaceball 4000 is in lefty mode.
Generic connection class not specific to the transport mechanism.
virtual void clear_values(void)
Set all buttons, analogs and encoders back to 0.
#define vrpn_gettimeofday
virtual void mainloop()
Called once through each main loop iteration to handle updates.
int vrpn_read_available_characters(int comm, unsigned char *buffer, size_t bytes)
int packlen
Expected packet length.
vrpn_float64 last[vrpn_CHANNEL_MAX]
unsigned char buf[512]
Buffer of characters in report,.
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 null_radius
range where no motion should be reported
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
int packtype
What kind of packet we are decoding.
int resetoccured
A reset event has occurred.