r4476 - developers/jeremy/maniac/src

jeremy at docs.openmoko.org jeremy at docs.openmoko.org
Thu Jun 5 05:56:01 CEST 2008


Author: jeremy
Date: 2008-06-05 05:56:00 +0200 (Thu, 05 Jun 2008)
New Revision: 4476

Modified:
   developers/jeremy/maniac/src/maniac.c
Log:
2008-06-05  Jeremy Chang  <jeremy at openmoko.com>

	* Implement the function of specifying limited area to test maniac.



Modified: developers/jeremy/maniac/src/maniac.c
===================================================================
--- developers/jeremy/maniac/src/maniac.c	2008-06-04 15:34:52 UTC (rev 4475)
+++ developers/jeremy/maniac/src/maniac.c	2008-06-05 03:56:00 UTC (rev 4476)
@@ -13,8 +13,14 @@
 #define LAP_MIN 500000
 #define LAP_MAX 2000000
 #define PATH_MAX 1024
-int fd; 
+typedef int Coord;
 
+static int fd; 
+static Coord x1 = 0;
+static Coord y1 = 0;
+static Coord x2 = 0;
+static Coord y2 = 0;
+
 enum {
    MANIAC_NONE,    // Show a random for a while and exit
    MANIAC_DEMO,    // Show a random for a while and exit
@@ -97,34 +103,46 @@
 void *
 maniac_mouse_func(void *param)
 {
-   int w, h;
    int screen;
    int x, y;
+   int w, h;
    int mouse_cmd;
    int lap;
    char data[32];
    int len;
    Display *disp = display_get();
 
+   x = 0;
+   y = 0;
    screen = DefaultScreen(disp);
    w = DisplayWidth(disp, screen);
    h = DisplayHeight(disp, screen);
+
+
+   if(x1 > x) x = x1;
+   if(y1 > y) y = y1;
+
+   if( (x2 < w) && (x2-x1 > 0) ) w = x2 - x;
+   if( (y2 < h) && (y2-x1 > 0) ) h = y2 - y;
+
   
    srand((unsigned)time(NULL));
-   printf("Maniac mouse event starts\n");
+   printf("Maniac mouse event starts in area: x:%d y:%d w:%d h:%d\n", x, y, w, h);
+   int px, py;
+
    while(1)
      {
-        x = rand() % w;
-        y = rand() % h;
+        px = x + rand() % w;
+        py = y + rand() % h;
         mouse_cmd = rand() % 3;
         lap = random_lap_get();
 
         if(fd)
           {
-             len = snprintf(data, sizeof(data), "%d %d %d %d\n", mouse_cmd, x, y, lap);
+             len = snprintf(data, sizeof(data), "%d %d %d %d\n", mouse_cmd, px, py, lap);
              write(fd, data, len);
           }
-        maniac_play_step(disp, mouse_cmd, x, y, lap);
+        maniac_play_step(disp, mouse_cmd, px, py, lap);
      } 
    return NULL;
 }
@@ -301,8 +319,24 @@
              log_file_name = strdup(buf);
              mode = MANIAC_RANDOM;
              i++;
-             break;
           }
+        else if (((!strcmp(argv[i], "-r")) ||
+             (!strcmp(argv[i], "-rect")) ||
+             (!strcmp(argv[i], "--rect"))) && (i < (argc - 4)))
+          {
+             char buf[8];
+             sscanf(argv[i +1], "%s", buf);
+             x1 = atoi(buf);
+             sscanf(argv[i +2], "%s", buf);
+             y1 = atoi(buf);
+             sscanf(argv[i +3], "%s", buf);
+             x2 = atoi(buf);
+             sscanf(argv[i +4], "%s", buf);
+             y2 = atoi(buf);
+             printf("lock in an area rect: %d %d %d %d\n", x1, y1, x2, y2);
+             if((y1-x1 > 0) && (y2 - x2 > 0) )
+             i += 4;
+          }
         else if(((!strcmp(argv[i], "-p")) ||
              (!strcmp(argv[i], "-play")) ||
              (!strcmp(argv[i], "--play"))) && (i < (argc - 1)))
@@ -359,28 +393,6 @@
    else if(mode == MANIAC_LOG)
      printf(">>> Log mode (not completed yet)\n");
 
-
-/*
-   // put into a thread
-   int err;
-   pthread_t pid;
-   err = pthread_create(&pid, NULL, maniac_thread_func, NULL);
-   sleep(1);
-   printf("thread: err=%d pid=%d\n", err, pid);
-*/
-   /*
-   pid_t pid; 
-   if(pid=fork())
-     {
-        printf("child pid is %d\n", pid);
-   
-     }
-   else
-     {
-        printf("pid is %d\n", pid);
-        maniac_thread_func(NULL);
-     }
-    */
    printf("exit program\n");
    return 0;
 }





More information about the commitlog mailing list