Exemple #1
0
// This routine will reset the Spaceball, zeroing the position,
// mode and making the device beep.
int	vrpn_Spaceball::reset(void) {

    /* Spaceball initialization string. Newer documentation suggests  */
    /* eliminating several init settings, leaving them at defaults.   */
    const char *reset_str = "CB\rNT\rFTp\rFRp\rP@r@r\rMSSV\rZ\rBcCcC\r";

    // Set the values back to zero for all buttons, analogs and encoders
    clear_values();

    /* Reset some state variables back to zero */
    bufpos = 0;
    packtype = 0;
    packlen = 0;
    escapedchar = 0;
    erroroccured = 0;
    resetoccured = 0;
    spaceball4000 = 0; /* re-determine which type it is     */
    leftymode4000 = 0; /* re-determine if its in lefty mode */
    null_radius = 8;  // The NULL radius is now set to 8

    // Send commands to the device to cause it to reset and beep.
    vrpn_flush_input_buffer(serial_fd);
    vrpn_write_slowly(serial_fd, (const unsigned char *)reset_str, strlen(reset_str), 5);

    // We're now waiting for a response from the box
    status = STATUS_SYNCING;

    vrpn_gettimeofday(&timestamp, NULL);	// Set watchdog now
    return 0;
}
Exemple #2
0
int	vrpn_Magellan::reset(void)
{
	struct	timeval	timeout, now;
	unsigned char	inbuf[45];
	const	char	*reset_str = "z\rm3\rc30\rnH\rbH\r";	// Reset string sent to box
	const	char	*expect_back = "z\rm3\rc30\rnH\rb\r";	// What we expect back
	int	ret;

	//-----------------------------------------------------------------------
	// See if we should be using the alternative reset string.
	// XXX The "expect_back" string here is almost certainly wrong.  Waiting
	// to hear back what the correct one should be.
	if (_altreset) {
	  reset_str = "z\rm3\rnH\rp?0\rq00\r";
	  expect_back = "z\rm3\rnH\rp?0\rq00\r";
	}

	//-----------------------------------------------------------------------
	// Set the values back to zero for all buttons, analogs and encoders
	clear_values();

	//-----------------------------------------------------------------------
	// Send the list of commands to the device to cause it to reset and beep.
	// Read back the response and make sure it matches what we expect.
	// Give it a reasonable amount of time to finish, then timeout
	vrpn_flush_input_buffer(serial_fd);
	vrpn_write_slowly(serial_fd, (unsigned char *)reset_str, strlen(reset_str), 5);
	timeout.tv_sec = 1;
	timeout.tv_usec = 0;
	ret = vrpn_read_available_characters(serial_fd, inbuf, strlen(expect_back), &timeout);
	inbuf[strlen(expect_back)] = 0;		// Make sure string is NULL-terminated

	vrpn_gettimeofday(&now, NULL);
	if (ret < 0) {
		send_text_message("vrpn_Magellan reset: Error reading from device", now);
		return -1;
	}
	if (ret == 0) {
		send_text_message("vrpn_Magellan reset: No response from device", now);
		return -1;
	}
	if (ret != (int)strlen(expect_back)) {
            send_text_message("vrpn_Magellan reset: Got less than expected number of characters", now);
                             //,ret,    strlen(expect_back));
		return -1;
	}

	// Make sure the string we got back is what we expected
	if ( strcmp((char *)inbuf, expect_back) != 0 ) {
		send_text_message("vrpn_Magellan reset: Bad reset string", now);
                //(want %s, got %s)\n",	expect_back, inbuf);
		return -1;
	}

	// The NULL radius is now set to 8
	_null_radius = 8;

	// We're now waiting for a response from the box
	status = STATUS_SYNCING;

	vrpn_gettimeofday(&timestamp, NULL);	// Set watchdog now
	return 0;
}