1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <gphoto2/gphoto2.h>
#include <time.h>
#define FOCUS_WIDGET_NAME "manualfocusdrive"
#define VIEWFINDER_WIDGET_NAME "viewfinder"
/**
gp_widget_set_value(CameraWidget*, const void) <-sets value
gp_widget_get_child_by_label(CameraWidget* widget, const char* label, CameraWidget ** child) <- child is widget
gp_camera_get_config(Camera* camera, CameraWidget **window, GpContext* context) <- window is parent
camera_init(Camera* camera, GPContext *context)
Create context:
context = gp_context_new();
gp_context_set_error_func (context, ctx_error_func, NULL);
gp_context_set_status_func (context, ctx_status_func, NULL);
Create camera:
gp_camera_new(&camera); <- point to return value
**/
int set_widget_value(CameraWidget *widget, void *widget_value, const char *widget_name, Camera *camera, GPContext *context) {
int err;
if ((err = gp_widget_set_value(widget, widget_value)) != 0) {
printf("Error setting local widget value: %s\nThis is not the hardware\'s fault. Fix your code!\n", gp_result_as_string(err));
return(1);
}
if((err = gp_camera_set_single_config(camera, widget_name, widget, context)) != 0) {
printf("Error modifying camera widget: %s\n", gp_result_as_string(err));
return(2);
}
}
int main() {
char *focus_large_temp = "Near 3";
int viewfinder_state = 1; //wish there was a better way to do this...
int err;
Camera *cam;
CameraWidget *widget_root;
CameraWidget *focus_widget;
CameraWidget *liveview_widget;
GPContext *context = gp_context_new();
gp_camera_new(&cam);
//start up and connect to camera
printf("Initilizing camera...\n");
if ((err = gp_camera_init(cam, context)) != 0) {
printf("Couldn't connect to camera: %s\n", gp_result_as_string(err));
return(1);
}
//get configuration tree
gp_camera_get_config(cam, &widget_root, context);
//get child widgets
gp_widget_get_child_by_name(widget_root, FOCUS_WIDGET_NAME, &focus_widget);
gp_widget_get_child_by_name(widget_root, VIEWFINDER_WIDGET_NAME, &liveview_widget);
//set to liveview so we can ajust focus
set_widget_value(liveview_widget, &viewfinder_state, VIEWFINDER_WIDGET_NAME, cam, context);
gp_camera_exit(cam, context);
return(1);
}
|