vrpn
07.33
Virtual Reality Peripheral Network
|
Go to the documentation of this file.
15 static const vrpn_float64 JoyScale[] = {1019, 200, 200, 350, 200, 200, 350};
19 vrpn_float64 update_rate):
25 if (update_rate != 0) {
26 MAX_TIME_INTERVAL = (long)(1000000/update_rate);
28 MAX_TIME_INTERVAL = -1;
50 fprintf(stderr,
"UNC Joystick: Cannot pack message, tossing\n");
53 fprintf(stderr,
"UNC Joystick: No valid Connection\n");
58 struct timeval current_time;
102 int write_rt, bytesread;
104 fprintf(stderr,
"Going into vrpn_Joystick::reset()\n");
111 fprintf(stderr,
"vrpn_Joystick::reset: write failed\n");
121 if (bytesread != 16) {
122 fprintf(stderr,
"vrpn_Joystick::reset: got only %d char from \
123 joystick, should be 16, trying again\n", bytesread);
151 if (bytesread == -1) {
152 perror(
"vrpn_Joystick::get_report() 1st read failed");
155 if (bytesread == 1) {
156 if ((serialbuf[0] >> 7) == 0) {
159 fprintf(stderr,
"vrpn_Joystick::get_report(): Bad 1st byte (re-syncing)\n");
168 if (bytesread == -1) {
169 perror(
"vrpn_Joystick::get_report() 2nd read failed");
172 if (bytesread == 0) {
181 if ( (serialbuf[1] >> 7) == 0 ) {
182 serialbuf[0] = serialbuf[1];
207 static const unsigned int mask1 = 7, mask2 = 127, left = 1, right = 2;
214 chan = serialbuf[index] >> 3;
219 fprintf(stderr,
"vrpn_Joystick::parse(): Invalid channel (%d)\n",chan);
231 buttons[0] =
static_cast<unsigned char>(!(serialbuf[index+1] & left)?1:0);
232 buttons[1] =
static_cast<unsigned char>(!(serialbuf[index+1] & right)?1:0);
234 printf(
"Joystick::parse: Buttons: %d %d\n",
245 temp = serialbuf[index] & mask1;
247 value = (serialbuf[index+1] & mask2) | temp;
252 if (reset_rest_pos) {
256 restval[chan]= value;
263 channel[chan] = (restval[chan] - value)/JoyScale[chan];
272 printf(
"Joystick::parse: channel[%d] = %f\n", chan,
channel[chan]);
virtual vrpn_int32 encode_to(char *buf)
unsigned long vrpn_TimevalDuration(struct timeval endT, struct timeval startT)
Return number of microseconds between startT and endT.
vrpn_float64 channel[vrpn_CHANNEL_MAX]
const int vrpn_ANALOG_SYNCING
const int vrpn_ANALOG_FAIL
void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
void parse(int, int reset_rest_pos=0)
vrpn_Serial: Pulls all the serial port routines into one file to make porting to new operating system...
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
vrpn_Connection * d_connection
Connection that this object talks to.
void vrpn_SleepMsecs(double dMsecs)
const int vrpn_ANALOG_RESETTING
vrpn_int32 d_sender_id
Sender ID registered with the connection.
Generic connection class not specific to the transport mechanism.
#define MAX_TIME_INTERVAL
#define vrpn_gettimeofday
int vrpn_read_available_characters(int comm, unsigned char *buffer, size_t bytes)
vrpn_Joystick(char *name, vrpn_Connection *c, char *portname, int baud, double)
void report(struct timeval current_time)
const int vrpn_ANALOG_PARTIAL
int vrpn_write_characters(int comm, const unsigned char *buffer, size_t bytes)
Write the buffer to the serial port.
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...