diff --git a/camlibs/canon/usb.c b/camlibs/canon/usb.c index 475f08589..1e1915d0a 100644 --- a/camlibs/canon/usb.c +++ b/camlibs/canon/usb.c @@ -226,40 +226,89 @@ canon_usb_init (Camera *camera) } /** - * canon_usb_keylock: + * canon_usb_lock_keys: * @camera: camera to lock keys on * @Returns: gphoto2 error code * * Lock the keys on the camera and turn off the display **/ int -canon_usb_keylock (Camera *camera) +canon_usb_lock_keys (Camera *camera) { unsigned char *c_res; int bytes_read; + char payload[4]; - GP_DEBUG ("canon_usb_keylock()"); + GP_DEBUG ("canon_usb_lock_keys()"); - /* Check for cameras that do not need this command */ - if (camera->pl->model == CANON_PS_S100) { - GP_DEBUG ("Your camera model does not need the keylock."); - return GP_OK; + switch (camera->pl->model) { + case CANON_PS_S100: + GP_DEBUG ("canon_usb_lock_keys: Your camera model does not need the keylock."); + break; + case CANON_EOS_D30: + memset (payload, 0, sizeof (payload)); + payload[0] = 0x06; + + c_res = canon_usb_dialogue (camera, CANON_USB_FUNCTION_EOS_LOCK_KEYS, + &bytes_read, payload, 4); + if (!c_res) + return GP_ERROR; + + break; + default: + c_res = canon_usb_dialogue (camera, + CANON_USB_FUNCTION_GENERIC_LOCK_KEYS, + &bytes_read, NULL, 0); + if (bytes_read == 0x4) { + GP_DEBUG ("canon_usb_lock_keys: Got the expected number of bytes back, " "unfortuntely we don't know what they mean."); + } else { + gp_camera_set_error (camera, "canon_usb_lock_keys: " + "Unexpected amount of data returned (%i bytes, expected %i)", + bytes_read, 0x4); + return GP_ERROR; + } + break; } - if (camera->pl->model == CANON_EOS_D30) { - GP_DEBUG ("Key locking is currently not working on EOS D30 cameras. Stay tuned."); - return GP_OK; - } - - c_res = canon_usb_dialogue (camera, CANON_USB_FUNCTION_KEYLOCK, &bytes_read, NULL, 0); - if (bytes_read == 0x4) { - GP_DEBUG ("Got the expected number of bytes back, " - "unfortuntely we don't know what they mean."); - } else { - gp_camera_set_error (camera, "canon_usb_keylock: " - "Unexpected amount of data returned (%i bytes, expected %i)", - bytes_read, 0x4); - return GP_ERROR_IO; + return GP_OK; +} + +/** + * canon_usb_unlock_keys: + * @camera: camera to unlock keys on + * @Returns: gphoto2 error code + * + * Unlocks the keys on cameras that support this + **/ +int +canon_usb_unlock_keys (Camera *camera) +{ + unsigned char *c_res; + int bytes_read; + char payload[4]; + + GP_DEBUG ("canon_usb_unlock_keys()"); + + switch (camera->pl->model) { + case CANON_EOS_D30: + memset (payload, 0, sizeof (payload)); + payload[0] = 0x06; + + c_res = canon_usb_dialogue (camera, CANON_USB_FUNCTION_EOS_UNLOCK_KEYS, + &bytes_read, NULL, 0); + /* Should look at the bytes returned, but I don't know what they mean */ + if (! c_res) + return GP_ERROR; + + break; + default: + /* Your camera model does not need unlocking, cannot do unlocking or + * we don't know how to unlock it's keys. If unlocking works when + * using the Windows software with your camera, please contact + * + */ + GP_DEBUG ("canon_usb_unlock_keys: Not unlocking the kind of camera you have."); + break; } return GP_OK; @@ -272,6 +321,9 @@ canon_usb_keylock (Camera *camera) * @return_length: number of bytes to read from the camera as response * @payload: data we are to send to the camera * @payload_length: length of #payload + * @Returns: a char * that points to the data read from the camera (or + * NULL on failure), and sets what @return_length points to to the number + * of bytes read. * * USB version of the #canon_serial_dialogue function. * @@ -753,7 +805,7 @@ canon_usb_ready (Camera *camera) return GP_ERROR; } - res = canon_usb_keylock (camera); + res = canon_usb_lock_keys (camera); if (res != GP_OK) { gp_camera_set_error (camera, "Camera not ready, " "could not lock camera keys (returned %i)", res); @@ -771,4 +823,3 @@ canon_usb_ready (Camera *camera) return GP_OK; } - diff --git a/camlibs/canon/usb.h b/camlibs/canon/usb.h index 45aaa497c..049eabd17 100644 --- a/camlibs/canon/usb.h +++ b/camlibs/canon/usb.h @@ -25,7 +25,8 @@ int canon_usb_long_dialogue (Camera *camera, int canon_funct, unsigned char **da int payload_length, int display_status); int canon_usb_get_file (Camera *camera, const char *name, unsigned char **data, int *length); int canon_usb_get_thumbnail (Camera *camera, const char *name, unsigned char **data, int *length); -int canon_usb_keylock(Camera *camera); +int canon_usb_lock_keys(Camera *camera); +int canon_usb_unlock_keys(Camera *camera); int canon_usb_get_dirents (Camera *camera, unsigned char **dirent_data, unsigned int *dirents_length, const char *path); int canon_usb_ready (Camera *camera); @@ -46,7 +47,9 @@ int canon_usb_ready (Camera *camera); #define CANON_USB_FUNCTION_SET_ATTR 13 /* GET_PIC_ABILITIES currently not implemented in gPhoto2 camlibs/canon driver */ #define CANON_USB_FUNCTION_GET_PIC_ABILITIES 14 -#define CANON_USB_FUNCTION_KEYLOCK 15 +#define CANON_USB_FUNCTION_GENERIC_LOCK_KEYS 15 +#define CANON_USB_FUNCTION_EOS_LOCK_KEYS 16 +#define CANON_USB_FUNCTION_EOS_UNLOCK_KEYS 17 struct canon_usb_cmdstruct { @@ -71,8 +74,10 @@ static const struct canon_usb_cmdstruct canon_usb_cmd[] = { {CANON_USB_FUNCTION_GET_DIRENT, "Get directory entrys", 0x0b, 0x11, 0x202, 0x40}, {CANON_USB_FUNCTION_DELETE_FILE, "Delete file", 0x0d, 0x11, 0x201, 0x54}, {CANON_USB_FUNCTION_SET_ATTR, "Set file attribute", 0x0e, 0x11, 0x201, 0x54}, + {CANON_USB_FUNCTION_EOS_LOCK_KEYS, "EOS lock keys", 0x1b, 0x12, 0x201, 0x54}, + {CANON_USB_FUNCTION_EOS_UNLOCK_KEYS, "EOS unlock keys", 0x1c, 0x12, 0x201, 0x54}, {CANON_USB_FUNCTION_GET_PIC_ABILITIES, "Get picture abilities", 0x1f, 0x12, 0x201, 0x384}, - {CANON_USB_FUNCTION_KEYLOCK, "Lock keys and turn off LCD", 0x20, 0x12, 0x201, 0x54}, + {CANON_USB_FUNCTION_GENERIC_LOCK_KEYS, "Lock keys and turn off LCD", 0x20, 0x12, 0x201, 0x54}, { 0 } };