From eb02a4c33c530156bf8b96e8e8b6fc6deb53dcf8 Mon Sep 17 00:00:00 2001 From: "B. Bogart" Date: Sat, 21 Mar 2009 01:26:02 +0000 Subject: Wrapped all pd functions with sys_lock() and sys_unlock(). Changed listconfig back to sending a value out for each child, rather than creating a PD list from within the external. svn path=/trunk/externals/bbogart/; revision=10882 --- gphoto/gphoto-help.pd | 31 ++++++++++--------- gphoto/gphoto.c | 85 +++++++++++++++++++++++++-------------------------- 2 files changed, 57 insertions(+), 59 deletions(-) diff --git a/gphoto/gphoto-help.pd b/gphoto/gphoto-help.pd index 79dff2c..a259d9d 100644 --- a/gphoto/gphoto-help.pd +++ b/gphoto/gphoto-help.pd @@ -1,10 +1,9 @@ -#N canvas 0 0 638 970 10; +#N canvas 479 0 638 776 10; #X msg 83 48 getconfig model; #X msg 142 83 getconfig capture; #X msg 167 116 getconfig zoom; #X obj 79 221 print; #X msg 59 21 listconfig; -#X msg 189 147 setconfig capture 0; #X msg 209 183 setconfig capture 1; #X msg 205 218 setconfig capture 2; #X text 336 182 cap on?; @@ -16,16 +15,18 @@ -1 -1; #X msg 266 33 capture test2.jpg; #X obj 86 191 gphoto; -#X connect 0 0 15 0; -#X connect 1 0 15 0; -#X connect 2 0 15 0; -#X connect 4 0 15 0; -#X connect 5 0 15 0; -#X connect 6 0 15 0; -#X connect 7 0 15 0; -#X connect 10 0 15 0; -#X connect 11 0 15 0; -#X connect 12 0 15 0; -#X connect 14 0 15 0; -#X connect 15 0 3 0; -#X connect 15 1 13 0; +#X msg 189 147 getconfig iso; +#X text 281 147 <- does not work.; +#X connect 0 0 14 0; +#X connect 1 0 14 0; +#X connect 2 0 14 0; +#X connect 4 0 14 0; +#X connect 5 0 14 0; +#X connect 6 0 14 0; +#X connect 9 0 14 0; +#X connect 10 0 14 0; +#X connect 11 0 14 0; +#X connect 13 0 14 0; +#X connect 14 0 3 0; +#X connect 14 1 12 0; +#X connect 15 0 14 0; diff --git a/gphoto/gphoto.c b/gphoto/gphoto.c index dab9f80..73ae822 100644 --- a/gphoto/gphoto.c +++ b/gphoto/gphoto.c @@ -60,10 +60,10 @@ void *listConfig(void *threadArgs) { // INIT camera (without context) gp_ret = gp_camera_init (camera, NULL); if (gp_ret != 0) {error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret));} - if (gp_ret == -105) {post("gphoto: Are you sure the camera is supported, connected and powered on?"); gp_camera_unref(camera); return(NULL);} + if (gp_ret == -105) {sys_lock(); post("gphoto: Are you sure the camera is supported, connected and powered on?"); sys_unlock(); gp_camera_unref(camera); return(NULL);} gp_ret = gp_camera_get_config (camera, &config, NULL); // get config from camera - if (gp_ret != 0) {error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); gp_camera_unref(camera); return(NULL);} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock(); gp_camera_unref(camera); return(NULL);} numsections = gp_widget_count_children(config); for (i=0; igphoto->x_obj.ob_outlet, gensym(childName)); sys_unlock(); - - //post("gphoto: Config Child: %s\n", childName); // send through outlet? } } } @@ -94,6 +92,11 @@ void *listConfig(void *threadArgs) { // We are done and other messsages can now be sent. ((gphoto_gimme_struct *)threadArgs)->gphoto->busy = 0; + // Send bang out 2nd outlet when operation is done. + sys_lock(); + outlet_bang(((gphoto_gimme_struct *)threadArgs)->gphoto->doneOutlet); + sys_unlock(); + return(NULL); } @@ -139,35 +142,23 @@ void *getConfig(void *threadArgs) { key = atom_getsymbol( ((gphoto_gimme_struct *)threadArgs)->argv ); // config key gp_ret = gp_camera_new (&camera); - if (gp_ret != 0) {error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); gp_camera_unref(camera); return(NULL);} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock(); gp_camera_unref(camera); return(NULL);} // INIT camera (without context) gp_ret = gp_camera_init (camera, NULL); - if (gp_ret != 0) {error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret));} - if (gp_ret == -105) {post("gphoto: Are you sure the camera is supported, connected and powered on?"); gp_camera_unref(camera); return(NULL);} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock();} + if (gp_ret == -105) {sys_lock(); post("gphoto: Are you sure the camera is supported, connected and powered on?"); sys_unlock(); gp_camera_unref(camera); return(NULL);} gp_ret = gp_camera_get_config (camera, &config, NULL); // get config from camera - if (gp_ret != 0) {error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); gp_camera_unref(camera); return(NULL);} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock(); gp_camera_unref(camera); return(NULL);} gp_ret = gp_widget_get_child_by_name (config, key->s_name, &child); // get item from config - if (gp_ret != 0) {error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret));} - -/* post("types:"); - post("GP_WIDGET_TOGGLE: %d", GP_WIDGET_TOGGLE); - post("GP_WIDGET_TEXT: %d", GP_WIDGET_TEXT); - post("GP_WIDGET_RANGE: %d", GP_WIDGET_RANGE); - post("GP_WIDGET_RADIO: %d", GP_WIDGET_RADIO); - post("GP_WIDGET_MENU: %d", GP_WIDGET_MENU); - post("GP_WIDGET_BUTTON: %d", GP_WIDGET_BUTTON); - post("GP_WIDGET_DATE: %d", GP_WIDGET_DATE); - post("GP_WIDGET_WINDOW: %d", GP_WIDGET_WINDOW); - post("GP_WIDGET_SECTION: %d", GP_WIDGET_SECTION); -*/ + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock(); gp_camera_unref(camera); return(NULL);} gp_ret = gp_widget_get_type (child, &type); if (gp_ret != 0) { - error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); - error("gphoto: Invalid config key."); + sys_lock; error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); + error("gphoto: Invalid config key."); sys_unlock(); } else { switch (type) { case GP_WIDGET_TOGGLE: @@ -243,43 +234,47 @@ void *setConfig(void *threadArgs) { sys_unlock(); gp_ret = gp_camera_new (&camera); - if (gp_ret != 0) {error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret));} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock();} // INIT camera (without context) gp_ret = gp_camera_init (camera, NULL); - if (gp_ret != 0) {error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret));} - if (gp_ret == -105) {error("gphoto: Are you sure the camera is supported, connected and powered on?"); gp_camera_unref(camera); return(NULL);} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock();} + if (gp_ret == -105) {sys_lock(); error("gphoto: Are you sure the camera is supported, connected and powered on?"); sys_unlock(); gp_camera_unref(camera); return(NULL);} gp_ret = gp_camera_get_config (camera, &config, NULL); // get config from camera - if (gp_ret != 0) {error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); gp_camera_unref(camera); return(NULL);} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock(); gp_camera_unref(camera); return(NULL);} gp_ret = gp_widget_get_child_by_name (config, key->s_name, &child); // get item from config - if (gp_ret != 0) {error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); gp_camera_unref(camera); return(NULL);} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock(); gp_camera_unref(camera); return(NULL);} gp_ret = gp_widget_get_type (child, &type); if (gp_ret != 0) { - error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); - error("gphoto: Invalid config key."); + sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); + error("gphoto: Invalid config key."); sys_unlock(); } else { switch (type) { case GP_WIDGET_TOGGLE: + sys_lock(); intValue = atom_getint( ((gphoto_gimme_struct *)threadArgs)->argv+1 ); + sys_unlock(); gp_ret = gp_widget_set_value (child, &intValue); // set widget value - if (gp_ret != 0) {error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret));} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock(); } gp_ret = gp_camera_set_config (camera, config, NULL); // set new config - if (gp_ret != 0) {error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret));} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock(); } break; case GP_WIDGET_RANGE: + sys_lock(); floatValue = atom_getfloat( ((gphoto_gimme_struct *)threadArgs)->argv+1 ); + sys_unlock(); gp_ret = gp_widget_set_value (child, &floatValue); // set widget value - if (gp_ret != 0) {error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret));} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock(); } gp_ret = gp_camera_set_config (camera, config, NULL); // set new config - if (gp_ret != 0) {error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret));} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock(); } break; } @@ -335,31 +330,33 @@ void *captureImage(void *threadArgs) { CameraFile *camerafile; CameraFilePath camera_file_path; t_symbol *filename; - + + sys_lock(); filename = atom_getsymbol( ((gphoto_gimme_struct *)threadArgs)->argv ); // destination filename + sys_unlock(); gp_ret = gp_camera_new (&camera); - if (gp_ret != 0) {error("1gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); gp_camera_unref(camera); return(NULL);} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock(); gp_camera_unref(camera); return(NULL);} // INIT camera (without context) gp_ret = gp_camera_init (camera, NULL); - if (gp_ret != 0) {error("2gphoto: ERROR: %s\n", gp_result_as_string(gp_ret));} - if (gp_ret == -105) {post("gphoto: Are you sure the camera is supported, connected and powered on?"); gp_camera_unref(camera); return(NULL);} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock(); } + if (gp_ret == -105) {sys_lock(); post("gphoto: Are you sure the camera is supported, connected and powered on?"); sys_unlock(); gp_camera_unref(camera); return(NULL);} gp_ret = gp_camera_capture(camera, GP_CAPTURE_IMAGE, &camera_file_path, NULL); - if (gp_ret != 0) {error("3gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); gp_camera_unref(camera); return(NULL);} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock(); gp_camera_unref(camera); return(NULL);} fd = open( filename->s_name, O_CREAT | O_WRONLY, 0644); // create file descriptor gp_ret = gp_file_new_from_fd(&camerafile, fd); // create gphoto file from descriptor - if (gp_ret != 0) {error("4gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); gp_camera_unref(camera); return(NULL);} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock(); gp_camera_unref(camera); return(NULL);} gp_ret = gp_camera_file_get(camera, camera_file_path.folder, camera_file_path.name, GP_FILE_TYPE_NORMAL, camerafile, NULL); // get file from camera - if (gp_ret != 0) {error("5gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); gp_camera_unref(camera); return(NULL);} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock(); gp_camera_unref(camera); return(NULL);} gp_ret = gp_camera_file_delete(camera, camera_file_path.folder, camera_file_path.name, NULL); - if (gp_ret != 0) {error("6gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); gp_camera_unref(camera); return(NULL);} + if (gp_ret != 0) {sys_lock(); error("gphoto: ERROR: %s\n", gp_result_as_string(gp_ret)); sys_unlock(); gp_camera_unref(camera); return(NULL);} // Free memory gp_camera_unref(camera); -- cgit v1.2.1