#include #include #include #include #include #include #include #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 **/ 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) { 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) { printw("Error modifying camera widget: %s\n", gp_result_as_string(err)); return(2); } } int main() { 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_near[3] = {0, 0, 0}; unsigned int focal_far[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 printw("Initilizing camera...\n"); refresh(); if ((err = gp_camera_init(cam, context)) != 0) { printw("Couldn't connect to camera: %s\n", gp_result_as_string(err)); refresh(); 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, &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("Near 3:\t\t%i\nNear 2:\t\t%i\nNear 1:\t\t%i\nFar 3:\t\t%i\nFar 2:\t\t%i\nFar 1:\t\t%i\n", focal_near[2], focal_near[1], focal_near[0], focal_far[2], focal_far[1], focal_far[0]); refresh(); flushinp(); switch(getch()) { case 'q': focal_near[2]++; set_widget_value(focus_widget, "Near 3", FOCUS_WIDGET_NAME, cam, context); usleep(500000); break; case 'w': focal_near[1]++; set_widget_value(focus_widget, "Near 2", FOCUS_WIDGET_NAME, cam, context); usleep(250000); break; case 'e': focal_near[0]++; set_widget_value(focus_widget, "Near 1", FOCUS_WIDGET_NAME, cam, context); usleep(125000); break; case 'a': focal_far[2]++; set_widget_value(focus_widget, "Far 3", FOCUS_WIDGET_NAME, cam, context); usleep(500000); break; case 's': focal_far[1]++; set_widget_value(focus_widget, "Far 2", FOCUS_WIDGET_NAME, cam, context); usleep(250000); break; case 'd': focal_far[0]++; set_widget_value(focus_widget, "Far 1", FOCUS_WIDGET_NAME, cam, context); usleep(125000); 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"); for(; focal_near[2] >= 1; focal_near[2]--) { set_widget_value(focus_widget, "Near 3", FOCUS_WIDGET_NAME, cam, context); usleep(500000); } for(; focal_near[1] >= 1; focal_near[1]--) { set_widget_value(focus_widget, "Near 2", FOCUS_WIDGET_NAME, cam, context); usleep(250000); } for(; focal_near[0] >= 1; focal_near[0]--) { set_widget_value(focus_widget, "Near 1", FOCUS_WIDGET_NAME, cam, context); usleep(125000); } for(; focal_far[2] >= 1; focal_far[2]--) { set_widget_value(focus_widget, "Far 3", FOCUS_WIDGET_NAME, cam, context); usleep(500000); } for(; focal_far[1] >= 1; focal_far[1]--) { set_widget_value(focus_widget, "Far 2", FOCUS_WIDGET_NAME, cam, context); usleep(250000); } for(; focal_far[0] >= 1; focal_far[0]--) { set_widget_value(focus_widget, "Far 1", FOCUS_WIDGET_NAME, cam, context); usleep(125000); } printw("Done!\n"); user_conf(); endwin(); gp_camera_exit(cam, context); return(0); }