Exemple #1
0
vrpn_Nikon_Controls::vrpn_Nikon_Controls(const char *device_name, vrpn_Connection *con, const char *port_name)
: vrpn_Serial_Analog(device_name, con, port_name), 
  vrpn_Analog_Output(device_name, con)
{
  num_channel = 1;	// Focus control
  o_num_channel = 1;	// Focus control

  // Set the mode to reset
  _status = STATUS_RESETTING;

  // Register to receive the message to request changes and to receive connection
  // messages.
  if (d_connection != NULL) {
    if (register_autodeleted_handler(request_m_id, handle_request_message,
      this, d_sender_id)) {
	  fprintf(stderr,"vrpn_Nikon_Controls: can't register handler\n");
	  d_connection = NULL;
    }
    if (register_autodeleted_handler(request_channels_m_id, handle_request_channels_message,
      this, d_sender_id)) {
	  fprintf(stderr,"vrpn_Nikon_Controls: can't register handler\n");
	  d_connection = NULL;
    }
    if (register_autodeleted_handler(d_ping_message_id, handle_connect_message,
      this, d_sender_id)) {
	  fprintf(stderr,"vrpn_Nikon_Controls: can't register handler\n");
	  d_connection = NULL;
    }
  } else {
	  fprintf(stderr,"vrpn_Nikon_Controls: Can't get connection!\n");
  }    
}
Exemple #2
0
vrpn_XInputGamepad::vrpn_XInputGamepad(const char *name, vrpn_Connection *c, unsigned int controllerIndex):
	vrpn_Analog(name, c),
	vrpn_Button(name, c),
	vrpn_Analog_Output(name, c),
	_controllerIndex(controllerIndex)
{
	vrpn_Analog::num_channel = 7;
	vrpn_Button::num_buttons = 10;
	vrpn_Analog_Output::o_num_channel = 2;

	_motorSpeed[0] = 0;
	_motorSpeed[1] = 0;

	if (register_autodeleted_handler(request_m_id,
	 handle_request_message, this, d_sender_id)) {
		fprintf(stderr, "vrpn_XInputGamepad: Can't register request-single handler\n");
		return;
	}

	if (register_autodeleted_handler(request_channels_m_id,
	 handle_request_channels_message, this, d_sender_id)) {
		fprintf(stderr, "vrpn_XInputGamepad: Can't register request-multiple handler\n");
		return;
	}

	if (register_autodeleted_handler(
	 d_connection->register_message_type(vrpn_dropped_last_connection),
	 handle_last_connection_dropped, this)) {
		fprintf(stderr, "vrpn_XInputGamepad: Can't register connections-dropped handler\n");
		return;
	}
}
Exemple #3
0
vrpn_Button_Filter::vrpn_Button_Filter(const char *name, vrpn_Connection *c)
    : vrpn_Button(name, c)
{
    if ((d_sender_id == -1) || (admin_message_id == -1)) {
        fprintf(stderr, "vrpn_Button: Can't register IDs\n");
        d_connection = NULL;
    }
    register_autodeleted_handler(admin_message_id, client_msg_handler, this);

    // setup message id type for alert messages to alert a device about changes
    alert_message_id = d_connection->register_message_type("vrpn_Button Alert");
    send_alerts = 0; // used to turn on/off alerts -- send and admin message
                     // from
    // remote to turn it on -- or server side call set_alerts();

    // Set up callback handler for ping message from client so that it
    // sends the button states.  This will make sure that the other side hears
    // the initial button states.  Also set this up
    // to fire on the "new connection" system message.

    register_autodeleted_handler(d_ping_message_id, handle_ping_message, this,
                                 d_sender_id);
    register_autodeleted_handler(
        d_connection->register_message_type(vrpn_got_connection),
        handle_ping_message, this, vrpn_ANY_SENDER);

    // set button default buttonstates
    for (vrpn_int32 i = 0; i < vrpn_BUTTON_MAX_BUTTONS; i++) {
        buttonstate[i] = vrpn_BUTTON_MOMENTARY;
    }
    return;
}
Exemple #4
0
vrpn_Analog_Output_Server::vrpn_Analog_Output_Server(const char* name, vrpn_Connection * c, 
                                                     vrpn_int32 numChannels) :
	vrpn_Analog_Output(name, c)
{
	this->setNumChannels( numChannels );
	
	// Check if we have a connection
	if (d_connection == NULL) {
		fprintf(stderr, "vrpn_Analog_Output: Can't get connection!\n");
	}
	
	// Register a handler for the request channel change message
	if (register_autodeleted_handler(request_m_id,
		handle_request_message, this, d_sender_id)) {
		fprintf(stderr,"vrpn_Analog_Output_Server: can't register change channel request handler\n");
		d_connection = NULL;
	}
	
	// Register a handler for the request channels change message
	if (register_autodeleted_handler(request_channels_m_id,
		handle_request_channels_message, this, d_sender_id)) {
		fprintf(stderr,"vrpn_Analog_Output_Server: can't register change channels request handler\n");
		d_connection = NULL;
	}

	// Register a handler for vrpn_got_connection, so we can tell the
	// client how many channels are active
	if( register_autodeleted_handler( got_connection_m_id, handle_got_connection, this ) ) {
		fprintf( stderr, "vrpn_Analog_Output_Server: can't register new connection handler\n");
		d_connection = NULL;
	}	
}
Exemple #5
0
vrpn_SGIBox::vrpn_SGIBox(char * name, vrpn_Connection * c):
  vrpn_Analog(name, c), vrpn_Button_Filter(name, c) {
    int ret;
    char hn[128];
    sid  = -1;
    winid =  -1;

    if (winid != -1) {
      printf("Closing previous windows Winid=%d, sid = %d:\n",winid, sid);
      winclose(winid);
      //dglclose(sid);
      dglclose(-1); // close all dgl connection;
    }

    ret = gethostname(hn, 100);
    if (ret < 0) {
      fprintf(stderr, "vrpn_SGIBox: error in gethostname()\n");
      return;
    }
    sid = ret = dglopen(hn,DGLLOCAL);
    if (ret < 0) {
      fprintf(stderr, "vrpn_SGIBox: error in dglopen()\n");
      return;
    }
    noport();
    winid = winopen("");
    reset();
    num_channel = NUM_DIALS;
    num_buttons = NUM_BUTTONS;
    
    register_autodeleted_handler(c->register_message_type( vrpn_got_first_connection), sgibox_con_cb, this);
    register_autodeleted_handler(alert_message_id,sgibox_alert_handler, this);
    set_alerts(1);	//turn on alerts from toggle filter class to notify
			//local sgibox that lights should be turned on/off
}
Exemple #6
0
void	vrpn_BaseClassUnique::client_mainloop(void)
{
    struct  timeval now;
    struct  timeval diff;

    // The first time through, set up a callback handler for the pong message so that we
    // know when we are getting them.  Also set up a handler for the system dropped-connection
    // message so that we can initiate a ping cycle when that happens.  Also, we'll initiate
    // the ping cycle here.

    if (d_first_mainloop && (d_connection != NULL)) {

	// Set up handlers for the pong message and for the system connection-drop message
	register_autodeleted_handler(d_pong_message_id, handle_pong, this, d_sender_id);
	register_autodeleted_handler(d_connection->register_message_type(vrpn_dropped_connection),
	    handle_connection_dropped, this);

	// Initiate a ping cycle;
	initiate_ping_cycle();

	// No longer first time through mainloop.
	d_first_mainloop = 0;
    }

    // If we are in the middle of a ping cycle...
    // Check if we've heard, if it has been long enough since we gave a warning or error (>= 1 sec).
    // If it has been three seconds or more since we sent our first ping,
    // start giving warnings.  If it has been ten seconds or more since we got one,
    // switch to errors.  New ping requests go out each second.

    if (d_unanswered_ping) {
    
        vrpn_gettimeofday(&now, NULL);
        diff = vrpn_TimevalDiff(now, d_time_last_warned);
        vrpn_TimevalNormalize(diff);
        
        if (diff.tv_sec >= 1) {
            
            // Send a new ping, since it has been a second since the last one
            d_connection->pack_message(0, now, d_ping_message_id, d_sender_id,
                                       NULL, vrpn_CONNECTION_RELIABLE);
            
            // Send another warning or error, and say if we're flatlined (10+ seconds)
            d_time_last_warned = now;
            if (!shutup) {
                diff = vrpn_TimevalDiff(now, d_time_first_ping);
                vrpn_TimevalNormalize(diff);	    
                if (diff.tv_sec >= 10) {
                    send_text_message("No response from server for >= 10 seconds", now, vrpn_TEXT_ERROR, diff.tv_sec);
                    d_flatline = 1;
                } else if (diff.tv_sec >= 3) {
                    send_text_message("No response from server for >= 3 seconds", now, vrpn_TEXT_WARNING, diff.tv_sec);
                }
            }
        }
    }
}
void vrpn_Xkeys::init_hid() {
	// Get notifications when clients connect and disconnect
	register_autodeleted_handler(d_connection->register_message_type(vrpn_dropped_last_connection), on_last_disconnect, this);
	register_autodeleted_handler(d_connection->register_message_type(vrpn_got_connection), on_connect, this);

	// Indicate we're waiting for a connection by turning on the red LED
	vrpn_uint8 outputs[9] = {0};
	outputs[8] = 128;
	send_data(9, outputs);
}
vrpn_RedundantController::vrpn_RedundantController(
    vrpn_RedundantTransmission *r, vrpn_Connection *c)
    : vrpn_BaseClass("vrpn Redundant Transmission Controller", c)
    , d_object(r)
{

    vrpn_BaseClass::init();

    // fprintf(stderr, "Registering set handler with type %d.\n",
    // d_protocol.d_set_type);

    register_autodeleted_handler(d_protocol.d_set_type, handle_set, this);
    register_autodeleted_handler(d_protocol.d_enable_type, handle_enable, this);
}
Exemple #9
0
vrpn_OmegaTemperature::vrpn_OmegaTemperature (const char * name, vrpn_Connection * c,
			const char * port, float temp1, float temp2, bool control_on):
	vrpn_Serial_Analog(name, c, port, 115200, 8, vrpn_SER_PARITY_NONE, true),
    vrpn_Analog_Output(name, c),
    vrpn_Button_Filter(name, c)
{
  // XXX Make this configurable?
  int baud = 38400;
  char parity = 'n';  // XXX What should this be?
  int stop_bits = 1;
  d_modbus = modbus_new_rtu(port, baud, parity, 8, stop_bits);
  // XXX No code below has been changed yet.

  num_channel = 6;
  o_num_channel = 3;
  num_buttons = 1;
  buttons[0] = control_on;

  // Fill in the arguments to send to the device at reset time.
  o_channel[0] = temp1;
  o_channel[1] = temp2;
  o_channel[2] = control_on;

  // Set the mode to reset
  status = STATUS_RESETTING;

  // Register to receive the message to request changes and to receive connection
  // messages.
  if (d_connection != NULL) {
    if (register_autodeleted_handler(request_m_id, handle_request_message,
      this, d_sender_id)) {
	  fprintf(stderr,"vrpn_OmegaTemperature: can't register handler\n");
	  d_connection = NULL;
    }
    if (register_autodeleted_handler(request_channels_m_id, handle_request_channels_message,
      this, d_sender_id)) {
	  fprintf(stderr,"vrpn_OmegaTemperature: can't register handler\n");
	  d_connection = NULL;
    }
    if (register_autodeleted_handler(d_ping_message_id, handle_connect_message,
      this, d_sender_id)) {
	  fprintf(stderr,"vrpn_OmegaTemperature: can't register handler\n");
	  d_connection = NULL;
    }
  } else {
	  fprintf(stderr,"vrpn_OmegaTemperature: Can't get connection!\n");
  }

}
Exemple #10
0
vrpn_Analog_Remote::vrpn_Analog_Remote (const char * name,
                                        vrpn_Connection * c ) : 
	vrpn_Analog (name, c)
{
	vrpn_int32	i;

	// Register a handler for the change callback from this device,
	// if we got a connection.
	if (d_connection != NULL) {
	  if (register_autodeleted_handler(channel_m_id, handle_change_message,
	    this, d_sender_id)) {
		fprintf(stderr,"vrpn_Analog_Remote: can't register handler\n");
		d_connection = NULL;
	  }
	} else {
		fprintf(stderr,"vrpn_Analog_Remote: Can't get connection!\n");
	}

	// At the start, as far as the client knows, the device could have
	// max channels -- the number of channels is specified in each
	// message.
	num_channel=vrpn_CHANNEL_MAX;
	for (i = 0; i < vrpn_CHANNEL_MAX; i++) {
		channel[i] = last[i] = 0;
	}
	vrpn_gettimeofday(&timestamp, NULL);
}
VRPN_AciCommand_transport_remote::VRPN_AciCommand_transport_remote(
        const char *name, vrpn_Connection *c)
  : VRPN_AciCommand_transport_base(name, c)
{
  // Register a handler for the image-response message.
  register_autodeleted_handler(d_command_response_m_id, handle_response_message, this, d_sender_id);
}
VRPN_AciCommand_transport_server::VRPN_AciCommand_transport_server(
        const char *name, vrpn_Connection *c)
  : VRPN_AciCommand_transport_base(name, c)
{
  // Register a handler for the command message.
  register_autodeleted_handler(d_command_send_m_id, handle_command_message, this, d_sender_id);
}
Exemple #13
0
vrpn_Text_Receiver::vrpn_Text_Receiver (const char * name,
                                        vrpn_Connection * c) :
    vrpn_BaseClass(name, c)
{
  init();
  if (d_connection) {
    register_autodeleted_handler(d_text_message_id, handle_message, this, d_sender_id);
  }
};
Exemple #14
0
void	vrpn_BaseClassUnique::server_mainloop(void)
{
    // Set up to handle pong message.  This should be sent whenever there is
    // a ping request from a client.

    if (d_first_mainloop && (d_connection != NULL)) {
	register_autodeleted_handler(d_ping_message_id, handle_ping, this, d_sender_id);
	d_first_mainloop = 0;
    }
}
vrpn_Tracker_PhaseSpace::vrpn_Tracker_PhaseSpace(const char *name, vrpn_Connection *c, const char* device, float frequency,int readflag, int slave)
  : vrpn_Tracker(name,c)
{
#ifdef DEBUG
  printf("%s %s %s %f %d\n", __PRETTY_FUNCTION__, name, device, frequency, readflag);
#endif

  if(d_connection) {
    // Register a handler for the update change callback
    if (register_autodeleted_handler(update_rate_id, handle_update_rate_request, this, d_sender_id))
      fprintf(stderr,"vrpn_Tracker: Can't register workspace handler\n");
  }

  this->slave = slave;
  this->frequency = frequency;

  numRigids = 0;
  numMarkers = 0;
  markers.reserve(VRPN_PHASESPACE_MAXMARKERS);
  rigids.reserve(VRPN_PHASESPACE_MAXRIGIDS);

  int owlflag = 0;
  if(slave) owlflag |= OWL_SLAVE;

  int ret = owlInit(device,owlflag);
  if(ret != owlflag) {
    fprintf(stderr, "owlInit error: 0x%x\n", ret);
    owlRunning = false;
    return;
  } else {
    owlRunning = true;
  }

  char msg[512];
  if(owlGetString(OWL_VERSION,msg)) {
    printf("OWL version: %s\n",msg);
  } else {
    printf("Unable to query OWL version.\n");
  }

  if(!slave) {
    //The master point tracker is index 0.  So all rigid trackers will start from 1.
    owlTrackeri(0, OWL_CREATE, OWL_POINT_TRACKER);
    if(!owlGetStatus()) {
      fprintf(stderr,"Error: Unable to create main point tracker.\n");
      return;
    }
  } else {
    printf("Ignoring tracker creation in slave mode.\n");
  }

  readMostRecent = readflag ? true : false;
  frame = 0;
}
Exemple #16
0
vrpn_BiosciencesTools::vrpn_BiosciencesTools (const char * name, vrpn_Connection * c,
			const char * port, float temp1, float temp2, bool control_on):
	vrpn_Serial_Analog(name, c, port, 115200),
        vrpn_Analog_Output(name, c),
        vrpn_Button_Filter(name, c)
{
  num_channel = 6;
  o_num_channel = 3;
  num_buttons = 1;

  // Fill in the arguments to send to the device at reset time.
  o_channel[0] = temp1;
  o_channel[1] = temp2;
  o_channel[2] = control_on;

  // Set the mode to reset
  status = STATUS_RESETTING;

  // Register to receive the message to request changes and to receive connection
  // messages.
  if (d_connection != NULL) {
    if (register_autodeleted_handler(request_m_id, handle_request_message,
      this, d_sender_id)) {
	  fprintf(stderr,"vrpn_BiosciencesTools: can't register handler\n");
	  d_connection = NULL;
    }
    if (register_autodeleted_handler(request_channels_m_id, handle_request_channels_message,
      this, d_sender_id)) {
	  fprintf(stderr,"vrpn_BiosciencesTools: can't register handler\n");
	  d_connection = NULL;
    }
    if (register_autodeleted_handler(d_ping_message_id, handle_connect_message,
      this, d_sender_id)) {
	  fprintf(stderr,"vrpn_BiosciencesTools: can't register handler\n");
	  d_connection = NULL;
    }
  } else {
	  fprintf(stderr,"vrpn_BiosciencesTools: Can't get connection!\n");
  }

}
Exemple #17
0
vrpn_Poser_Server::vrpn_Poser_Server (const char* name, vrpn_Connection * c) :
    vrpn_Poser(name, c)
{
//	register_server_handlers();

    // Make sure that we have a valid connection
    if (d_connection == NULL) {
		fprintf(stderr,"vrpn_Poser_Server: No connection\n");
		return;
	}

    // Register a handler for the position change callback for this device
 	if (register_autodeleted_handler(req_position_m_id,
			handle_change_message, this, d_sender_id)) {
		fprintf(stderr,"vrpn_Poser_Server: can't register position handler\n");
		d_connection = NULL;
	}

    // Register a handler for the relative position change callback for this device
 	if (register_autodeleted_handler(req_position_relative_m_id,
			handle_relative_change_message, this, d_sender_id)) {
		fprintf(stderr,"vrpn_Poser_Server: can't register relative position handler\n");
		d_connection = NULL;
	}

    // Register a handler for the velocity change callback for this device
    if (register_autodeleted_handler(req_velocity_m_id,
			handle_vel_change_message, this, d_sender_id)) {
		fprintf(stderr,"vrpn_Poser_Server: can't register velocity handler\n");
		d_connection = NULL;
	}

    // Register a handler for the relative velocity change callback for this device
    if (register_autodeleted_handler(req_velocity_relative_m_id,
			handle_relative_vel_change_message, this, d_sender_id)) {
		fprintf(stderr,"vrpn_Poser_Server: can't register velocity handler\n");
		d_connection = NULL;
	}
}
/// custom contructor for falcon device tracker. handles a single device.
vrpn_Tracker_NovintFalcon::vrpn_Tracker_NovintFalcon(const char *name,
        vrpn_Connection *c,
        const int devidx,
        const char *grip,
        const char *kine,
        const char *damp)
    : vrpn_Tracker(name, c), vrpn_Button_Filter(name, c),
      vrpn_ForceDevice(name, c), m_dev(NULL), m_obj(NULL), m_update_rate(1000.0), m_damp(0.9)
{
    m_devflags=vrpn_NovintFalcon_Device::MASK_DEVICEIDX & devidx;
    if (grip != NULL) {
        if (0 == strcmp(grip,"4-button")) {
            m_devflags |= vrpn_NovintFalcon_Device::GRIP_FOURBUTTON;
            vrpn_Button::num_buttons = 4;
        } else {
            fprintf(stderr, "WARNING: Unknown grip for Novint Falcon #%d: %s \n", devidx, grip);
            m_devflags = -1;
            return;
        }
    }

    if (kine != NULL) {
        if (0 == strcmp(kine,"stamper")) {
            m_devflags |= vrpn_NovintFalcon_Device::KINE_STAMPER;
        } else {
            fprintf(stderr, "WARNING: Unknown kinematic model for Novint Falcon #%d: %s \n", devidx, kine);
            m_devflags = -1;
            return;
        }
    }

    if (damp != NULL) {
        vrpn_float64 val= atof(damp);
        if (val >= 1.0 && val <= 10000.0) {
            m_damp = 1.0 - 1.0/val;
        } else {
            fprintf(stderr, "WARNING: Ignoring illegal force effect damping factor: %g \n", val);
        }
    }
    clear_values();

    if (register_autodeleted_handler(forcefield_message_id,
                                     handle_forcefield_change_message, this, vrpn_ForceDevice::d_sender_id)) {
        fprintf(stderr,"vrpn_Tracker_NovintFalcon:can't register force handler\n");
        return;
    }
    vrpn_gettimeofday(&m_timestamp, NULL);
    status = vrpn_TRACKER_RESETTING;
}
Exemple #19
0
vrpn_Analog_Output_Callback_Server::vrpn_Analog_Output_Callback_Server(const char* name, vrpn_Connection * c, 
                                                     vrpn_int32 numChannels) :
	vrpn_Analog_Output_Server(name, c, numChannels)
{
  // Register a handler for the request channel change message.  This will go
  // in the list AFTER the one for the base class, so the values will already
  // have been filled in.  So we just need to call the user-level callbacks
  // and pass them a pointer to the data values.
  if (register_autodeleted_handler(request_m_id,
	  handle_change_message, this, d_sender_id)) {
	  fprintf(stderr,"vrpn_Analog_Output_Callback_Server: can't register change channel request handler\n");
	  d_connection = NULL;
  }

  // Register a handler for the request channels change message.  This will go
  // in the list AFTER the one for the base class, so the values will already
  // have been filled in.  So we just need to call the user-level callbacks
  // and pass them a pointer to the data values.
  if (register_autodeleted_handler(request_channels_m_id,
	  handle_change_message, this, d_sender_id)) {
	  fprintf(stderr,"vrpn_Analog_Output_Callback_Server: can't register change channels request handler\n");
	  d_connection = NULL;
  }
}
vrpn_Tracker_WiimoteHead::vrpn_Tracker_WiimoteHead(const char* name,
        vrpn_Connection* trackercon,
        const char* wiimote,
        float update_rate,
        float led_spacing) :
	vrpn_Tracker(name, trackercon),
	d_name(wiimote),
	d_update_interval(update_rate ? (1.0 / update_rate) : 1.0 / 60.0),
	d_blobDistance(led_spacing),
	d_flipState(FLIP_UNKNOWN),
	d_points(0),
	d_ana(NULL),
	d_contact(false),
	d_lock(false),
	d_updated(false),
	d_gravDirty(true) {
	// If the name is NULL, we're done.
	if (wiimote == NULL) {
		d_name = NULL;
		fprintf(stderr, "vrpn_Tracker_WiimoteHead: "
		        "Can't start without a valid specified Wiimote device!");
		return;
	}

	setup_wiimote();

	//--------------------------------------------------------------------
	// Whenever we get a connection, set a flag so we make sure to send an
	// update. Set up a handler to do this.
	register_autodeleted_handler(d_connection->register_message_type(vrpn_got_connection),
	                             handle_connection, this);

	//--------------------------------------------------------------------
	// Set the current matrix to identity, the current timestamp to "now",
	// the current matrix to identity in case we never hear from the Wiimote.
	// Also, set the updated flag to send a single report
	reset();

	// put a little z translation as a saner default
	d_currentPose.xyz[2] = 1;

	// Set up our initial "default" pose to make sure everything is
	// safely initialized before our first report.
	_convert_pose_to_tracker();
}
Exemple #21
0
vrpn_Analog_Output_Remote::vrpn_Analog_Output_Remote(const char* name, vrpn_Connection * c) :
    vrpn_Analog_Output(name, c)
{
    vrpn_int32 i;

    o_num_channel = vrpn_CHANNEL_MAX;
    for (i = 0; i < vrpn_CHANNEL_MAX; i++) {
	o_channel[i] = 0;
    }
    vrpn_gettimeofday(&o_timestamp, NULL);

     // Register a handler for the report number of active channels message
    if (register_autodeleted_handler(report_num_channels_m_id,
		    handle_report_num_channels, this, d_sender_id)) 
    {
	fprintf(stderr,"vrpn_Analog_Output_Remote: can't register active channel report handler\n");
	d_connection = NULL;
    }
}
Exemple #22
0
vrpn_Button_Filter::vrpn_Button_Filter(const char *name, vrpn_Connection *c)
	:vrpn_Button(name, c)
{
      if ( (d_sender_id == -1) || (admin_message_id == -1) ) {
        fprintf(stderr,"vrpn_Button: Can't register IDs\n");
         d_connection = NULL;
      }
      register_autodeleted_handler(admin_message_id, client_msg_handler, this);

      //setup message id type for alert messages to alert a device about changes
      alert_message_id = d_connection->register_message_type("vrpn_Button Alert");
      send_alerts=0;	//used to turn on/off alerts -- send and admin message from
			//remote to turn it on -- or server side call set_alerts();

      //set button default buttonstates
      for (vrpn_int32 i=0; i< vrpn_BUTTON_MAX_BUTTONS; i++) {
           buttonstate[i] = vrpn_BUTTON_MOMENTARY;
      }
      return;
}
Exemple #23
0
// ctor
vrpn_Tracker_PhaseSpace::vrpn_Tracker_PhaseSpace(const char *name, vrpn_Connection *c)
  : vrpn_Tracker(name ,c),
    vrpn_Button_Filter(name, c),
    vrpn_Clipping_Analog_Server(name, c),
    debug(false),
    drop_frames(false),
    smgr(NULL)
{
  // TODO fix
  //num_buttons = vrpn_BUTTON_MAX_BUTTONS;
  num_buttons = 0;

  smgr = new SensorManager();

  if(d_connection) {
    // Register a handler for the update change callback
    if (register_autodeleted_handler(update_rate_id, handle_update_rate_request, this, d_sender_id))
      fprintf(stderr,"vrpn_Tracker: Can't register workspace handler\n");
  }
}
Exemple #24
0
// This creates a vrpn_GlobalHapticsOrb and sets it to reset mode. It opens
// the serial device using the code in the vrpn_Serial_Analog constructor.
vrpn_GlobalHapticsOrb::vrpn_GlobalHapticsOrb(const char * name, vrpn_Connection * c,
					     const char * port, int baud) :
		vrpn_Serial_Analog(name, c, port, baud),
		vrpn_Button_Filter(name, c),
		vrpn_Dial(name, c)
{
	// Set the parameters in the parent classes
	vrpn_Button::num_buttons = 30;
	vrpn_Analog::num_channel = 3;
	vrpn_Dial::num_dials = 3;

	// Set the status of the buttons, analogs and encoders to 0 to start
	clear_values();

	// Set a callback handler for when the first connection is made so
	// that it can reset the analogs and buttons whenever this happens.
	register_autodeleted_handler(
		      d_connection->register_message_type(vrpn_got_first_connection),
		      handle_firstConnection, this);

	// Set the mode to reset
	d_status = STATUS_RESETTING;
}
void vrpn_Logitech_Controller_Raw::init_hid()
{
	// Get notifications when clients connect and disconnect
	register_autodeleted_handler(d_connection->register_message_type(vrpn_dropped_last_connection), on_last_disconnect, this);
	register_autodeleted_handler(d_connection->register_message_type(vrpn_got_connection), on_connect, this);
}
void vrpn_Griffin::init_hid(void) {
	// Get notifications when clients connect and disconnect
	register_autodeleted_handler(d_connection->register_message_type(vrpn_dropped_last_connection), on_last_disconnect, this);
	register_autodeleted_handler(d_connection->register_message_type(vrpn_got_connection), on_connect, this);
}
vrpn_Imager_Stream_Buffer::vrpn_Imager_Stream_Buffer(
    const char *name, const char *imager_server_name, vrpn_Connection *c)
    : vrpn_Auxiliary_Logger_Server(name, c)
    , vrpn_Imager_Server(
          name, c, 0, 0) // Default number of rows and columns for the device.
    , d_logging_thread(NULL)
    , d_imager_server_name(NULL)
{
    // Copy the name of the server we are to connect to when we are logging.
    try { d_imager_server_name = new char[strlen(imager_server_name) + 1]; }
    catch (...) {
        fprintf(stderr, "vrpn_Imager_Stream_Buffer::vrpn_Imager_Stream_Buffer: "
                        "Out of memory\n");
        d_connection = NULL;
        return;
    }
    strcpy(d_imager_server_name, imager_server_name);

    // Create the logging thread but do not run it yet.
    vrpn_ThreadData td;
    td.pvUD = this;
    try { d_logging_thread = new vrpn_Thread(static_logging_thread_func, td); }
    catch (...) {
        fprintf(stderr, "vrpn_Imager_Stream_Buffer::vrpn_Imager_Stream_Buffer: "
                        "can't create logging thread\n");
        d_connection = NULL;
        return;
    }

    // Register a handler for the got first connection message.
    got_first_connection_m_id =
        d_connection->register_message_type(vrpn_got_first_connection);
    if (got_first_connection_m_id == -1) {
        fprintf(stderr, "vrpn_Imager_Stream_Buffer::vrpn_Imager_Stream_Buffer: "
                        "can't register got first connection type\n");
        d_connection = NULL;
        return;
    }
    if (register_autodeleted_handler(got_first_connection_m_id,
                                     static_handle_got_first_connection, this,
                                     vrpn_ANY_SENDER)) {
        fprintf(stderr, "vrpn_Imager_Stream_Buffer::vrpn_Imager_Stream_Buffer: "
                        "can't register got first connection handler\n");
        d_connection = NULL;
    }

    // The base server class implements throttling for us, so we could just go
    // ahead
    // and try to send the messages all the time using the normal frame
    // begin/end and
    // region routines.  If we do this, though, we're going to have to unpack
    // and repack
    // all of the messages. If we re-implement the throttling code, then we can
    // just
    // watch the packets as they go by and see what types they are, discarding
    // as
    // appropriate (but we still have to queue and watch them).
    //   If we implement the throttling
    // code down in the thread that listens to the server, we can avoid putting
    // them into the queue at all.  In that case, there can be a frame or more
    // in
    // the queue that would drain even after the throttle message was received.
    //   We can subtract the number of frames in the buffer from the request if
    //   the
    // request is large enough, thus removing the problem, but it won't work for
    // the common case of requesting 0 or 1 frames.  This will work in the
    // steady
    // state, where a sender requests one more each time it gets one, but there
    // will be an initial bolus of images.
    //    Nonetheless, this seems like the cleanest solution.  So, we will
    //    install
    // a handler for the throttling message that will pass it on down to the
    // thread
    // that is baby-sitting the server object.
    if (register_autodeleted_handler(d_throttle_frames_m_id,
                                     static_handle_throttle_message, this,
                                     vrpn_ANY_SENDER)) {
        fprintf(stderr, "vrpn_Imager_Stream_Buffer::vrpn_Imager_Stream_Buffer: "
                        "can't register throttle handler\n");
        d_connection = NULL;
    }
}
Exemple #28
0
vrpn_Tracker_ButtonFly::vrpn_Tracker_ButtonFly
         (const char * name, vrpn_Connection * trackercon,
          vrpn_Tracker_ButtonFlyParam * params, float update_rate,
	  bool reportChanges) :
	vrpn_Tracker (name, trackercon),
	d_vel_scale(NULL),
	d_vel_scale_value(1.0),
	d_rot_scale(NULL),
	d_rot_scale_value(1.0),
	d_update_interval (update_rate ? (1/update_rate) : 1.0),
        d_reportChanges (reportChanges)
{
  int i;

  //--------------------------------------------------------------------
  // Copy the parameter values and initialize the values and pointers
  // in the list of axes.  The setup_channel() call opens the button
  // remote and sets up a callback to handle the changes.
  d_num_axes = params->num_axes;
  for (i = 0; i < params->num_axes; i++) {
    d_axes[i].axis = params->axes[i];
    d_axes[i].active = false;
    d_axes[i].bf = this;
    setup_channel(&d_axes[i]);
  }

  //--------------------------------------------------------------------
  // Open the scale analogs if they have non-NULL names.
  // If the name starts with the "*" character, use tracker
  //      connection rather than getting a new connection for it.
  // Set up a callback for each to set the scale factor.

  if (params->vel_scale_name != NULL) {

    // Copy the parameters into our member variables
    d_vel_scale_channel = params->vel_scale_channel;
    d_vel_scale_offset = params->vel_scale_offset;
    d_vel_scale_scale = params->vel_scale_scale;
    d_vel_scale_power = params->vel_scale_power;

    // Open the analog device and point the remote at it.
    // If the name starts with the '*' character, use
    // the server connection rather than making a new one.
    if (params->vel_scale_name[0] == '*') {
      d_vel_scale = new vrpn_Analog_Remote
             (&(params->vel_scale_name[1]), d_connection);
    } else {
      d_vel_scale = new vrpn_Analog_Remote(params->vel_scale_name);
    }

    // Set up the callback handler
    if (d_vel_scale == NULL) {
      fprintf(stderr,"vrpn_Tracker_ButtonFly: "
           "Can't open Analog %s\n",params->vel_scale_name);
    } else {
      // Set up the callback handler for the channel
      d_vel_scale->register_change_handler(this, handle_velocity_update);
    }
  }

  if (params->rot_scale_name != NULL) {

    // Copy the parameters into our member variables
    d_rot_scale_channel = params->rot_scale_channel;
    d_rot_scale_offset = params->rot_scale_offset;
    d_rot_scale_scale = params->rot_scale_scale;
    d_rot_scale_power = params->rot_scale_power;

    // Open the analog device and point the remote at it.
    // If the name starts with the '*' character, use
    // the server connection rather than making a new one.
    if (params->rot_scale_name[0] == '*') {
      d_rot_scale = new vrpn_Analog_Remote
             (&(params->rot_scale_name[1]), d_connection);
    } else {
      d_rot_scale = new vrpn_Analog_Remote(params->rot_scale_name);
    }

    // Set up the callback handler
    if (d_rot_scale == NULL) {
      fprintf(stderr,"vrpn_Tracker_ButtonFly: "
           "Can't open Analog %s\n",params->rot_scale_name);
    } else {
      // Set up the callback handler for the channel
      d_rot_scale->register_change_handler(this, handle_rotation_update);
    }
  }

  //--------------------------------------------------------------------
  // Whenever we get the first connection to this server, we also
  // want to reset the matrix to identity, so that you start at the
  // beginning. Set up a handler to do this.
  register_autodeleted_handler(d_connection->register_message_type
                                      (vrpn_got_first_connection),
		handle_newConnection, this);

  //--------------------------------------------------------------------
  // Set the initialization matrix to identity, then also set
  // the current matrix to identity.
  for ( i =0; i< 4; i++)
	  for (int j=0; j< 4; j++) 
		  d_initMatrix[i][j] = 0;

  d_initMatrix[0][0] = d_initMatrix[1][1] = d_initMatrix[2][2] =
                     d_initMatrix[3][3] = 1.0;
  reset();
}
vrpn_ForceDeviceServer::vrpn_ForceDeviceServer(const char * name, vrpn_Connection *c):vrpn_ForceDevice(name,c)
{
  if (register_autodeleted_handler(addObject_message_id, 
	handle_addObject_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(addObjectExScene_message_id, 
	handle_addObjectExScene_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(setVertex_message_id, 
	handle_setVertex_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(setNormal_message_id, 
	handle_setNormal_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(setTriangle_message_id, 
	handle_setTriangle_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(removeTriangle_message_id, 
	handle_removeTriangle_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(updateTrimeshChanges_message_id, 
	handle_updateTrimeshChanges_message, this, vrpn_ForceDevice::  d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(transformTrimesh_message_id, 
	handle_transformTrimesh_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(setTrimeshType_message_id, 
	handle_setTrimeshType_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(setObjectPosition_message_id, 
	handle_setObjectPosition_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(setObjectOrientation_message_id, 
	handle_setObjectOrientation_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(setObjectScale_message_id, 
	handle_setObjectScale_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(removeObject_message_id, 
	handle_removeObject_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(moveToParent_message_id, 
	handle_moveToParent_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(setHapticOrigin_message_id, 
	handle_setHapticOrigin_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(setHapticScale_message_id, 
	handle_setHapticScale_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(setSceneOrigin_message_id, 
	handle_setSceneOrigin_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(setObjectIsTouchable_message_id, 
	handle_setObjectIsTouchable_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
  if (register_autodeleted_handler(clearTrimesh_message_id, 
	handle_clearTrimesh_message, this, vrpn_ForceDevice::d_sender_id)) {
		fprintf(stderr,"vrpn_Phantom:can't register handler\n");
		vrpn_ForceDevice::d_connection = NULL;
  }
}
Exemple #30
0
// Device constructor.
// Parameters:
// - name: VRPN name to assign to this server
// - c: VRPN connection this device should be attached to
vrpn_WiiMote::vrpn_WiiMote(const char *name, vrpn_Connection *c, unsigned which):
    vrpn_Analog(name, c),
    vrpn_Button(name, c),
    vrpn_Analog_Output(name, c),
    wiimote(new vrpn_Wiimote_Device)
{
    int i;
    char  msg[1024];

    vrpn_Analog::num_channel = min(64, vrpn_CHANNEL_MAX);
    for (i = 0; i < vrpn_Analog::num_channel; i++) {
        channel[i] = 0;
    }

    // There are bits for up to 16 buttons on the main remote, and for
    // up to 16 more on an expansion pack.
    vrpn_Button::num_buttons = min(64, vrpn_BUTTON_MAX_BUTTONS);
    for (i = 0; i < vrpn_Button::num_buttons; i++) {
        buttons[i] = 0;
    }

    vrpn_Analog_Output::o_num_channel = 1;

    // Register a handler for the request channel change message
    if (register_autodeleted_handler(request_m_id,
                                     handle_request_message, this, d_sender_id)) {
        FAIL("vrpn_WiiMote: can't register change channel request handler");
        return;
    }

    // Register a handler for the request channels change message
    if (register_autodeleted_handler(request_channels_m_id,
                                     handle_request_channels_message, this, d_sender_id)) {
        FAIL("vrpn_WiiMote: can't register change channels request handler");
        return;
    }

    // Register a handler for the no-one's-connected-now message
    if (register_autodeleted_handler(
                d_connection->register_message_type(vrpn_dropped_last_connection),
                handle_last_connection_dropped, this)) {
        FAIL("Can't register self-destruct handler");
        return;
    }

    // Get a list of available devices and select the one we want.
    // Look for up to 4 motes.  Timeout in 5 seconds if one not found.
    wiimote->which = which;
    wiimote_t **available_wiimotes = wiiuse_init(4);
    unsigned num_available = wiiuse_find(available_wiimotes, 4, 5);
    if (num_available < (wiimote->which + 1)) {
        struct timeval now;
        vrpn_gettimeofday(&now, NULL);
        sprintf(msg, "Could not open remote %d (%d found)", wiimote->which, num_available);
        send_text_message(msg, now, vrpn_TEXT_ERROR);
        wiimote->found = false;
    } else {
        wiimote->found = true;

        // Make a list containing just the one we want, and then connect to it.
        wiimote_t *selected_one[1];
        wiimote->device = selected_one[0] = available_wiimotes[wiimote->which];
        wiimote->connected = (wiiuse_connect(selected_one, 1) == 1);
        if (!wiimote->connected) {
            struct timeval now;
            vrpn_gettimeofday(&now, NULL);
            sprintf(msg, "Could not connect to remote %d", wiimote->which);
            send_text_message(msg, now, vrpn_TEXT_ERROR);
        }
    }

    if (wiimote->connected) {
        initialize_wiimote_state();
    }
}