int
main(int argc, char **argv) {
	Camera	*canon;
	int	retval;
	GPContext *canoncontext = sample_create_context();

	gettimeofday(&starttime,NULL);
	gp_log_add_func(GP_LOG_ERROR, errordumper, NULL);
	gp_camera_new(&canon);

	/* When I set GP_LOG_DEBUG instead of GP_LOG_ERROR above, I noticed that the
	 * init function seems to traverse the entire filesystem on the camera.  This
	 * is partly why it takes so long.
	 * (Marcus: the ptp2 driver does this by default currently.)
	 */
	printf("Camera init.  Takes about 10 seconds.\n");
	retval = gp_camera_init(canon, canoncontext);
	if (retval != GP_OK) {
		printf("  Retval: %d\n", retval);
		exit (1);
	}
	canon_enable_capture(canon, TRUE, canoncontext);
	/*set_capturetarget(canon, canoncontext);*/
	capture_to_file(canon, canoncontext, "foo.jpg");
	gp_camera_exit(canon, canoncontext);
	return 0;
}
Beispiel #2
0
int main(int argc, char **argv) {
	Camera		*camera = NULL;
	int		ret;
	GPContext	*context;
	CameraWidget	*rootwidget;
	char		buf[200];
	CameraText	summary;

        gp_log_add_func(GP_LOG_DEBUG, errordumper, NULL);

	context = sample_create_context (); /* see context.c */

	strcpy(buf,"usb:");
	if (argc > 1)
		strcat (buf, argv[1]);

	fprintf(stderr,"setting path %s.\n", buf);

	ret = sample_open_camera (&camera, "USB PTP Class Camera", buf, context);
        if (ret < GP_OK) {
		fprintf(stderr,"camera %s not found.\n", buf);
		goto out;
	}

	ret = gp_camera_init (camera, context);
	if (ret < GP_OK) {
		fprintf(stderr,"No camera auto detected.\n");
		goto out;
	}

	/* AFL PART STARTS HERE */
	ret = gp_camera_get_summary (camera, &summary, context);
	if (ret < GP_OK) {
		printf ("Could not get summary.\n");
		goto out;
	}

#if 1
	ret = gp_camera_get_config (camera, &rootwidget, context);
	if (ret < GP_OK) {
		fprintf (stderr,"Could not get config.\n");
		goto out;
	}
#endif
	printf ("OK, %s\n", summary.text);

	/* AFL PART ENDS HERE */
out:
	gp_camera_exit (camera, context);
	gp_camera_free (camera);
	return 0;
}
int main(int argc, char **argv) {
    CameraList	*list;
    Camera		**cams;
    int		ret, i, count;
    const char	*name, *value;
    GPContext	*context;

    context = sample_create_context (); /* see context.c */

    /* Detect all the cameras that can be autodetected... */
    ret = gp_list_new (&list);
    if (ret < GP_OK) return 1;
    count = sample_autodetect (list, context);

    /* Now open all cameras we autodected for usage */
    printf("Number of cameras: %d\n", count);
    cams = calloc (sizeof (Camera*),count);
    for (i = 0; i < count; i++) {
        gp_list_get_name  (list, i, &name);
        gp_list_get_value (list, i, &value);
        ret = sample_open_camera (&cams[i], name, value, context);
        if (ret < GP_OK) fprintf(stderr,"Camera %s on port %s failed to open\n", name, value);
    }
    /* Now call a simple function in each of those cameras. */
    for (i = 0; i < count; i++) {
        CameraText	text;
        char 		*owner;
        ret = gp_camera_get_summary (cams[i], &text, context);
        if (ret < GP_OK) {
            fprintf (stderr, "Failed to get summary.\n");
            continue;
        }

        gp_list_get_name  (list, i, &name);
        gp_list_get_value (list, i, &value);
        printf("%-30s %-16s\n", name, value);
        printf("Summary:\n%s\n", text.text);

        /* Query a simple string configuration variable. */
        ret = get_config_value_string (cams[i], "owner", &owner, context);
        if (ret >= GP_OK) {
            printf("Owner: %s\n", owner);
            free (owner);
        } else {
            printf("Owner: No owner found.\n");
        }

    }
    return 0;
}
	CameraController() {
		int	retval;
		context = sample_create_context();

		gp_log_add_func(GP_LOG_ERROR, errordumper, NULL);
		gp_camera_new(&camera);

		printf("Camera init.  Takes a few seconds.\n");
		signal(SIGTERM, handle_sigterm);
		retval = gp_camera_init(camera, context);
		if (retval != GP_OK) {
			printf("  Retval: %d\n", retval);
			exit (1);
		}

	}
Beispiel #5
0
int main(int argc, char **argv) {
	Camera		*camera;
	int		ret;
	char		*owner;
	GPContext	*context;

	context = sample_create_context (); /* see context.c */

	gp_log_add_func(GP_LOG_ERROR, errordumper, NULL);

	gp_camera_new (&camera);

	/* This call will autodetect cameras, take the
	 * first one from the list and use it. It will ignore
	 * any others... See the *multi* examples on how to
	 * detect and use more than the first one.
	 */
	ret = gp_camera_init (camera, context);
	if (ret < GP_OK) {
		printf("No camera auto detected.\n");
		gp_camera_free (camera);
		return 0;
	}

	ret = get_config_value_string (camera, "ownername", &owner, context);
	if (ret < GP_OK) {
		printf ("Could not query owner.\n");
		goto out;
	}
	printf("Current owner: %s\n", owner);
	if (argc > 1) {
		ret = set_config_value_string (camera, "ownername", argv[1], context);
		if (ret < GP_OK) {
			fprintf (stderr, "Failed to set camera owner to %s; %d\n", argv[1], ret);
		} else 
			printf("New owner: %s\n", argv[1]);
	}
out:
	gp_camera_exit (camera, context);
	gp_camera_free (camera);
	return 0;
}
int main(int argc, char **argv) {
	Camera		*camera;
	int		ret;
	char		*owner;
	GPContext	*context;
	CameraText	text;

	context = sample_create_context (); /* see context.c */
	gp_camera_new (&camera);

	/* This call will autodetect cameras, take the
	 * first one from the list and use it. It will ignore
	 * any others... See the *multi* examples on how to
	 * detect and use more than the first one.
	 */
	ret = gp_camera_init (camera, context);
	if (ret < GP_OK) {
		printf("No camera auto detected.\n");
		gp_camera_free (camera);
		return 0;
	}

	/* Simple query the camera summary text */
	ret = gp_camera_get_summary (camera, &text, context);
	if (ret < GP_OK) {
		printf("Camera failed retrieving summary.\n");
		gp_camera_free (camera);
		return 0;
	}
	printf("Summary:\n%s\n", text.text);

	/* Simple query of a string configuration variable. */
	ret = get_config_value_string (camera, "owner", &owner, context);
	if (ret >= GP_OK) {
		printf("Owner: %s\n", owner);
		free (owner);
	}
	gp_camera_exit (camera, context);
	gp_camera_free (camera);
	gp_context_unref (context);
	return 0;
}
Beispiel #7
0
int
main(int argc, char **argv) {
	Camera	*camera;
	int	retval;
	GPContext *context = sample_create_context();
	FILE 	*f;
	char	*data;
	unsigned long size;

	gp_log_add_func(GP_LOG_ERROR, errordumper, NULL);
	gp_camera_new(&camera);

	/* When I set GP_LOG_DEBUG instead of GP_LOG_ERROR above, I noticed that the
	 * init function seems to traverse the entire filesystem on the camera.  This
	 * is partly why it takes so long.
	 * (Marcus: the ptp2 driver does this by default currently.)
	 */
	printf("Camera init.  Takes about 10 seconds.\n");
	retval = gp_camera_init(camera, context);
	if (retval != GP_OK) {
		printf("  Retval of capture_to_file: %d\n", retval);
		exit (1);
	}
	capture_to_file(camera, context, "foo.jpg");

	capture_to_memory(camera, context, (const char**)&data, &size);

	f = fopen("foo2.jpg", "wb");
	if (f) {
		retval = fwrite (data, size, 1, f);
		if (retval != size) {
			printf("  fwrite size %ld, written %d\n", size, retval);
		}
		fclose(f);
	} else
		printf("  fopen foo2.jpg failed.\n");
	gp_camera_exit(camera, context);
	return 0;
}
Beispiel #8
0
int main(int argc, char **argv) {
	Camera		*camera = NULL;
	int		ret;
	GPContext	*context;
	CameraWidget	*rootwidget;
	char		buf[200];
	CameraText	summary;

        gp_log_add_func(GP_LOG_DEBUG, errordumper, NULL);

	context = sample_create_context (); /* see context.c */

	strcpy(buf,"usb:");
	if (argc > 1)
		strcat (buf, argv[1]);

	fprintf(stderr,"setting path %s.\n", buf);

	ret = sample_open_camera (&camera, "USB PTP Class Camera", buf, context);
        if (ret < GP_OK) {
		fprintf(stderr,"camera %s not found.\n", buf);
		goto out;
	}

	ret = gp_camera_init (camera, context);
	if (ret < GP_OK) {
		fprintf(stderr,"No camera auto detected.\n");
		goto out;
	}

	/* AFL PART STARTS HERE */

	ret = recursive_directory(camera, "/", context, NULL);
	if (ret < GP_OK) {
		printf ("Could not recursive list files.\n");
		goto out;
	}

	ret = gp_camera_get_summary (camera, &summary, context);
	if (ret < GP_OK) {
		printf ("Could not get summary.\n");
		goto out;
	}

#if 1
	ret = gp_camera_get_config (camera, &rootwidget, context);
	if (ret < GP_OK) {
		fprintf (stderr,"Could not get config.\n");
		goto out;
	}
#endif
	printf ("OK, %s\n", summary.text);
	while (1) {
		CameraEventType evttype;
		void *data = NULL;

		ret = gp_camera_wait_for_event(camera, 1, &evttype, &data, context);
		if (ret < GP_OK) break;
		if (data) free (data);
		if (evttype == GP_EVENT_TIMEOUT) break;
	}

	/* AFL PART ENDS HERE */
out:
	gp_camera_exit (camera, context);
	gp_camera_free (camera);
	return 0;
}
Beispiel #9
0
int
main(int argc, char **argv) {
	Camera	*canon;
	int	i, retval;
	GPContext *canoncontext = sample_create_context();

	gp_log_add_func(GP_LOG_ERROR, errordumper, 0);
	gp_camera_new(&canon);

	/* When I set GP_LOG_DEBUG instead of GP_LOG_ERROR above, I noticed that the
	 * init function seems to traverse the entire filesystem on the camera.  This
	 * is partly why it takes so long.
	 * (Marcus: the ptp2 driver does this by default currently.)
	 */
	printf("Camera init.  Takes about 10 seconds.\n");
	retval = gp_camera_init(canon, canoncontext);
	if (retval != GP_OK) {
		printf("  Retval: %d\n", retval);
		exit (1);
	}
	canon_enable_capture(canon, TRUE, canoncontext);
	retval = camera_eosviewfinder(canon,canoncontext,1);
	if (retval != GP_OK) {
		fprintf(stderr,"camera_eosviewfinder(1): %d\n", retval);
		exit(1);
	}
	/*set_capturetarget(canon, canoncontext);*/
	printf("Taking 100 previews and saving them to snapshot-XXX.jpg ...\n");
	for (i=0;i<100;i++) {
		CameraFile *file;
		char output_file[32];

		fprintf(stderr,"preview %d\n", i);
		retval = gp_file_new(&file);
		if (retval != GP_OK) {
			fprintf(stderr,"gp_file_new: %d\n", retval);
			exit(1);
		}

		/* autofocus every 10 shots */
		if (i%10 == 9) {
			camera_auto_focus (canon, canoncontext, 1);
			/* FIXME: wait a bit and/or poll events ? */
			camera_auto_focus (canon, canoncontext, 0);
		} else {
			camera_manual_focus (canon, (i/10-5)/2, canoncontext);
		}
#if 0 /* testcase for EOS zooming */
		{
			char buf[20];
			if (i<10) set_config_value_string (canon, "eoszoom", "5", canoncontext);
			sprintf(buf,"%d,%d",(i&0x1f)*64,(i>>5)*64);
			fprintf(stderr, "%d - %s\n", i, buf);
			set_config_value_string (canon, "eoszoomposition", buf, canoncontext);
		}
#endif
		retval = gp_camera_capture_preview(canon, file, canoncontext);
		if (retval != GP_OK) {
			fprintf(stderr,"gp_camera_capture_preview(%d): %d\n", i, retval);
			exit(1);
		}
		sprintf(output_file, "snapshot-%03d.jpg", i);
		retval = gp_file_save(file, output_file);
		if (retval != GP_OK) {
			fprintf(stderr,"gp_camera_capture_preview(%d): %d\n", i, retval);
			exit(1);
		}
		gp_file_unref(file);
	/*
		sprintf(output_file, "image-%03d.jpg", i);
	        capture_to_file(canon, canoncontext, output_file);
	*/
	}
	retval = camera_eosviewfinder(canon,canoncontext,0);
	if (retval != GP_OK) {
		fprintf(stderr,"camera_eosviewfinder(0): %d\n", retval);
		exit(1);
	}

	sleep(10);
	gp_camera_exit(canon, canoncontext);
	return 0;
}