Ejemplo n.º 1
0
int main(int argc, char *argv[]) {
  char *section = NULL;//"Default [ \nblablabla";
  float heading, pitch, roll;
  float tx, ty, tz;
  unsigned int counter;
  int retval;
  
  if(argc > 1){
    section = argv[1];
  }
  printf("Section: %s\n", section);
  
  retval = linuxtrack_init(section);
  while(linuxtrack_get_tracking_state() == INITIALIZING){
    ltr_int_usleep(333333);
  }
  if (retval != 0) { 
    printf("Error %d detected! Aborting!\n", retval);
    return retval; 
  };  
  printf("Trying to recenter!\n");
  linuxtrack_recenter();
  pthread_create(&reader, NULL, kbd_reader, NULL);
  unsigned int cntr=-1; 
  while (!quit_flag) {
    retval = linuxtrack_get_pose (&heading,&pitch,&roll,
                                  &tx, &ty, &tz, &counter);
    if(retval < 0){
      printf("Problem reading update!\n");
      break;
    }
    if(cntr != counter){
      cntr = counter;
      printf("hdg:%8.3f pitch:%8.3f roll:%8.3f ", heading, pitch, roll);
      printf("tx:%8.3f y:%8.3f z:%8.3f\n", tx, ty, tz);
    }
    ltr_int_usleep(100000);
  }
  pthread_join(reader, NULL);
  return 0;
}
Ejemplo n.º 2
0
int main(int argc, const char **argv)
{
    (void)(argc);
    (void)(argv);

    int ret;

    // Pre-emptively destory any previous device that might still be around
    foohid_destroy(FoohidDevice, strlen(FoohidDevice));

    // Create the virtual HID device
    ret = foohid_create(FoohidDevice, strlen(FoohidDevice), (uint64_t)report_descriptor, sizeof(report_descriptor));
    if (ret != 0) {
        printf("Unable to create device.\n");
        exit(1);
    }

    // Now initialise linuxTracker
    bool trackingInitialised = intialise_tracking();
    if (!trackingInitialised) {
        printf("Initialisation of tracking failed: tracker not running or not found.\n");

        foohid_destroy(FoohidDevice, strlen(FoohidDevice));

        exit(1);
    }

    struct mouse_report_t mouse;

    // Do some silly stuff
    // for (int i = 0; i < 1000000; ++i) {
    for (;;) {
        if (linuxtrack_get_pose(&heading, &pitch, &roll, &x, &y, &z, &counter) > 0) {
          printf("heading:%f  pitch:%f  roll:%f\n  x:%f  y:%f  z:%f\n", heading, pitch, roll, x, y, z);

          mouse.buttons = 0;
          float nx = (130.0f + heading) / 260.0f;
          float ny = (80.0f + pitch) / 160.0f;
          mouse.x = (int)(nx * 1024.0f); //rand();
          mouse.y = (int)(ny * 768.0f);; //rand();
          mouse.x = 1;
          mouse.y = 1;

          printf("nx: %f, ny: %f mouse.x:%d  mouse.y:%d\n", nx, ny, mouse.x, mouse.y);

          // ignore return value, just for testing
          ret = foohid_send(FoohidDevice, strlen(FoohidDevice), (uint64_t)&mouse, sizeof(mouse_report_t));
        }

    }

    //linuxtrack_shutdown();

    // Finally destroy ("disconnect") the virtual HID device again
    ret = foohid_destroy(FoohidDevice, strlen(FoohidDevice));
    if (ret != 0) {
        printf("Unable to destroy device before exit.\n");
        exit(1);
    }

    return 0;
}