From ac650d65b065faaec76b8327e493757344195cc9 Mon Sep 17 00:00:00 2001 From: Brett Weiland Date: Sun, 20 Sep 2020 17:36:04 -0500 Subject: modified: maintain_focus.c modified: makefile --- maintain_focus.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 93 insertions(+), 11 deletions(-) (limited to 'maintain_focus.c') diff --git a/maintain_focus.c b/maintain_focus.c index 3835e7e..dd90038 100644 --- a/maintain_focus.c +++ b/maintain_focus.c @@ -4,6 +4,7 @@ #include #include #include +#include #define FOCUS_WIDGET_NAME "manualfocusdrive" #define VIEWFINDER_WIDGET_NAME "viewfinder" @@ -24,37 +25,53 @@ gp_camera_new(&camera); <- point to return value **/ - +void user_conf() { + printw("\nPress enter to continue.\n"); + refresh(); + getchar(); +} 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)); + printw("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)); + printw("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... + char focus_state[8] = "None"; + int user_focusing = 1; + int toggle = 1; //wish there was a better way to do this... + int key; int err; + unsigned int focal_distance[3] = {0, 0, 0}; + Camera *cam; CameraWidget *widget_root; CameraWidget *focus_widget; CameraWidget *liveview_widget; + + initscr(); + cbreak(); + noecho(); + + char *key_help_msg = "Press [q] [w] [e] to focus closer, [q] moving the fastest.\nPress [a] [s] [d] to focus further, [a] being the fastest.\nPress [Q] when done.\n"; GPContext *context = gp_context_new(); gp_camera_new(&cam); //start up and connect to camera - printf("Initilizing camera...\n"); + printw("Initilizing camera...\n"); + refresh(); if ((err = gp_camera_init(cam, context)) != 0) { - printf("Couldn't connect to camera: %s\n", gp_result_as_string(err)); + printw("Couldn't connect to camera: %s\n", gp_result_as_string(err)); + refresh(); return(1); } @@ -65,14 +82,79 @@ int main() { 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); + set_widget_value(liveview_widget, &toggle, VIEWFINDER_WIDGET_NAME, cam, context); + printw("\nCamera now connected.\nOn the camera, manually focus all the way to the left. Turn on autofocus when done.\n"); + user_conf(); - + /** + * Left: far + * Right: near + * Powerful: 3 + * There's a lot of limitations, such as not knowing when we've hit the limit. We'll just have to depend on the user (me!) for that. + * We also don't know how much "Near/Far 3" is compared to "Near/Far 1". + */ + while(user_focusing) { + clear(); + printw("%s", key_help_msg); + printw("Level 3:\t\t%i\nLevel 2:\t\t%i\nLevel 1:\t\t%i\n", focal_distance[2], focal_distance[1], focal_distance[0]); + refresh(); + switch(getch()) { + case 'q': + focal_distance[2]++; + set_widget_value(focus_widget, "Near 3", FOCUS_WIDGET_NAME, cam, context); + break; + case 'w': + focal_distance[1]++; + set_widget_value(focus_widget, "Near 2", FOCUS_WIDGET_NAME, cam, context); + break; + case 'e': + focal_distance[0]++; + set_widget_value(focus_widget, "Near 1", FOCUS_WIDGET_NAME, cam, context); + break; + case 'a': + if(focal_distance[2] > 0) { + focal_distance[2]--; + set_widget_value(focus_widget, "Far 3", FOCUS_WIDGET_NAME, cam, context); + } + break; + case 's': + if(focal_distance[1] > 0) { + focal_distance[1]--; + set_widget_value(focus_widget, "Far 2", FOCUS_WIDGET_NAME, cam, context); + } + break; + case 'd': + if(focal_distance[0] > 0) { + focal_distance[0]--; + set_widget_value(focus_widget, "Far 1", FOCUS_WIDGET_NAME, cam, context); + } + break; + case 'Q': + user_focusing = 0; + break; + default: + break; + } + } + clear(); + printw("Focal length saved, put on the filter now. You can turn off autofocus.\n"); + user_conf(); + + clear(); + printw("Manually focus all the way to left, then turn on autofocus.\n"); + user_conf(); + + clear(); + printw("Restoring focus...\n"); + printw("Done!\n"); + user_conf(); + + endwin(); gp_camera_exit(cam, context); + - - return(1); + return(0); } -- cgit v1.2.3