From: <mar...@us...> - 2011-11-18 10:23:35
|
Revision: 13774 http://gphoto.svn.sourceforge.net/gphoto/?rev=13774&view=rev Author: marcusmeissner Date: 2011-11-18 10:23:28 +0000 (Fri, 18 Nov 2011) Log Message: ----------- new Canon Powershot event handling Modified Paths: -------------- branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/ChangeLog branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/config.c branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/library.c branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/ptp.c branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/ptp.h Modified: branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/ChangeLog =================================================================== --- branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/ChangeLog 2011-11-17 14:11:04 UTC (rev 13773) +++ branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/ChangeLog 2011-11-18 10:23:28 UTC (rev 13774) @@ -1,3 +1,31 @@ +2010-11-17 Marcus Meissner <ma...@je...> + + * config.c, library.c, ptp.c, ptp.h: switch the canon powershot event + handling to be non-interrupt (just using the 0x9013 opcode). + +2010-11-17 Marcus Meissner <ma...@je...> + + * library.c: Replace 20 by 100 tries in EOS preview capturing. + +2010-11-15 Flori Radlherr + + * config.c: Implement a "Immediate" button trigger config on Canon EOS. + + +2010-10-28 Marcus Meissner <ma...@je...> + + * library.c: Speed up initial EOS capture if the event stack was not + drained before. + +2010-10-15 Chris Wulff + + * library.c: Fixed session setup to really use incremental, + from Chris Wulff. + +2010-09-15 Marcus Meissner <ma...@je...> + + * library.c: When querying the thumb, use the direct thumbsize. + 2010-08-08 Marcus Meissner <ma...@je...> * library.c: backported event queue PTP handling from trunk Modified: branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/config.c =================================================================== --- branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/config.c 2011-11-17 14:11:04 UTC (rev 13773) +++ branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/config.c 2011-11-18 10:23:28 UTC (rev 13774) @@ -73,10 +73,9 @@ camera_prepare_canon_powershot_capture(Camera *camera, GPContext *context) { PTPContainer event; PTPPropertyValue propval; - uint16_t val16; - int i, ret, isevent; + int ret; PTPParams *params = &camera->pl->params; - int oldtimeout; + int found, oldtimeout; propval.u16 = 0; ret = ptp_getdevicepropvalue(params, PTP_DPC_CANON_EventEmulateMode, &propval, PTP_DTC_UINT16); @@ -88,6 +87,7 @@ propval.u16=1; ret = ptp_setdevicepropvalue(params, PTP_DPC_CANON_EventEmulateMode, &propval, PTP_DTC_UINT16); + params->canon_event_mode = propval.u16; ret = ptp_getdevicepropvalue(params, PTP_DPC_CANON_SizeOfOutputDataFromCamera, &propval, PTP_DTC_UINT32); gp_log (GP_LOG_DEBUG, "ptp", "prop PTP_DPC_CANON_SizeOfOutputDataFromCamera value is 0x%8x, ret 0x%x",propval.u32, ret); ret = ptp_getdevicepropvalue(params, PTP_DPC_CANON_SizeOfInputDataToCamera, &propval, PTP_DTC_UINT32); @@ -104,6 +104,7 @@ ret = ptp_getdeviceinfo (params, ¶ms->deviceinfo); fixup_cached_deviceinfo (camera, ¶ms->deviceinfo); ret = ptp_getdevicepropvalue(params, PTP_DPC_CANON_EventEmulateMode, &propval, PTP_DTC_UINT16); + params->canon_event_mode = propval.u16; gp_log (GP_LOG_DEBUG, "ptp","prop 0xd045 value is 0x%4x, ret 0x%x",propval.u16,ret); gp_log (GP_LOG_DEBUG, "ptp","Magic code ends."); @@ -118,35 +119,34 @@ 6 No No 7 No Yes */ - propval.u16=4; + propval.u16 = 7; ret = ptp_setdevicepropvalue(params, PTP_DPC_CANON_EventEmulateMode, &propval, PTP_DTC_UINT16); + params->canon_event_mode = propval.u16; CPR (context, ptp_canon_startshootingmode (params)); gp_port_get_timeout (camera->port, &oldtimeout); gp_port_set_timeout (camera->port, 1000); - /* Catch event */ - if (PTP_RC_OK==(val16=params->event_wait (params, &event))) { - if (event.Code==PTP_EC_StorageInfoChanged) - gp_log (GP_LOG_DEBUG, "ptp", "Event: entering shooting mode."); - else - gp_log (GP_LOG_DEBUG, "ptp", "Event: 0x%x", event.Code); - } else { - gp_log (GP_LOG_DEBUG, "ptp", "No event yet, we'll try later."); - } + /* Catch the event telling us the mode was switched ... */ + found = 0; + while (!found) { + ret = ptp_check_event (params); + if (ret != PTP_RC_OK) + break; - /* Emptying event stack */ - for (i=0;i<2;i++) { - ret = ptp_canon_checkevent (params,&event,&isevent); - if (ret != PTP_RC_OK) { - gp_log (GP_LOG_DEBUG, "ptp", "error during check event: %d", ret); + while (ptp_get_one_event (params, &event)) { + gp_log (GP_LOG_DEBUG, "ptp", "Event: 0x%x", event.Code); + if ((event.Code==0xc00c) || + (event.Code==PTP_EC_StorageInfoChanged)) { + gp_log (GP_LOG_DEBUG, "ptp", "Event: Entered shooting mode."); + found = 1; + break; + } } - if (isevent) - gp_log (GP_LOG_DEBUG, "ptp", "evdata: nparam=0x%x, C=0x%x, trans_id=0x%x, p1=0x%x, p2=0x%x, p3=0x%x", - event.Nparam,event.Code,event.Transaction_ID, - event.Param1, event.Param2, event.Param3); + if (!found) usleep(50*1000); } + #if 0 gp_port_set_timeout (camera->port, oldtimeout); if (ptp_operation_issupported(params, PTP_OC_CANON_ViewfinderOn)) { @@ -157,18 +157,7 @@ } gp_port_set_timeout (camera->port, 1000); #endif - /* Catch event, attempt 2 */ - if (val16!=PTP_RC_OK) { - if (PTP_RC_OK==params->event_wait (params, &event)) { - if (event.Code == PTP_EC_StorageInfoChanged) - gp_log (GP_LOG_DEBUG, "ptp","Event: entering shooting mode."); - else - gp_log (GP_LOG_DEBUG, "ptp","Event: 0x%x", event.Code); - } else - gp_log (GP_LOG_DEBUG, "ptp", "No expected mode change event."); - } - /* FIXME: Marcus: wait for the 0xC00C Canon event? also apparently sent by the SX100IS */ /* Reget device info, they change on the Canons. */ ptp_getdeviceinfo(&camera->pl->params, &camera->pl->params.deviceinfo); Modified: branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/library.c =================================================================== --- branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/library.c 2011-11-17 14:11:04 UTC (rev 13773) +++ branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/library.c 2011-11-18 10:23:28 UTC (rev 13774) @@ -2267,7 +2267,7 @@ { static int capcnt = 0; PTPObjectInfo oi; - int found, ret, isevent, timeout, sawcapturecomplete = 0, viewfinderwason = 0; + int found, ret, timeout, sawcapturecomplete = 0, viewfinderwason = 0; PTPParams *params = &camera->pl->params; uint32_t newobject = 0x0; PTPPropertyValue propval; @@ -2333,7 +2333,11 @@ viewfinderwason = 1; params->canon_viewfinder_on = 0; } - ptp_check_event (params); + ret = ptp_check_event (params); + if (ret != PTP_RC_OK) { + gp_context_error (context, _("Canon Capture failed: 0x%04x"), ret); + return translate_ptp_result (ret); + } #if 0 /* FIXME: For now, to avoid flash during debug */ @@ -2342,7 +2346,7 @@ #endif ret = ptp_canon_initiatecaptureinmemory (params); if (ret != PTP_RC_OK) { - gp_context_error (context, _("Canon Capture failed: %x"), ret); + gp_context_error (context, _("Canon Capture failed: 0x%04x"), ret); return translate_ptp_result (ret); } sawcapturecomplete = 0; @@ -2355,22 +2359,17 @@ while (!_timeout_passed(&event_start, capture_timeout)) { /*usleep(100000);*/ gp_context_idle (context); - /* Make sure we do not poll USB interrupts after the capture complete event. - * MacOS libusb 1 has non-timing out interrupts so we must avoid event reads that will not - * result in anything. - */ - if (!sawcapturecomplete && (PTP_RC_OK == params->event_check (params, &event))) { - isevent = 1; - } else -{ - ret = ptp_canon_checkevent (params,&event,&isevent); - if (ret!=PTP_RC_OK) - continue; + ret = ptp_check_event (params); + if (ret != PTP_RC_OK) { + gp_context_error (context, _("Canon Capture failed: 0x%04x"), ret); + return translate_ptp_result (ret); } - /* we sometimes get CaptureComplete only from ptp_canon_checkevent, but perhaps - * also from regular USB events. Just make sure we write it down. */ - if (!isevent) + + if (!ptp_get_one_event (params, &event)) { + /* FIXME: wait a bit? */ + usleep(20*1000); continue; + } gp_log (GP_LOG_DEBUG, "ptp","evdata: nparams=0x%X, code=0x%X, trans_id=0x%X, p1=0x%X, p2=0x%X, p3=0x%X", event.Nparam,event.Code,event.Transaction_ID, event.Param1, event.Param2, event.Param3); switch (event.Code) { case PTP_EC_ObjectAdded: { @@ -2400,16 +2399,17 @@ newobject = event.Param1; gp_log (GP_LOG_DEBUG, "ptp", "PTP_EC_CANON_RequestObjectTransfer, object handle=0x%X.",newobject); + for (j=0;j<2;j++) { - isevent = 0; - ret=ptp_canon_checkevent(params,&event,&isevent); - if ((ret==PTP_RC_OK) && isevent) + ret = ptp_check_event (params); + while (ptp_get_one_event (params, &event) && !sawcapturecomplete) { gp_log (GP_LOG_DEBUG, "ptp", "evdata: L=0x%X, C=0x%X, trans_id=0x%X, p1=0x%X, p2=0x%X, p3=0x%X", event.Nparam,event.Code,event.Transaction_ID, event.Param1, event.Param2, event.Param3); - if (isevent) { - gp_log (GP_LOG_DEBUG, "ptp", "Unhandled canon event: 0x%04x.", event.Code); if (event.Code == PTP_EC_CaptureComplete) sawcapturecomplete = 1; } + if (sawcapturecomplete) + break; + usleep(20*1000); } /* Marcus: Not sure if we really needs this. This refocuses the camera. ret = ptp_canon_reset_aeafawb(params,7); @@ -2426,15 +2426,22 @@ break; } CR (gp_port_set_timeout (camera->port, timeout)); - /* Catch event, attempt 2 */ - if (!sawcapturecomplete) { - if (PTP_RC_OK==params->event_wait (params, &event)) { - if (event.Code==PTP_EC_CaptureComplete) - gp_log (GP_LOG_DEBUG, "ptp", "Event: capture complete(2)."); - else - gp_log (GP_LOG_DEBUG, "ptp", "Event: 0x%X (2)", event.Code); - } else - gp_log (GP_LOG_DEBUG, "ptp", "No expected capture complete event"); + /* wait for capture complete */ + gettimeofday (&event_start, NULL); + while (!sawcapturecomplete && !_timeout_passed(&event_start, capture_timeout)) { + ret = ptp_check_event (params); + if (ret != PTP_RC_OK) + break; + while (ptp_get_one_event (params, &event)) { + gp_log (GP_LOG_DEBUG, "ptp", "Event: 0x%X (2)", event.Code); + if (event.Code == PTP_EC_CaptureComplete) { + sawcapturecomplete = 1; + break; + } + } + if (sawcapturecomplete) + break; + usleep(20*1000); } if (!found) { gp_log (GP_LOG_DEBUG, "ptp","ERROR: Capture timed out!"); Modified: branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/ptp.c =================================================================== --- branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/ptp.c 2011-11-17 14:11:04 UTC (rev 13773) +++ branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/ptp.c 2011-11-18 10:23:28 UTC (rev 13774) @@ -1653,6 +1653,10 @@ return ret; if (isevent) goto store_event; + /* Event Emulate Mode 0 (unset) and 1-5 get interrupt events. 6-7 does not. */ + if (params->canon_event_mode > 5) + return ret; + /* FIXME: fallthrough or return? */ #ifdef __APPLE__ /* the libusb 1 on darwin currently does not like polling Modified: branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/ptp.h =================================================================== --- branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/ptp.h 2011-11-17 14:11:04 UTC (rev 13773) +++ branches/libgphoto2-2_4/libgphoto2/camlibs/ptp2/ptp.h 2011-11-18 10:23:28 UTC (rev 13774) @@ -2125,6 +2125,7 @@ PTPCanon_Property *canon_props; int nrofcanon_props; int canon_viewfinder_on; + int canon_event_mode; /* PTP: Canon EOS event queue */ PTPCanon_changes_entry *backlogentries; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |