1 #include <stdlib.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <fcntl.h>
5 #include <stdio.h>
6 #include <stdarg.h>
7 #include <string.h>
8 #include <gphoto2/gphoto2.h>
9 
10 #include "samples.h"
11 
main(int argc,char * argv[])12 int main(int argc, char *argv[]){
13         Camera		*camera;
14         GPContext	*context = gp_context_new();
15         int		retval;
16 	CameraEventType evttype;
17 	void    	*evtdata;
18 	CameraFile	*file;
19 
20         gp_camera_new(&camera);
21 	retval = gp_camera_init(camera, context);
22         if(retval != GP_OK)
23         {
24                 printf("Error: %s\n", gp_result_as_string(retval));
25                 return 1;
26         }
27 
28 	do {
29 		retval = gp_camera_wait_for_event (camera, 10, &evttype, &evtdata, context);
30 	} while ((retval == GP_OK) && (evttype != GP_EVENT_TIMEOUT));
31 
32 	retval = gp_file_new(&file);
33 	if (retval != GP_OK) {
34 		printf("gp_file_new: %d\n", retval);
35 		return 1;
36 	}
37 	/*retval = gp_camera_capture_preview(camera, file, context); */
38 	if (retval != GP_OK) {
39 		printf("gp_camera_capture_preview: %d\n", retval);
40 		return 1;
41 	}
42 	gp_file_free (file);
43 
44         if(argc == 1)
45         {
46                 retval = camera_auto_focus(camera, context, 1);
47 		if(retval != GP_OK) {
48 			printf("Error: %s\n", gp_result_as_string(retval));
49 			return 1;
50 		}
51         }
52         else if(argc == 2)
53         {
54                 int value = atoi(argv[1]);
55                 retval = camera_manual_focus(camera, value, context);
56 		if(retval != GP_OK) {
57 			printf("Error: %s\n", gp_result_as_string(retval));
58 			return 1;
59 		}
60         }
61 	do {
62 		retval = gp_camera_wait_for_event (camera, 10, &evttype, &evtdata, context);
63 	} while ((retval == GP_OK) && (evttype != GP_EVENT_TIMEOUT));
64 
65 	retval = camera_auto_focus(camera, context, 0);
66 	if(retval != GP_OK) {
67 		printf("Error: %s\n", gp_result_as_string(retval));
68 		return 1;
69 	}
70 
71         gp_camera_exit(camera, context);
72         return 0;
73 }
74