--- setpwc-0.6/setpwc.c.orig	Thu Apr 22 10:13:32 2004
+++ setpwc-0.6/setpwc.c	Tue Apr 27 00:00:41 2004
@@ -14,9 +14,9 @@
 
 char *device = "/dev/video0";
 
-#define SET_PAN		0
-#define SET_TILT	1
-#define SET_ZOOM	2
+#define SET_PAN		1
+#define SET_TILT	2
+#define SET_ZOOM	4
 
 void error_exit(char *what_ioctl)
 {
@@ -31,12 +31,16 @@
 {
 	if (*fd == -1)
 	{
-		/* open device */
-		*fd = open(device, O_RDWR);
-		if (*fd == -1)
-		{
-			fprintf(stderr, "Error while accessing device %s: %s\n", device, strerror(errno));
-			exit(1);
+		if(strcmp(device,"-") == 0) {
+			*fd = 0;
+		} else {
+			/* open device */
+			*fd = open(device, O_RDWR);
+			if (*fd == -1)
+			{
+				fprintf(stderr, "Error while accessing device %s: %s\n", device, strerror(errno));
+				exit(1);
+			}
 		}
 	}
 }
@@ -242,13 +246,25 @@
 	printf("Time tilt: %d\n", pms.time_tilt);
 }
 
+int query_pan_tilt_busy(fd)
+{
+	struct pwc_mpt_status pms;
+
+	if (ioctl(fd, VIDIOCPWCMPTSTATUS, &pms) == -1)
+		error_exit("VIDIOCPWCMPTSTATUS");
+
+        //printf("Status: %d\n", pms.status);
+
+        return pms.status == 1;
+}
+
 void reset_pan_tilt(int fd, int what)
 {
 	if (ioctl(fd, VIDIOCPWCMPTRESET, &what) == -1)
 		error_exit("VIDIOCPWCMPTRESET");
 }
 
-void set_pan_or_tilt_or_zoom(int fd, char what, int value)
+void set_pan_or_tilt_or_zoom(int fd, char what, int pan, int tilt, int zoom)
 {
 	struct pwc_mpt_angles pma;
 
@@ -256,12 +272,12 @@
 	if (ioctl(fd, VIDIOCPWCMPTGANGLE, &pma) == -1)
 		error_exit("VIDIOCPWCMPTGANGLE");
 
-	if (what == SET_PAN)
-		pma.pan = value;
-	else if (what == SET_TILT)
-		pma.tilt = value;
-	else if (what == SET_ZOOM)
-		pma.zoom = value;
+	if (what & SET_PAN)
+		pma.pan = pan;
+	if (what & SET_TILT)
+		pma.tilt = tilt;
+	if (what & SET_ZOOM)
+		pma.zoom = zoom;
 
 	if (ioctl(fd, VIDIOCPWCMPTSANGLE, &pma) == -1)
 		error_exit("VIDIOCPWCMPTSANGLE");
@@ -484,6 +500,7 @@
 	fprintf(stderr, "-v	set zoom\n");
 	fprintf(stderr, "-y x	set pan position\n");
 	fprintf(stderr, "-z x	set tilt position\n");
+	fprintf(stderr, "-W	pause until pan/tilt is complete\n");
 	fprintf(stderr, "-h	this help\n");
 	fprintf(stderr, "\n");
 	fprintf(stderr, "With this tool, you can only set settings specific to the Philips WebCams.\n");
@@ -496,9 +513,15 @@
 	int fd = -1;
 	char c;
 
+        int delay = 0;
+        int zoom = 0;
+        int pan = 0;
+        int tilt = 0;
+        int movewhat = 0;
+
 	fprintf(stderr, "setpwc, (C) 2003 by folkert@vanheusden.com\n");
 
-        while((c = getopt(argc, argv, "d:hf:pbrxc:g:s:w:a:e:i:j:k:l:m:n:o:q:t:uv:y:z:")) != -1)
+        while((c = getopt(argc, argv, "d:hf:pbrxc:g:s:w:a:e:i:j:k:l:m:n:o:q:t:uv:y:z:W")) != -1)
 	{
 		switch(c) {
 		case 'd':
@@ -592,22 +615,33 @@
 			query_pan_tilt_status(fd);
 			break;
 		case 'v':
-			check_device(&fd);
-			set_pan_or_tilt_or_zoom(fd, SET_ZOOM, atoi(optarg));
+                        zoom = atoi(optarg);
+                        movewhat |= SET_ZOOM;
 			break;
 		case 'y':
-			check_device(&fd);
-			set_pan_or_tilt_or_zoom(fd, SET_PAN, atoi(optarg));
+                        pan = atoi(optarg);
+                        movewhat |= SET_PAN;
 			break;
 		case 'z':
-			check_device(&fd);
-			set_pan_or_tilt_or_zoom(fd, SET_TILT, atoi(optarg));
+                        tilt = atoi(optarg);
+                        movewhat |= SET_TILT;
 			break;
+                case 'W':
+                        delay = 1;
+                        break;
 		default:
 			fprintf(stderr, "Internal error: unexpected option (%c %s).\n", c, optarg);
 			break;
 		}
 	}
+        if(movewhat != 0) {
+          check_device(&fd);
+          set_pan_or_tilt_or_zoom(fd, movewhat, pan, tilt, zoom);
+        }
+
+        if(delay) {
+          while(query_pan_tilt_busy(fd)) usleep(100);
+        }
 
 	if (fd != -1)
 		close(fd);
