From ff9c29fd4155c8cece2151a67d938db31cb2ba49 Mon Sep 17 00:00:00 2001 From: Hubert Figuiere Date: Thu, 25 Jul 2002 19:10:46 +0000 Subject: [PATCH] The rest of the work I have done for DC210. I don't think it works. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@4911 67ed7778-7388-44ab-90cf-0a291f65f57c --- camlibs/kodak/dc210/.cvsignore | 7 ++ camlibs/kodak/dc210/dc210.c | 184 +++++++++++++++++++++++---------- camlibs/kodak/dc210/library.c | 52 ++++++++-- camlibs/kodak/dc210/library.h | 7 ++ 4 files changed, 189 insertions(+), 61 deletions(-) create mode 100644 camlibs/kodak/dc210/.cvsignore diff --git a/camlibs/kodak/dc210/.cvsignore b/camlibs/kodak/dc210/.cvsignore new file mode 100644 index 000000000..4e820267f --- /dev/null +++ b/camlibs/kodak/dc210/.cvsignore @@ -0,0 +1,7 @@ +*.la +*.lo +*.o +.libs +.deps +Makefile +Makefile.in diff --git a/camlibs/kodak/dc210/dc210.c b/camlibs/kodak/dc210/dc210.c index 9e719a316..374abfc52 100644 --- a/camlibs/kodak/dc210/dc210.c +++ b/camlibs/kodak/dc210/dc210.c @@ -154,83 +154,144 @@ int camera_init (Camera *camera) int camera_exit (Camera *camera) { + int ret; DC210Data * dd = (DC210Data *)camera->camlib_data; - kodak_dc210_close_camera (dd); + ret = kodak_dc210_close_camera (dd); if (dd->dev) { - if (gp_port_close(dd->dev) == GP_ERROR) - { /* camera did a bad, bad thing */ } + gp_port_close(dd->dev); + if (ret == GP_ERROR) { + gp_debug_printf (GP_DEBUG_LOW, "dc210", + "%s,%d: gp_port_close = %d", + __FILE__, __LINE__, ret); + + } gp_port_free(dd->dev); } free(dd); - return (GP_OK); + return ret; } int camera_folder_list_folders (Camera *camera, const char *folder, CameraList *list) { - return (GP_OK); + /* there is only one folder */ + /* don't list */ + gp_debug_printf (GP_DEBUG_LOW, "dc210", + "%s,%d: camera_folder_list_folders: unimplemented", + __FILE__, __LINE__); + + return (GP_ERROR); } int camera_folder_list_files (Camera *camera, const char *folder, CameraList *list) { - return (GP_OK); -} - -int camera_file_get (Camera *camera, const char *folder, const char *filename, - CameraFileType type, CameraFile *file) -{ - int numPicBefore; - int numPicAfter; - struct Image *im = NULL; - + int ret; DC210Data * dd = (DC210Data *)camera->camlib_data; - if (type != GP_FILE_TYPE_PREVIEW) - return (GP_ERROR_NOT_SUPPORTED); - - /* - * 2001/08/25: Lutz Müller - * What's happening here? We are supposed to get the file or the preview, - * not capturing an image?!? That's totally screwed up... Please fix. - */ - - /* find out how many pictures are in the camera so we can - make sure a picture was taken later */ - numPicBefore = kodak_dc210_number_of_pictures(dd); - - /* take a picture -- it returns the picture number taken */ - numPicAfter = kodak_dc210_capture (dd); - - /* if a picture was taken then get the picture from the camera and - then delete it */ - if (numPicBefore + 1 == numPicAfter) - { - im = kodak_dc210_get_picture (dd, numPicAfter, file); - kodak_dc210_delete_picture (dd, numPicAfter); - } - - return (GP_OK); + ret = kodak_dc210_get_directory_listing (dd, list); +/* gp_debug_printf (GP_DEBUG_LOW, "dc210", + "kodak_dc210_get_picture_info failed %d", ret);*/ + return ret; } + +/* + Possible ops are: + -getPic 0; + -getThumbnail 1; + -delete 2; + */ +static int _camera_file_op (Camera *camera, const char *folder, + const char *filename, CameraFile *file, int op) +{ + int ret = GP_OK; + int count = 0; + int i; + CameraList * list; + const char * current; + DC210Data * dd = (DC210Data *)camera->camlib_data; + + if (!dd) { + gp_debug_printf (GP_DEBUG_LOW, "dc210", "%s,%d: unable to get dd", + __FILE__, __LINE__); + return GP_ERROR; + } + + gp_list_new (&list); + ret = kodak_dc210_get_directory_listing (dd, list); + count = gp_list_count (list); + + for (i = 0; i < count; i++) { + gp_list_get_name (list, i, ¤t); + if (current == NULL) { + /* ERROR */ + ret = GP_ERROR; + break; + } + + if (strcmp (current, filename) == 0) { + /* picture found */ + switch (op) { + case 0: + ret = kodak_dc210_get_picture (dd, i, file); + break; + case 1: + ret = kodak_dc210_get_thumbnail (dd, i, file); + break; + case 2: + ret = kodak_dc210_delete_picture (dd, i); + break; + default: + gp_debug_printf (GP_DEBUG_LOW, "dc210", + "%s,%d: unknown file op = %d", + __FILE__, __LINE__, op); + /* DOH ! */ + break; + } + /* we found our file */ + break; + } + } + gp_list_free (list); + gp_debug_printf (GP_DEBUG_LOW, "dc210", "%s,%d: file op completed = %d", + __FILE__, __LINE__, ret); + return ret; +} + + +/* Get the file */ +int camera_file_get (Camera *camera, const char *folder, const char *filename, + CameraFileType type, CameraFile *file) +{ + switch (type) + { + case GP_FILE_TYPE_NORMAL: + return _camera_file_op (camera, folder, filename, file, 0); + break; + case GP_FILE_TYPE_PREVIEW: + return _camera_file_op (camera, folder, filename, file, 1); + break; + default: + return GP_ERROR_NOT_SUPPORTED; + } +} + + int camera_folder_put_file (Camera *camera, const char *folder, CameraFile *file) { - return (GP_OK); + /* not supported */ + return GP_ERROR; } int camera_file_delete (Camera *camera, const char *folder, const char *filename) { - /* TODO */ - int picNum = 0; - DC210Data * dd = (DC210Data *)camera->camlib_data; - - kodak_dc210_delete_picture (dd, picNum); - return (GP_OK); + return _camera_file_op (camera, folder, filename, NULL, 2); } #if 0 @@ -254,11 +315,30 @@ int camera_config_set (Camera *camera, CameraWidget *window) int camera_capture (Camera *camera, int capture_type, CameraFilePath *path) { - // Capture image/preview/video and return it in 'file'. Don't store it - // anywhere on your camera! If your camera does store the image, - // delete it manually here. - - return (GP_OK); + int ret = GP_OK; + int numPicBefore; + int numPicAfter; + struct kodak_dc210_picture_info picInfo; + DC210Data * dd = (DC210Data *)camera->camlib_data; + + /* find out how many pictures are in the camera so we can + make sure a picture was taken later */ + numPicBefore = kodak_dc210_number_of_pictures(dd); + + /* take a picture -- it returns the picture number taken */ + numPicAfter = kodak_dc210_capture (dd); + + /* if a picture was taken then get the picture from the camera and + then delete it */ + if (numPicBefore + 1 == numPicAfter) + { + strcpy (path->folder, "/"); + ret = kodak_dc210_get_picture_info (dd, numPicAfter, &picInfo); + strncpy (path->name, picInfo.fileName, 12); + path->name[12] = 0; + } + + return ret; } int camera_summary (Camera *camera, CameraText *summary) diff --git a/camlibs/kodak/dc210/library.c b/camlibs/kodak/dc210/library.c index c2f31ef51..5fdfb7199 100644 --- a/camlibs/kodak/dc210/library.c +++ b/camlibs/kodak/dc210/library.c @@ -36,7 +36,9 @@ static int kodak_dc210_read (DC210Data * dd, unsigned char *buf, int nbytes); static int kodak_dc210_write_byte (DC210Data * dd, char b); static unsigned char kodak_dc210_checksum(char *packet,int length); - +static int kodak_dc210_set_port_speed(DC210Data * dd, int speed); +static int kodak_dc210_command_complete (DC210Data * dd); +static int kodak_dc210_read_packet (DC210Data * dd, char *packet, int length); static int kodak_dc210_send_command (DC210Data * dd, char command, char arg1, char arg2, char arg3, char arg4) { @@ -87,7 +89,7 @@ static int kodak_dc210_send_command (DC210Data * dd, char command, char arg1, ch tell the camera to change the port speed, then set it. */ -int kodak_dc210_set_port_speed(DC210Data * dd, int speed) +static int kodak_dc210_set_port_speed(DC210Data * dd, int speed) { int success = 0; int arg1, arg2; @@ -139,7 +141,7 @@ int kodak_dc210_set_port_speed(DC210Data * dd, int speed) } -int kodak_dc210_command_complete (DC210Data * dd) +static int kodak_dc210_command_complete (DC210Data * dd) { int status = DC_BUSY; int success = TRUE; @@ -188,7 +190,7 @@ static int kodak_dc210_write_byte (DC210Data * dd, char b ) return (gp_port_read(dd->dev, &b, 1)); } -int kodak_dc210_read_packet (DC210Data * dd, char *packet, int length) +static int kodak_dc210_read_packet (DC210Data * dd, char *packet, int length) { int success = TRUE; unsigned char sent_checksum; @@ -311,7 +313,7 @@ int kodak_dc210_capture(DC210Data * dd) return kodak_dc210_number_of_pictures(dd); } -static int kodak_dc210_get_picture_info (DC210Data * dd, +int kodak_dc210_get_picture_info (DC210Data * dd, int picNum, struct kodak_dc210_picture_info *picInfo) { @@ -467,7 +469,8 @@ int kodak_dc210_get_thumbnail (DC210Data * dd, int picNum, CameraFile *file) } gp_file_append (file, imData, fileSize + 54); - gp_file_set_type (file, "image/bmp"); + gp_file_set_mime_type (file, GP_MIME_BMP); + gp_file_set_type (file, GP_FILE_TYPE_PREVIEW); strncpy(file->name, picInfo.fileName, 12); file->name[12] = 0; } @@ -498,6 +501,7 @@ int kodak_dc210_get_picture (DC210Data * dd, int picNum, CameraFile *file) int numBytes; struct kodak_dc210_picture_info picInfo; char *picData; + char name [13]; /* get information (size, name, etc) about the picture */ kodak_dc210_get_picture_info (dd, picNum, &picInfo); @@ -532,9 +536,11 @@ int kodak_dc210_get_picture (DC210Data * dd, int picNum, CameraFile *file) fprintf(stderr,"%d/%d\n",numRead,fileSize); kodak_dc210_command_complete (dd); - strcpy(file->type, "image/jpeg"); - strncpy(file->name, picInfo.fileName, 12); - file->name[12] = 0; + gp_file_set_mime_type (file, GP_MIME_JPEG); + gp_file_set_type (file, GP_FILE_TYPE_NORMAL); + strncpy (name, picInfo.fileName, 12); + name[12] = 0; + gp_file_set_name (file, name); return GP_OK; } @@ -548,6 +554,34 @@ int kodak_dc210_delete_picture (DC210Data * dd, int picNum) return (1); } +/* + By default all image on DC210 are in \DCIMAGES. So well list + all the pictures as if they where on a flat file system. + */ +int kodak_dc210_get_directory_listing (DC210Data *dd, CameraList *list) +{ + int ret = GP_OK; + int num, i; + struct kodak_dc210_picture_info picInfo; + char fileName [13]; + + num = kodak_dc210_number_of_pictures (dd); + for (i = 0; i < num; i++) { + ret = kodak_dc210_get_picture_info (dd, i, &picInfo); + if (ret == GP_OK) { + strncpy (fileName, picInfo.fileName, 12); + fileName[12] = 0; + gp_list_append(list, fileName, NULL); + } + else { + gp_debug_printf (GP_DEBUG_LOW, "dc210", + "kodak_dc210_get_picture_info failed %d", ret); + break; + } + } + return ret; +} + #if 0 struct Image *kodak_dc210_get_preview () diff --git a/camlibs/kodak/dc210/library.h b/camlibs/kodak/dc210/library.h index 4cd1b3f6d..498500256 100644 --- a/camlibs/kodak/dc210/library.h +++ b/camlibs/kodak/dc210/library.h @@ -27,7 +27,9 @@ #define DC_COMMAND_ACK 0xD1 #define DC_CORRECT_PACKET 0xD2 #define DC_COMMAND_NAK 0xE1 +#define DC_COMMAND_EXEC_ERROR 0xE2 #define DC_ILLEGAL_PACKET 0xE3 +#define DC_CANCEL 0xE4 #define DC_BUSY 0xF0 /* Kodak System Commands */ @@ -86,8 +88,13 @@ struct kodak_dc210_picture_info { int kodak_dc210_open_camera (DC210Data * dd); int kodak_dc210_close_camera (DC210Data * dd); +int kodak_dc210_get_picture_info (DC210Data * dd, + int picNum, + struct kodak_dc210_picture_info *picInfo); int kodak_dc210_get_picture (DC210Data * dd, int picNum, CameraFile *file); +int kodak_dc210_get_thumbnail (DC210Data * dd, int picNum, CameraFile *file); int kodak_dc210_number_of_pictures (DC210Data * dd); +int kodak_dc210_get_directory_listing (DC210Data *dd, CameraList *list); int kodak_dc210_capture (DC210Data * dd); int kodak_dc210_delete_picture (DC210Data * dd, int picNum);