Esempio n. 1
0
void execute_drag(int fd, uint32_t device_flags, int start_x,
                  int start_y, int end_x, int end_y, int num_steps,
                  int duration_msec)
{
  int delta[] = {(end_x-start_x)/num_steps, (end_y-start_y)/num_steps};
  int sleeptime = duration_msec / num_steps;
  int i;

  print_action(ACTION_START, "drag", "\"start_x\": %d, \"start_y\": %d, "
               "\"end_x\": %d, \"end_y\": %d, \"num_steps\": %d, "
               "\"duration_msec\": %d", start_x, start_y, end_x, end_y,
               num_steps, duration_msec);

  // press
  execute_press(fd, device_flags, start_x, start_y);

  // drag
  for (i=0; i<num_steps; i++) {
    execute_sleep(sleeptime);
    execute_move(fd, device_flags, start_x+delta[0]*i, start_y+delta[1]*i);
  }

  // release
  execute_release(fd, device_flags);

  // wait
  execute_sleep(100);

  print_action(ACTION_END, "drag", NULL);
}
Esempio n. 2
0
void execute_pinch(int fd, uint32_t device_flags, int touch1_x1,
                   int touch1_y1, int touch1_x2, int touch1_y2, int touch2_x1,
                   int touch2_y1, int touch2_x2, int touch2_y2, int num_steps,
                   int duration_msec)
{
  int delta1[] = {(touch1_x2-touch1_x1)/num_steps, (touch1_y2-touch1_y1)/num_steps};
  int delta2[] = {(touch2_x2-touch2_x1)/num_steps, (touch2_y2-touch2_y1)/num_steps};
  int sleeptime = duration_msec / num_steps;
  int i;

  print_action(ACTION_START, "pinch",
               "\"touch1_x1\": %d, \"touch1_y1\": %d, \"touch1_x2\": %d, "
               "\"touch1_y2\": %d, \"touch2_x1\": %d, \"touch2_y1\": %d, "
               "\"touch2_x2\": %d, \"touch2_y2\": %d, \"num_steps\": %d, "
               "\"duration_msec\": %d",
               touch1_x1, touch1_y1, touch1_x2, touch1_y2,
               touch2_x1, touch2_y1, touch2_x2, touch2_y2,
               num_steps, duration_msec);

  // press
  change_mt_slot(fd, device_flags, 0);
  add_mt_tracking_id(fd, device_flags, global_tracking_id++);
  execute_press(fd, device_flags, touch1_x1, touch1_y1);

  change_mt_slot(fd, device_flags, 1);
  add_mt_tracking_id(fd, device_flags, global_tracking_id++);
  execute_press(fd, device_flags, touch2_x1, touch2_y1);

  // drag
  for (i=0; i<num_steps; i++) {
    execute_sleep(sleeptime);

    change_mt_slot(fd, device_flags, 0);
    execute_move(fd, device_flags, touch1_x1+delta1[0]*i, touch1_y1+delta1[1]*i);

    change_mt_slot(fd, device_flags, 1);
    execute_move(fd, device_flags, touch2_x1+delta2[0]*i, touch2_y1+delta2[1]*i);

    //write_event(fd, EV_SYN, SYN_REPORT, 0);
  }

  // release
  change_mt_slot(fd, device_flags, 0);
  execute_release(fd, device_flags);

  change_mt_slot(fd, device_flags, 1);
  execute_release(fd, device_flags);

  remove_mt_tracking_id(fd, device_flags, 0);
  remove_mt_tracking_id(fd, device_flags, 1);

  // wait
  execute_sleep(100);

  print_action(ACTION_END, "pinch", NULL);
}
Esempio n. 3
0
void execute_pinch(int fd, int version, unsigned int device_flags, int touch1_x1,
                   int touch1_y1, int touch1_x2, int touch1_y2, int touch2_x1,
                   int touch2_y1, int touch2_x2, int touch2_y2, int num_steps,
                   int duration_msec)
{
    int delta1[] = {(touch1_x2-touch1_x1)/num_steps, (touch1_y2-touch1_y1)/num_steps};
    int delta2[] = {(touch2_x2-touch2_x1)/num_steps, (touch2_y2-touch2_y1)/num_steps};
    int sleeptime = duration_msec / num_steps;
    int i;

    // press
    change_mt_slot(fd, version, device_flags, 0);
    add_mt_tracking_id(fd, version, device_flags, global_tracking_id++);
    execute_press(fd, version, device_flags, touch1_x1, touch1_y1);

    change_mt_slot(fd, version, device_flags, 1);
    add_mt_tracking_id(fd, version, device_flags, global_tracking_id++);
    execute_press(fd, version, device_flags, touch2_x1, touch2_y1);

    // drag
    for (i=0; i<num_steps; i++) {
      execute_sleep(sleeptime);

      change_mt_slot(fd, version, device_flags, 0);
      execute_move(fd, version, device_flags, touch1_x1+delta1[0]*i, touch1_y1+delta1[1]*i);

      change_mt_slot(fd, version, device_flags, 1);
      execute_move(fd, version, device_flags, touch2_x1+delta2[0]*i, touch2_y1+delta2[1]*i);

      //write_event(fd, EV_SYN, SYN_REPORT, 0);
    }

    // release
    change_mt_slot(fd, version, device_flags, 0);
    execute_release(fd, version, device_flags);

    change_mt_slot(fd, version, device_flags, 1);
    execute_release(fd, version, device_flags);

    remove_mt_tracking_id(fd, version, device_flags, 0);
    remove_mt_tracking_id(fd, version, device_flags, 1);

    // wait
    execute_sleep(100);

}
Esempio n. 4
0
void execute_drag(int fd, uint32_t device_flags, int start_x,
                  int start_y, int end_x, int end_y, int num_steps,
                  int duration_msec)
{
  int delta[] = {(end_x-start_x)/num_steps, (end_y-start_y)/num_steps};
  double desired_interval_msec, avg_event_dispatch_time_msec;
  struct timespec start_time, current_time, time_before_last_move;
  int i;

  clock_gettime(CLOCK_MONOTONIC, &start_time);
  double start_nsecs = (double) (start_time.tv_sec * (1000*1000)) + start_time.tv_nsec;

  print_action(ACTION_START, "drag", "\"start_x\": %d, \"start_y\": %d, "
               "\"end_x\": %d, \"end_y\": %d, \"num_steps\": %d, "
               "\"duration_msec\": %d", start_x, start_y, end_x, end_y,
               num_steps, duration_msec);

  // press
  clock_gettime(CLOCK_MONOTONIC, &time_before_last_move);
  execute_press(fd, device_flags, start_x, start_y);

  // drag
  desired_interval_msec = duration_msec / num_steps;
  for (i=0; i<num_steps; i++) {
    clock_gettime(CLOCK_MONOTONIC, &current_time);
    avg_event_dispatch_time_msec = ((avg_event_dispatch_time_msec * i) +
                                    timediff_msec(&time_before_last_move,
                                                  &current_time)) / i;
    if (desired_interval_msec > 0 &&
        avg_event_dispatch_time_msec < desired_interval_msec) {
      execute_sleep(desired_interval_msec - avg_event_dispatch_time_msec);
    }

    memcpy(&time_before_last_move, &current_time, sizeof(struct timespec));
    execute_move(fd, device_flags, start_x+delta[0]*i, start_y+delta[1]*i);
  }

  // release
  execute_release(fd, device_flags);

  // wait
  execute_sleep(100);

  print_action(ACTION_END, "drag", NULL);
}
Esempio n. 5
0
void execute_tap(int fd, int version, unsigned int device_flags, int x, int y,
                 int num_times)
{
  int i;

  for (i=0;i<num_times;i++) {
    // press
    execute_press(fd, version, device_flags, x, y);
    execute_sleep(100);

    // release
    execute_release(fd, version, device_flags);
    execute_sleep(100);

    // wait
    execute_sleep(50);
  }
}
Esempio n. 6
0
File: orng.c Progetto: tdz/orangutan
void execute_tap(int fd, uint32_t device_flags, int x, int y,
                 int num_times, int duration_msec)
{
  int i;

  for (i=0; i<num_times; i++) {
    // press
    execute_press(fd, device_flags, x, y);
    execute_sleep(duration_msec);

    // release
    execute_release(fd, device_flags);
    execute_sleep(100);

    // wait
    execute_sleep(50);
  }
}
Esempio n. 7
0
void execute_drag(int fd, int version, unsigned int device_flags, int start_x,
                  int start_y, int end_x, int end_y, int num_steps,
                  int duration_msec)
{
    int delta[] = {(end_x-start_x)/num_steps, (end_y-start_y)/num_steps};
    int sleeptime = duration_msec / num_steps;
    int i;

    // press
    execute_press(fd, version, device_flags, start_x, start_y);

    // drag
    for (i=0; i<num_steps; i++) {
      execute_sleep(sleeptime);
      execute_move(fd, version, device_flags, start_x+delta[0]*i, start_y+delta[1]*i);
    }

    // release
    execute_release(fd, version, device_flags);

    // wait
    execute_sleep(100);
}
Esempio n. 8
0
void execute_tap(int fd, uint32_t device_flags, int x, int y,
                 int num_times, int duration_msec)
{
  int i;

  print_action(ACTION_START, "tap", "\"x\": %d, \"y\": %d, "
               "\"num_times\": %d, \"duration_msec\": %d", x, y, num_times,
               duration_msec);

  for (i=0; i<num_times; i++) {
    // press
    execute_press(fd, device_flags, x, y);
    execute_sleep(duration_msec);

    // release
    execute_release(fd, device_flags);
    execute_sleep(100);

    // wait
    execute_sleep(50);
  }

  print_action(ACTION_END, "tap", NULL);
}
Esempio n. 9
0
bool ThreadsExec::wake()
{
  verify_is_process("ThreadsExec::wake", true );

  if ( & execute_sleep != s_current_function ) return false ;

  ThreadsExec::global_unlock();

  if ( s_threads_process.m_pool_base ) {
    execute_sleep( s_threads_process , 0 );
    s_threads_process.m_pool_state = ThreadsExec::Inactive ;
  }

  fence();

  return true ;
}
Esempio n. 10
0
int main(int argc, char *argv[])
{
  int i;
  int fd;
  int ret;
  int c;
  const char *device;
  const char *script_file;

  int num_args = 0;
  int args[MAX_COMMAND_ARGS];
  char *line, *cmd, *arg;

  while ((c = getopt (argc, argv, "t")) != -1) {
    if (c=='t') {
      print_actions = 1;
    } else {
      fprintf(stderr, "Unknown option: -%c\n", c);
    }
  }

  if((argc - optind) != 2) {
    fprintf(stderr, "Usage: %s [options] <device> <script file>\n\n"
            "Options:\n"
            "  -t                  print event timings\n", argv[0]);
    return 1;
  }
  device = argv[optind];
  script_file = argv[optind + 1];

  fd = open(device, O_RDWR);
  if(fd < 0) {
    fprintf(stderr, "could not open %s, %s\n", device, strerror(errno));
    return 1;
  }

  uint32_t device_flags = figure_out_events_device_reports(fd);

  FILE *f = fopen(script_file, "r");
  if (!f) {
    printf("Unable to read file %s", script_file);
    return 1;
  }

  line = malloc(sizeof(char)*MAX_COMMAND_LEN);
  int lineCount = 0;
  while (fgets(line, MAX_COMMAND_LEN, f) != NULL) {
    // Remove end-of-line comments.
    char *comment = strstr(line, "#");
    if (comment != NULL)
      *comment = '\0';

    lineCount += 1;
    int hasNextCmd = 1;
    char *tempLine = line;
  commandLoop:
    while (hasNextCmd) {
      num_args = 0;
      hasNextCmd = 0;
      int errCode = 0;

      // Parse {-} comments before command names.
      do {
        if ((cmd = strtok(tempLine, " \n")) == NULL)
          goto commandLoop;
        tempLine = NULL;
      } while ((errCode = parseComment(cmd, lineCount)) == 1);
      if (errCode < 0)
        return 1;

      while ((arg = strtok(NULL, " \n")) != NULL) {
        // Parse comment {-} within arguments.
        if ((errCode = parseComment(arg, lineCount)) != 0) {
          if (errCode < 0)
            return 1;
          continue;
        }

        // If we enter a new command, we remember the position for the next iteration.
        if (*arg == ';') {
          hasNextCmd = 1;
          break;
        }

        assert(num_args < MAX_COMMAND_ARGS);

        args[num_args] = atoi(arg);
        num_args++;
      }

      if (strcmp(cmd, "tap") == 0) {
        checkArguments(cmd, num_args, 4, lineCount);
        execute_tap(fd, device_flags, args[0], args[1], args[2], args[3]);
      } else if (strcmp(cmd, "drag") == 0) {
        checkArguments(cmd, num_args, 6, lineCount);
        execute_drag(fd, device_flags, args[0], args[1], args[2],
                     args[3], args[4], args[5]);
      } else if (strcmp(cmd, "sleep") == 0) {
        checkArguments(cmd, num_args, 1, lineCount);
        execute_sleep(args[0]);
      } else if (strcmp(cmd, "pinch") == 0) {
        checkArguments(cmd, num_args, 10, lineCount);
        execute_pinch(fd, device_flags, args[0], args[1], args[2],
                      args[3], args[4], args[5], args[6], args[7], args[8],
                      args[9]);
      } else if (strcmp(cmd, "keyup") == 0) {
        checkArguments(cmd, num_args, 1, lineCount);
        execute_keyup(fd, args[0]);
      } else if (strcmp(cmd, "keydown") == 0) {
        checkArguments(cmd, num_args, 1, lineCount);
        execute_keydown(fd, args[0]);
      } else {
        printf("Unrecognized command at line %d: '%s'\n", lineCount, cmd);
        return 1;
      }
    }
  }
  free(line);

  return 0;
}
Esempio n. 11
0
int main(int argc, char *argv[])
{
    int i;
    int fd;
    int ret;
    int version;

    int num_args = 0;
    int args[MAX_COMMAND_ARGS];
    char *line, *cmd, *arg;
    char device_name[80];
    unsigned int device_flags = 0;

    if(argc != 3) {
        fprintf(stderr, "Usage: %s <device> <script file>\n", argv[0]);
        return 1;
    }

    fd = open(argv[1], O_RDWR);
    if(fd < 0) {
        fprintf(stderr, "could not open %s, %s\n", argv[optind], strerror(errno));
        return 1;
    }
    if (ioctl(fd, EVIOCGVERSION, &version)) {
        fprintf(stderr, "could not get driver version for %s, %s\n",
                argv[optind], strerror(errno));
        return 1;
    }
    if(ioctl(fd, EVIOCGNAME(sizeof(device_name) - 1), &device_name) < 1) {
        //fprintf(stderr, "could not get device name for %s, %s\n", device, strerror(errno));
        device_name[0] = '\0';
    }

    // the atmel touchscreen has a weird protocol which requires MT_SYN events
    // to be sent after every touch
    if(strcmp(device_name, "atmel-touchscreen") == 0) {
      device_flags &= NEED_MT_SYN;
    }

    FILE *f = fopen(argv[2], "r");
    if (!f) {
      printf("Unable to read file %s", argv[1]);
      return 1;
    }

    line = malloc(sizeof(char)*MAX_COMMAND_LEN);
    while (fgets(line, MAX_COMMAND_LEN, f) != NULL) {
      cmd = strtok(line, " ");

      num_args = 0;
      while ((arg = strtok(NULL, " \n")) != NULL) {
        assert(num_args < MAX_COMMAND_ARGS);

        args[num_args] = atoi(arg);
        num_args++;
      }

      if (strcmp(cmd, "tap") == 0) {
        assert(num_args == 3);
        execute_tap(fd, version, device_flags, args[0], args[1], args[2]);
      } else if (strcmp(cmd, "drag") == 0) {
        assert(num_args == 6);
        execute_drag(fd, version, device_flags, args[0], args[1], args[2],
                     args[3], args[4], args[5]);
      } else if (strcmp(cmd, "sleep") == 0) {
        assert(num_args == 1);
        execute_sleep(args[0]);
      } else if (strcmp(cmd, "pinch") == 0) {
        assert(num_args == 10);
        execute_pinch(fd, version, device_flags, args[0], args[1], args[2],
                      args[3], args[4], args[5], args[6], args[7], args[8],
                      args[9]);
      } else {
        printf("Unrecognized command: '%s'", cmd);
        return 1;
      }
    }
    free(line);

    return 0;
}
Esempio n. 12
0
File: orng.c Progetto: tdz/orangutan
int main(int argc, char *argv[])
{
    int i;
    int fd;
    int ret;

    int num_args = 0;
    int args[MAX_COMMAND_ARGS];
    char *line, *cmd, *arg;

    if(argc != 3) {
        fprintf(stderr, "Usage: %s <device> <script file>\n", argv[0]);
        return 1;
    }

    fd = open(argv[1], O_RDWR);
    if(fd < 0) {
        fprintf(stderr, "could not open %s, %s\n", argv[optind], strerror(errno));
        return 1;
    }

    uint32_t device_flags = figure_out_events_device_reports(fd);

    FILE *f = fopen(argv[2], "r");
    if (!f) {
      printf("Unable to read file %s", argv[1]);
      return 1;
    }

    line = malloc(sizeof(char)*MAX_COMMAND_LEN);
    while (fgets(line, MAX_COMMAND_LEN, f) != NULL) {
      cmd = strtok(line, " ");

      num_args = 0;
      while ((arg = strtok(NULL, " \n")) != NULL) {
        assert(num_args < MAX_COMMAND_ARGS);

        args[num_args] = atoi(arg);
        num_args++;
      }

      if (strcmp(cmd, "tap") == 0) {
        assert(num_args == 4);
        execute_tap(fd, device_flags, args[0], args[1], args[2], args[3]);
      } else if (strcmp(cmd, "drag") == 0) {
        assert(num_args == 6);
        execute_drag(fd, device_flags, args[0], args[1], args[2],
                     args[3], args[4], args[5]);
      } else if (strcmp(cmd, "sleep") == 0) {
        assert(num_args == 1);
        execute_sleep(args[0]);
      } else if (strcmp(cmd, "pinch") == 0) {
        assert(num_args == 10);
        execute_pinch(fd, device_flags, args[0], args[1], args[2],
                      args[3], args[4], args[5], args[6], args[7], args[8],
                      args[9]);
      } else {
        printf("Unrecognized command: '%s'", cmd);
        return 1;
      }
    }
    free(line);

    return 0;
}