summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett Weiland <techcrazybsw@gmail.com>2020-09-20 00:16:46 -0500
committerBrett Weiland <techcrazybsw@gmail.com>2020-09-20 00:16:46 -0500
commit948ab0358bc97ad2b74019309b05f54e67fa2e43 (patch)
tree602d2156eb52abd1cc003ef725aa52b88daf9597
new file: maintain_focus.c
new file: makefile
-rw-r--r--maintain_focus.c78
-rw-r--r--makefile8
2 files changed, 86 insertions, 0 deletions
diff --git a/maintain_focus.c b/maintain_focus.c
new file mode 100644
index 0000000..3835e7e
--- /dev/null
+++ b/maintain_focus.c
@@ -0,0 +1,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);
+
+}
diff --git a/makefile b/makefile
new file mode 100644
index 0000000..c352f29
--- /dev/null
+++ b/makefile
@@ -0,0 +1,8 @@
+CC=gcc
+OUT=capture_focus
+
+make: maintain_focus.c
+ $(CC) maintain_focus.c -lgphoto2 -o $(OUT)
+debug: maintain_focus.c
+ $(CC) maintain_focus.c -lgphoto2 -ggdb -o $(OUT)
+