Example #1
0
void vrpn_Freespace::deviceUnconfigure() {
    int rc = 0;

    // Send the data mode request
    struct freespace_message message;
    memset(&message, 0, sizeof(message));
    if (_deviceInfo.hVer == 1) {
        message.messageType = FREESPACE_MESSAGE_DATAMOTIONCONTROL;
        struct freespace_DataMotionControl * req;
        req = &message.dataMotionControl;
        req->enableBodyMotion = 0;
        req->enableUserPosition = 0;
        req->inhibitPowerManager = 0;
        req->enableMouseMovement = 1;
        req->disableFreespace = 0;
    } else {
        message.messageType = FREESPACE_MESSAGE_DATAMODEREQUEST;
        struct freespace_DataModeRequest * req;
        req = &message.dataModeRequest;
        req->enableBodyMotion = 0;
        req->enableUserPosition = 0;
        req->inhibitPowerManager = 0;
        req->enableMouseMovement = 1;
        req->disableFreespace = 0;
    }

    rc = freespace_sendMessage(_freespaceDevice, &message);
    if (rc != FREESPACE_SUCCESS) {
        fprintf(stderr, "vrpn_Freespace::deviceUnconfigure: Could not send message: %d.\n", rc);
    }
}
Example #2
0
//-----------------------------------------------------------------------------
void Close() {

   if (DeviceID >= 0) {
      
      // Shut off the data stream
      freespace_message msg;
      memset(&msg, 0, sizeof(msg));

      if (Device.hVer >= 2) {
         msg.messageType = FREESPACE_MESSAGE_DATAMODECONTROLV2REQUEST;
         msg.dataModeControlV2Request.packetSelect = 0;        // No output
         msg.dataModeControlV2Request.modeAndStatus = 1 << 1;  // operating mode == sleep  
      }
      else {
         msg.messageType = FREESPACE_MESSAGE_DATAMODEREQUEST;
         msg.dataModeRequest.enableUserPosition = 0;
         msg.dataModeRequest.inhibitPowerManager = 0;
      }

      int err = freespace_sendMessage(DeviceID, &msg);
      
      // Detach from the tracker
      freespace_closeDevice(DeviceID);
      DeviceID = -1;
   }

   freespace_exit();
}
int FreeSpaceTracker::connect() 
{
	OutputDebugString("Free Tracker Connect\n");
   // Initialize the freespace library
   int err = freespace_init();
   if (err)
      return err;

   // Look for a single tracker
   int num_devices;
   err = freespace_getDeviceList(&DeviceID, 1, &num_devices);
   if (err)
      return err;

   if (num_devices == 0)
      return FREESPACE_ERROR_NO_DEVICE;

   // Attach to the tracker
   err = freespace_openDevice(DeviceID);
   if (err) 
   {
      DeviceID = -1;
      return err;
   }

   err = freespace_getDeviceInfo(DeviceID, &Device);

   // Flush the message stream
   err = freespace_flush(DeviceID);
   if (err)
      return err;

   // Turn on the orientation message stream
   freespace_message msg;
   memset(&msg, 0, sizeof(msg));

   if (Device.hVer >= 2) 
   {
      // version 2 protocol
      msg.messageType = FREESPACE_MESSAGE_DATAMODECONTROLV2REQUEST;
      msg.dataModeControlV2Request.packetSelect = 3;    // User Frame (orientation)
      msg.dataModeControlV2Request.modeAndStatus = 0;   // operating mode == full motion
   }
   else 
   {
      // version 1 protocol
      msg.messageType = FREESPACE_MESSAGE_DATAMODEREQUEST;
      msg.dataModeRequest.enableUserPosition = 1;
      msg.dataModeRequest.inhibitPowerManager = 1;
   }

   err = freespace_sendMessage(DeviceID, &msg);
   if (err)
      return err;

   // Now the tracker is ready to read
   return 0;
}
/**
 * main
 * This example uses the synchronous API to
 *  - find a device
 *  - open the device found
 *  - configure the device to output motion
 *  - read motion messages sent by the device
 * This example assume the device is already connected.
 */
int main(int argc, char* argv[]) {
    struct freespace_message message;
    FreespaceDeviceId device;
    int numIds; // The number of device ID found
    int rc; // Return code
    //struct MultiAxisSensor pointer;
    //struct MultiAxisSensor angVel;

    // Flag to indicate that the application should quit
    // Set by the control signal handler
    int quit = 0;

    printVersionInfo(argv[0]);

    addControlHandler(&quit);

    // Initialize the freespace library
    rc = freespace_init();
    if (rc != FREESPACE_SUCCESS) {
        printf("Initialization error. rc=%d\n", rc);
	    return 1;
    }

    printf("Scanning for Freespace devices...\n");
     // Get the ID of the first device in the list of availble devices
    rc = freespace_getDeviceList(&device, 1, &numIds);
    if (numIds == 0) {
        printf("Didn't find any devices.\n");
        return 1;
    }

    printf("Found a device. Trying to open it...\n");
    // Prepare to communicate with the device found above
    rc = freespace_openDevice(device);
    if (rc != FREESPACE_SUCCESS) {
        printf("Error opening device: %d\n", rc);
        return 1;
    }

    // Display the device information.
    printDeviceInfo(device);

    // Make sure any old messages are cleared out of the system
    rc = freespace_flush(device);
    if (rc != FREESPACE_SUCCESS) {
        printf("Error flushing device: %d\n", rc);
        return 1;
    }

    // Cleanup when done and configure the device to output mouse packets
    printf("Sending message to enable mouse data.\n");
    memset(&message, 0, sizeof(message)); // Init message fields to 0
    message.messageType = FREESPACE_MESSAGE_DATAMODECONTROLV2REQUEST;
    message.dataModeControlV2Request.packetSelect = 1;        // Mouse packet
    message.dataModeControlV2Request.mode = 0; // Set full motion
    rc = freespace_sendMessage(device, &message);
    if (rc != FREESPACE_SUCCESS) {
        printf("Could not send message: %d.\n", rc);
    }

    // Close communications with the device
    printf("Cleaning up...\n");
    freespace_closeDevice(device);

    // Cleanup the library
    freespace_exit();

    return 0;
}
/**
 * main
 * This example uses the synchronous API to 
 *  - find a device
 *  - open the device found
 *  - send a message
 *  - look for a response
 * This example assumes that the device is already connected.
 */
int main(int argc, char* argv[]) {
    FreespaceDeviceId device;                       // Keep track of the device you are talking to
    struct freespace_message send;                  // A place to create messages to send to the device
    struct freespace_message receive;               // A place to put a message received from the device
    int numIds;                                     // Keep track of how many devices are available
    int rc;                                         // Return Code
    int retryCount = 0;                             // How many times tried so far to get a response

    // Flag to indicate that the application should quit
    // Set by the control signal handler
    int quit = 0;

    printVersionInfo(argv[0]);

    addControlHandler(&quit);

    // Initialize the freespace library
    rc = freespace_init();
    if (rc != FREESPACE_SUCCESS) {
        printf("Initialization error. rc=%d\n", rc);
	    return 1;
    }

    printf("Scanning for Freespace devices...\n");
    // Get the ID of the first device in the list of availble devices
    rc = freespace_getDeviceList(&device, 1, &numIds);
    if (numIds == 0) {
        printf("Didn't find any devices.\n");
        return 1;
    }

    printf("Found a device. Trying to open it...\n");
    // Prepare to communicate with the device found above
    rc = freespace_openDevice(device);
    if (rc != FREESPACE_SUCCESS) {
        printf("Error opening device: %d\n", rc);
        return 1;
    }

    // Display the device information.
    printDeviceInfo(device);

    // Make sure any old messages are cleared out of the system
    rc = freespace_flush(device);
    if (rc != FREESPACE_SUCCESS) {
        printf("Error flushing device: %d\n", rc);
        return 1;
    }

    printf("Requesting battery level messages.\n");

    memset(&send, 0, sizeof(send)); // Start with a clean message struct
    // Populate the message fields. Two options are shown below. Uncomment one desired
    // and comment out the one not desired.
    //send.messageType = FREESPACE_MESSAGE_BATTERYLEVELREQUEST; // To send a battery level request
    send.messageType = FREESPACE_MESSAGE_PRODUCTIDREQUEST;    // To send a product ID request

    while (!quit) {
        if (retryCount < RETRY_COUNT_LIMIT) {
            retryCount++;
            // Send the message constructed above.
            rc = freespace_sendMessage(device, &send);
            if (rc != FREESPACE_SUCCESS) {
                printf("Could not send message: %d.\n", rc);
            }

            // Read the response message.
            rc = freespace_readMessage(device, &receive, 100);
            if (rc == FREESPACE_SUCCESS) {
                // Print the received message
                freespace_printMessage(stdout, &receive);
                retryCount = 0;
            } else if (rc == FREESPACE_ERROR_TIMEOUT) {
                printf("<timeout>  Try moving the Freespace device to wake it up.\n");
            } else if (rc == FREESPACE_ERROR_INTERRUPTED) {
                printf("<interrupted>\n");
            } else {
                printf("Error reading: %d. Quitting...\n", rc);
                break;
            }
        } else {
            printf("Did not receive response after %d trials\n", RETRY_COUNT_LIMIT);
            quit = 1;
        }
        SLEEP;
    }

    printf("Cleaning up...\n");
    freespace_closeDevice(device);

    freespace_exit();

    return 0;
}