From 07b1ceedc1178c8031fa7e9580e9c9ebbb30ca52 Mon Sep 17 00:00:00 2001 From: Lutz Mueller Date: Wed, 14 Mar 2001 21:29:22 +0000 Subject: [PATCH] Better error reporting. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@1749 67ed7778-7388-44ab-90cf-0a291f65f57c --- camlibs/sierra/library.c | 674 ++++++++++++++---------------- camlibs/sierra/library.h | 7 +- camlibs/sierra/sierra.c | 877 +++++++++++++++++++++------------------ camlibs/sierra/sierra.h | 1 - 4 files changed, 794 insertions(+), 765 deletions(-) diff --git a/camlibs/sierra/library.c b/camlibs/sierra/library.c index 761bd794f..f67ecf59d 100644 --- a/camlibs/sierra/library.c +++ b/camlibs/sierra/library.c @@ -7,62 +7,12 @@ #define QUICKSLEEP 5 -void sierra_dump_packet (Camera *camera, char *packet) { - - int x, length=0; - char buf[4096], msg[4096]; - SierraData *fd = (SierraData*)camera->camlib_data; - - return; - - if ((packet[0] == TYPE_COMMAND) || - (packet[0] == TYPE_DATA) || - (packet[0] == TYPE_DATA_END)) { - length = ((unsigned char)packet[2]) + - ((unsigned char)packet[3] * 256); - length += 6; - } else { - switch((unsigned char)packet[0]) { - case NUL: - strcpy(buf, " packet: NUL"); - break; - case ENQ: - strcpy(buf, " packet: ENQ"); - break; - case ACK: - strcpy(buf, " packet: ACK"); - break; - case DC1: - strcpy(buf, " packet: DC1"); - break; - case NAK: - strcpy(buf, " packet: NAK (Camera Signature)"); - break; - case TRM: - strcpy(buf, " packet: TRM"); - break; - default: - sprintf(buf, " packet: 0x%02x (UNKNOWN!)", packet[0]); - } - sierra_debug_print(fd, buf); - return; - } - sprintf(msg, " packet length: %i", length); - sierra_debug_print(fd, msg); - if (length > 256) - length = 256; - strcpy(msg, " packet: "); - for (x=0; xcamlib_data; + + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* sierra_valid_packet"); if ((packet[0] == TYPE_COMMAND) || (packet[0] == TYPE_DATA) || (packet[0] == TYPE_DATA_END)) { + + /* ??? */ length = ((unsigned char)packet[2]) + ((unsigned char)packet[3] * 256); length += 6; - } else { - switch((unsigned char)packet[0]) { - case NUL: - case ENQ: - case ACK: - case DC1: - case NAK: - case TRM: - return (GP_OK); - break; - default: - return (GP_ERROR); - } - } - sierra_debug_print(fd, "VALID_PACKET NOT DONE FOR DATA PACKETS!"); - return (GP_ERROR); + return (GP_ERROR); + } + + switch((unsigned char)packet[0]) { + case NUL: + case ENQ: + case ACK: + case DC1: + case NAK: + case TRM: + return (GP_OK); + default: + return (GP_ERROR); + } } int sierra_write_packet (Camera *camera, char *packet) { @@ -111,9 +62,7 @@ int sierra_write_packet (Camera *camera, char *packet) { int x, ret, r, checksum=0, length; SierraData *fd = (SierraData*)camera->camlib_data; - sierra_debug_print(fd, " sierra_write_packet"); - -// usleep(QUICKSLEEP); + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* sierra_write_packet"); /* Determing packet length */ if ((packet[0] == TYPE_COMMAND) || @@ -134,127 +83,114 @@ int sierra_write_packet (Camera *camera, char *packet) { packet[length-1]= (checksum >> 8) & 0xff; } - sierra_dump_packet(camera, packet); + /* USB */ + if (fd->type == GP_PORT_USB) + return (gp_port_write (fd->dev, packet, length)); - /* For USB support */ - if (fd->type == GP_PORT_USB) { - return (gp_port_write(fd->dev, packet, length)); + /* SERIAL */ + for (r = 0; r < RETRIES; r++) { + + ret = gp_port_write (fd->dev, packet, length); + if (ret == GP_ERROR_IO_TIMEOUT) + continue; + + return (ret); } - r=0; - x=0; - while (xdev, &packet[x], 1); - - switch (ret) { - case GP_OK: - r=0; /* reset retries */ - x++; /* next byte */ - break; - case GP_ERROR_TIMEOUT: - if (r++ > RETRIES) - return (ret); - sierra_debug_print(fd, " write timed out. trying again."); - break; - default: - return (ret); - } - } - - return (GP_OK); + return (GP_ERROR_IO_TIMEOUT); } int sierra_read_packet (Camera *camera, char *packet) { - int y, r=0, ret, done, length=0; + int y, r = 0, ret, done, length=0; int blocksize, bytes_read; char buf[4096]; SierraData *fd = (SierraData*)camera->camlib_data; + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* sierra_read_packet"); + read_packet_again: buf[0] = 0; packet[0] = 0; - sierra_debug_print(fd, " sierra_read_packet"); - -// usleep(QUICKSLEEP); + if (r > 0) + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* reading again..."); done = 0; if (fd->type == GP_PORT_USB) gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_ENDPOINT_IN); - while (!done && (r++type) { - case GP_PORT_USB: - blocksize = 2054; - break; - case GP_PORT_SERIAL: - blocksize = 1; - break; - default: - return (GP_ERROR_IO_UNKNOWN_PORT); - } - bytes_read = gp_port_read(fd->dev, packet, blocksize); - - - if (bytes_read == GP_ERROR) { - sierra_debug_print(fd, " read error (packet type)"); - return (GP_ERROR); - } - if (sierra_valid_type(packet[0])==GP_OK) - done = 1; - if (r>RETRIES) { - sierra_debug_print(fd, " read error (too many retries on packet type)"); - return (GP_ERROR); - } - - /* Determine the packet type */ - if ((packet[0] == TYPE_COMMAND) || - (packet[0] == TYPE_DATA) || - (packet[0] == TYPE_DATA_END)) { - /* It's a response/command packet */ - if (fd->type == GP_PORT_SERIAL) { - bytes_read = gp_port_read(fd->dev, &packet[1], 3); - if (bytes_read == GP_ERROR) { - sierra_debug_print(fd, " read error (header)"); - return (GP_ERROR); - } - bytes_read = 4; - } - /* Determine the packet length */ - length = ((unsigned char)packet[2]) + - ((unsigned char)packet[3] * 256); - length += 6; - } else { - /* It's a single byte response. dump and validate */ - sierra_dump_packet(camera, packet); - - if (fd->type == GP_PORT_USB) - gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_ENDPOINT_IN); - - return (sierra_valid_packet(camera, packet)); - } - for (y=bytes_read; y < length; y+=blocksize) { - ret = gp_port_read(fd->dev, &packet[y], blocksize); - if (ret == GP_ERROR_TIMEOUT) { - sierra_write_nak(camera); - goto read_packet_again; - } - - if (ret ==GP_ERROR) - return (GP_ERROR); - } + + switch (fd->type) { + case GP_PORT_USB: + blocksize = 2054; + break; + case GP_PORT_SERIAL: + blocksize = 1; + break; + default: + return (GP_ERROR_IO_UNKNOWN_PORT); + } + + for (r = 0; r < RETRIES; r++) { + + bytes_read = gp_port_read (fd->dev, packet, blocksize); + if (bytes_read == GP_ERROR_IO_TIMEOUT) + continue; + if (bytes_read < 0) + return (bytes_read); + + ret = sierra_valid_type (packet[0]); + if (ret == GP_OK) + done = 1; + + /* Determine the packet type */ + if (!((packet[0] == TYPE_COMMAND) || + (packet[0] == TYPE_DATA) || + (packet[0] == TYPE_DATA_END))) { + if (fd->type == GP_PORT_USB) + gp_port_usb_clear_halt (fd->dev, + GP_PORT_USB_ENDPOINT_IN); + return (sierra_valid_packet (camera, packet)); + } + + /* It's a response/command packet */ + if (fd->type == GP_PORT_SERIAL) { + bytes_read = gp_port_read (fd->dev, + &packet[1], 3); + if (bytes_read < 0) + return (bytes_read); + + bytes_read = 4; + } + + /* Determine the packet length */ + length = ((unsigned char)packet[2]) + + ((unsigned char)packet[3] * 256); + length += 6; + + for (y = bytes_read; y < length; y += blocksize) { + + ret = gp_port_read (fd->dev, &packet[y], blocksize); + if (ret == GP_ERROR_IO_TIMEOUT) { + sierra_write_nak (camera); + goto read_packet_again; + } + if (ret < 0) + return (ret); + } + + if (done) break; } - sierra_dump_packet(camera, packet); if (fd->type == GP_PORT_USB) gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_ENDPOINT_IN); - return (GP_OK); + return (GP_ERROR_IO_TIMEOUT); } -int sierra_build_packet (Camera *camera, char type, char subtype, int data_length, char *packet) { - +int sierra_build_packet (Camera *camera, char type, char subtype, + int data_length, char *packet) +{ SierraData *fd = (SierraData*)camera->camlib_data; packet[0] = type; @@ -274,7 +210,8 @@ int sierra_build_packet (Camera *camera, char type, char subtype, int data_lengt packet[1] = subtype; break; default: - sierra_debug_print(fd, "unknown packet type"); + gp_debug_printf (GP_DEBUG_HIGH, "sierra", + "* unknown packet type!"); } packet[2] = data_length & 0xff; @@ -283,14 +220,14 @@ int sierra_build_packet (Camera *camera, char type, char subtype, int data_lengt return (GP_OK); } -int sierra_write_ack(Camera *camera) { - +int sierra_write_ack (Camera *camera) +{ char buf[4096]; SierraData *fd = (SierraData*)camera->camlib_data; int ret; - sierra_debug_print(fd, " sierra_write_ack"); - + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* sierra_write_ack"); + buf[0] = ACK; ret = sierra_write_packet (camera, buf); if (fd->type == GP_PORT_USB) @@ -298,13 +235,13 @@ int sierra_write_ack(Camera *camera) { return (ret); } -int sierra_write_nak(Camera *camera) { - +int sierra_write_nak (Camera *camera) +{ char buf[4096]; SierraData *fd = (SierraData*)camera->camlib_data; int ret; - sierra_debug_print(fd, " sierra_write_nak"); + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* sierra_write_nack"); buf[0] = NAK; ret = sierra_write_packet (camera, buf); @@ -313,44 +250,49 @@ int sierra_write_nak(Camera *camera) { return (ret); } -int sierra_ping(Camera *camera) { - - int r=0; +int sierra_ping (Camera *camera) +{ + int ret, r = 0; char buf[4096]; - SierraData *fd = (SierraData*)camera->camlib_data; + + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* sierra_ping"); buf[0] = NUL; + for (r = 0; r < RETRIES; r++) { - while (r++ < RETRIES) { - sierra_debug_print(fd, "pinging the camera"); - if (sierra_write_packet(camera, buf)==GP_ERROR) - return (GP_ERROR); + ret = sierra_write_packet (camera, buf); + if (ret == GP_ERROR_IO_TIMEOUT) + continue; + if (ret != GP_OK) + return (ret); - if (sierra_read_packet(camera, buf)==GP_ERROR) - return (GP_ERROR); + ret = sierra_read_packet (camera, buf); + if (ret == GP_ERROR_IO_TIMEOUT) + continue; + if (ret != GP_OK) + return (ret); - if (buf[0] == NAK) { - sierra_debug_print(fd, "ping succeeded"); + if (buf[0] == NAK) return (GP_OK); - } - sierra_debug_print(fd, "ping failed"); + else + return (GP_ERROR_CORRUPTED_DATA); + } - return (GP_ERROR); + return (GP_ERROR_IO_TIMEOUT); } -int sierra_set_speed (Camera *camera, int speed) { - +int sierra_set_speed (Camera *camera, int speed) +{ gp_port_settings settings; - char buf[1024]; SierraData *fd = (SierraData*)camera->camlib_data; int ret; - sprintf(buf, "Setting speed to %i", speed); - sierra_debug_print(fd, buf); + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* sierra_set_speed"); + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* speed: %i", speed); fd->first_packet = 1; - gp_port_settings_get(fd->dev, &settings); + gp_port_settings_get (fd->dev, &settings); switch (speed) { case 9600: @@ -395,21 +337,21 @@ int sierra_set_speed (Camera *camera, int speed) { return (GP_OK); } -int sierra_set_int_register (Camera *camera, int reg, int value) { - +int sierra_set_int_register (Camera *camera, int reg, int value) +{ int r=0; char p[4096]; char buf[4096]; - SierraData *fd = (SierraData*)camera->camlib_data; int ret; - sprintf(buf, "Setting register #%i to %i", reg, value); - sierra_debug_print(fd, buf); + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* sierra_set_int_register"); + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* register: %i", reg); + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* value: %i", value); if (value < 0) - sierra_build_packet(camera, TYPE_COMMAND, 0, 2, p); + sierra_build_packet (camera, TYPE_COMMAND, 0, 2, p); else - sierra_build_packet(camera, TYPE_COMMAND, 0, 6, p); + sierra_build_packet (camera, TYPE_COMMAND, 0, 6, p); /* Fill in the data */ p[4] = 0x00; @@ -421,14 +363,17 @@ int sierra_set_int_register (Camera *camera, int reg, int value) { p[9] = (value>>24) & 0xff; } - while (r++camlib_data; int ret; - sprintf(buf, "Getting register #%i value", reg); - sierra_debug_print(fd, buf); + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* sierra_get_int_register"); + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* register: %i", reg); - sierra_build_packet(camera, TYPE_COMMAND, 0, 2, packet); + ret = sierra_build_packet (camera, TYPE_COMMAND, 0, 2, packet); + if (ret != GP_OK) + return (ret); /* Fill in the data */ packet[4] = 0x01; @@ -473,7 +417,7 @@ int sierra_get_int_register (Camera *camera, int reg, int *value) { return (ret); } - if (sierra_read_packet(camera, buf)==GP_ERROR) + if (sierra_read_packet (camera, buf)==GP_ERROR) return (GP_ERROR); /* DC1 = invalid register or value */ @@ -492,20 +436,21 @@ int sierra_get_int_register (Camera *camera, int reg, int *value) { } } - sierra_debug_print(fd, "too many retries"); return (GP_ERROR); } -int sierra_set_string_register (Camera *camera, int reg, char *s, int length) { +int sierra_set_string_register (Camera *camera, int reg, char *s, int length) +{ char packet[4096], buf[4096]; char type; unsigned char c; int x=0, seq=0, size=0, done, r; - SierraData *fd = (SierraData*)camera->camlib_data; - sprintf(buf, "Setting string in register #%i to \"%s\"", reg, s); - sierra_debug_print(fd, buf); + gp_debug_printf (GP_DEBUG_HIGH, "sierra", + "* sierra_set_string_register"); + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* register: %i", reg); + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* value: %s", s); while (x < length) { if (x==0) { @@ -551,7 +496,6 @@ int sierra_set_string_register (Camera *camera, int reg, char *s, int length) { } if (r > RETRIES) { - sierra_debug_print(fd, "too many NAKs from camera"); return (GP_ERROR); } } @@ -561,15 +505,18 @@ int sierra_set_string_register (Camera *camera, int reg, char *s, int length) { int sierra_get_string_register (Camera *camera, int reg, int file_number, CameraFile *file, char *s, int *length) { - char packet[4096], buf[2048]; + char packet[4096]; int done, x, packlength, do_percent, l; - SierraData *fd = (SierraData*)camera->camlib_data; int ret; - sprintf(buf, "Getting string in register #%i", reg); - sierra_debug_print(fd, buf); + gp_debug_printf (GP_DEBUG_HIGH, "sierra", + "* sierra_get_string_register"); + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* register: %i", reg); + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* file number: %i", + file_number); do_percent = 1; + /* Set the current picture number */ if (file_number >= 0) { @@ -579,31 +526,35 @@ int sierra_get_string_register (Camera *camera, int reg, int file_number, } switch (reg) { - case 14: - /* Get the size of the current image */ - if (sierra_get_int_register(camera, 12, &l)==GP_ERROR) - return (GP_ERROR); + case 14: + /* Get the size of the current image */ + ret = sierra_get_int_register(camera, 12, &l); + if (ret != GP_OK) + return (ret); - break; - case 15: - /* Get the size of the current thumbnail */ - if (sierra_get_int_register(camera, 13, &l)==GP_ERROR) - return (GP_ERROR); - break; - case 44: - /* Get the size of the current audio */ - /* will do */ - break; - default: - do_percent = 0; + break; + case 15: + + /* Get the size of the current thumbnail */ + ret = sierra_get_int_register(camera, 13, &l); + if (ret != GP_OK) + return (ret); + + break; + case 44: + /* Get the size of the current audio will do */ + break; + default: + do_percent = 0; } /* Send request */ - sierra_build_packet(camera, TYPE_COMMAND, 0, 2, packet); + sierra_build_packet (camera, TYPE_COMMAND, 0, 2, packet); packet[4] = 0x04; packet[5] = reg; - if (sierra_write_packet(camera, packet)==GP_ERROR) - return (GP_ERROR); + ret = sierra_write_packet (camera, packet); + if (ret != GP_OK) + return (ret); /* Read all the data packets */ x=0; done=0; @@ -637,7 +588,8 @@ int sierra_get_string_register (Camera *camera, int reg, int file_number, /* transferred by using gp_file_chunk */ if (do_percent) - gp_frontend_progress(camera, file, (float)(100.0*(float)x/(float)(l))); + gp_frontend_progress (camera, file, + (float)(100.0*(float)x/(float)(l))); } x += packlength; @@ -649,18 +601,19 @@ int sierra_get_string_register (Camera *camera, int reg, int file_number, return (GP_OK); } -int sierra_delete(Camera *camera, int picture_number) { - +int sierra_delete (Camera *camera, int picture_number) +{ char packet[4096], buf[4096]; int r, done; - SierraData *fd = (SierraData*)camera->camlib_data; int ret; + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* sierra_delete"); + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* picture: %i", + picture_number); + ret = sierra_set_int_register (camera, 4, picture_number); - if (ret != GP_OK) { - sierra_debug_print(fd, "Can not set current image"); + if (ret != GP_OK) return (ret); - } sierra_build_packet(camera, TYPE_COMMAND, 0, 3, packet); packet[4] = 0x02; @@ -684,10 +637,8 @@ int sierra_delete(Camera *camera, int picture_number) { } } - if (r > RETRIES) { - sierra_debug_print(fd, "too many NAKs from camera"); + if (r > RETRIES) return (GP_ERROR); - } GP_SYSTEM_SLEEP(QUICKSLEEP); @@ -699,7 +650,8 @@ int sierra_end_session(Camera *camera) { char packet[4096], buf[4096]; unsigned char c; int r, done; - SierraData *fd = (SierraData*)camera->camlib_data; + + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* sierra_end_session"); sierra_build_packet(camera, TYPE_COMMAND, 0, 3, packet); packet[4] = 0x02; @@ -728,10 +680,8 @@ int sierra_end_session(Camera *camera) { return ((c==ENQ)? GP_OK : GP_ERROR); } } - if (r > RETRIES) { - sierra_debug_print(fd, "too many NAKs from camera"); + if (r > RETRIES) return (GP_ERROR); - } return (GP_OK); } @@ -739,10 +689,9 @@ int sierra_end_session(Camera *camera) { int sierra_file_count (Camera *camera) { int value; - SierraData *fd = (SierraData*)camera->camlib_data; int ret; - - sierra_debug_print(fd, "Counting files"); + + gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* sierra_file_count"); ret = sierra_get_int_register (camera, 10, &value); if (ret != GP_OK) @@ -751,118 +700,123 @@ int sierra_file_count (Camera *camera) { return (value); } -#if 0 -int sierra_capture (Camera *camera, CameraFile *file, CameraCaptureInfo *info) { - +static int do_capture (Camera *camera, char *packet) +{ SierraData *fd = (SierraData*)camera->camlib_data; - int r, done, retval, picnum; - char packet[4096], buf[8]; - unsigned char c; - struct tm *t; - time_t tt; + char buf[8]; + int r, ret, done; + unsigned char c = 0; - if (info == NULL) return (GP_ERROR_BAD_PARAMETERS); - - switch (info->type) { - case GP_CAPTURE_IMAGE: - - /* Take a picture */ - sierra_build_packet(camera, TYPE_COMMAND, 0, 3, packet); - packet[4] = 0x02; - packet[5] = 0x02; - packet[6] = 0x00; - break; + for (r = 0; r < RETRIES; r++) { - case GP_CAPTURE_PREVIEW: + ret = sierra_write_packet (camera, packet); + if (ret != GP_OK) + return (ret); - /* Take a quick preview */ - sierra_build_packet(camera, TYPE_COMMAND, 0, 3, packet); - packet[4] = 0x02; - packet[5] = 0x05; - packet[6] = 0x00; - break; - - default: - return (GP_ERROR_BAD_PARAMETERS); - } - - r=0; done=0; - while ((!done)&&(r++= RETRIES) { - sierra_debug_print(fd, "too many NAKs from camera"); - return (GP_ERROR); - } - r = 0;done=0; - while ((!done)&&(r++dev, buf, 1); - switch(retval) { - case GP_ERROR: - return (GP_ERROR); - break; - case GP_ERROR_TIMEOUT: - break; - default: - done = 1; - } + ret = gp_port_read (fd->dev, buf, 1); + if (ret == GP_ERROR_IO_TIMEOUT) + continue; + if (ret != GP_OK) + return (ret); + + done = 1; + c = (unsigned char)buf[0]; - gp_frontend_progress(camera, file, 0.0); - } - if ((r >= RETRIES) || (c!=ENQ)) - return (GP_ERROR); - - switch (info->type) { - case GP_CAPTURE_IMAGE: - - /* After picture is taken, register 4 is set to current picture */ - if (sierra_get_int_register(camera, 4, &picnum)==GP_ERROR) - return (GP_ERROR); - - /* Retrieve the just-taken picture */ - if (sierra_get_string_register(camera, 14, picnum, file, NULL, NULL)==GP_ERROR) - return (GP_ERROR); - - /* Delete the just-taken picture */ - if (sierra_delete(camera, picnum)==GP_ERROR) - return (GP_ERROR); - break; - - case GP_CAPTURE_PREVIEW: - - /* Retrieve the quick preview */ - if (sierra_get_string_register(camera, 14, 0, file, NULL, NULL)==GP_ERROR) - return (GP_ERROR); - break; - - default: - return (GP_ERROR_BAD_PARAMETERS); + if (done) + break; } - tt = time(&tt); - t = gmtime(&tt); + if (r == RETRIES) + return (GP_ERROR_IO_TIMEOUT); - /* fix it :P */ - if (t->tm_year < 1900) - t->tm_year += 1900; - - sprintf(file->name, "%04i%02i%02i-%02i%02i%02i.jpg", - t->tm_year, t->tm_mon, t->tm_mday, - t->tm_hour, t->tm_min, t->tm_sec); + if (c != ENQ) + return (GP_ERROR_CORRUPTED_DATA); + + return (GP_OK); +} + + + +int sierra_capture_preview (Camera *camera, CameraFile *file) +{ + int ret; + char packet[4096]; + + if (file == NULL) + return (GP_ERROR_BAD_PARAMETERS); + + ret = sierra_build_packet (camera, TYPE_COMMAND, 0, 3, packet); + if (ret != GP_OK) + return (ret); + + packet[4] = 0x02; + packet[5] = 0x05; + packet[6] = 0x00; + + ret = do_capture (camera, packet); + gp_frontend_progress (camera, file, 0.0); + if (ret != GP_OK) + return (ret); + + /* Retrieve the quick preview */ + ret = sierra_get_string_register (camera, 14, 0, file, NULL, NULL); + if (ret != GP_OK) + return (ret); + + return (GP_OK); +} + +int sierra_capture (Camera *camera, int capture_type, CameraFilePath *filepath) +{ + int ret, picnum; + char packet[4096]; + + if (filepath == NULL) + return (GP_ERROR_BAD_PARAMETERS); + if (capture_type != GP_OPERATION_CAPTURE_IMAGE) + return (GP_ERROR_NOT_SUPPORTED); + + ret = sierra_build_packet (camera, TYPE_COMMAND, 0, 3, packet); + if (ret != GP_OK) + return (ret); + + packet[4] = 0x02; + packet[5] = 0x02; + packet[6] = 0x00; + + ret = do_capture (camera, packet); + if (ret != GP_OK) + return (ret); + + /* After picture is taken, register 4 is set to current picture */ + ret = sierra_get_int_register (camera, 4, &picnum); + if (ret != GP_OK) + return (ret); + + //FIXME: Where is the picture stored?!? return (GP_OK); } -#endif diff --git a/camlibs/sierra/library.h b/camlibs/sierra/library.h index f488728fc..709c18031 100644 --- a/camlibs/sierra/library.h +++ b/camlibs/sierra/library.h @@ -18,7 +18,6 @@ #define RETRIES 10 /* Packet functions */ -void sierra_dump_packet (Camera *camera, char *packet); int sierra_valid_packet (Camera *camera, char *packet); int sierra_write_packet (Camera *camera, char *packet); int sierra_read_packet (Camera *camera, char *packet); @@ -39,6 +38,6 @@ int sierra_get_string_register (Camera *camera, int reg, int file_number, int sierra_folder_set (Camera *camera, const char *folder); int sierra_file_count (Camera *camera); int sierra_delete (Camera *camera, int picture_number); -#if 0 -int sierra_capture (Camera *camera, CameraFile *file, CameraCaptureInfo *info); -#endif +int sierra_capture (Camera *camera, int capture_type, + CameraFilePath *filepath); +int sierra_capture_preview (Camera *camera, CameraFile *file); diff --git a/camlibs/sierra/sierra.c b/camlibs/sierra/sierra.c index df8d827dc..7a5c1d5d9 100644 --- a/camlibs/sierra/sierra.c +++ b/camlibs/sierra/sierra.c @@ -11,11 +11,6 @@ int camera_start(Camera *camera); int camera_stop(Camera *camera); -void sierra_debug_print(SierraData *fd, char *message) -{ - gp_debug_printf(GP_DEBUG_LOW, "sierra", message); -} - int camera_id (CameraText *id) { strcpy(id->text, "sierra"); @@ -82,6 +77,7 @@ SierraCamera sierra_cameras[] = { {"Olympus C-1400L", 0, 0, 0, 0 }, {"Olympus C-1400XL", 0, 0, 0, 0 }, {"Olympus C-2000Z", 0, 0, 0, 0 }, + {"Olympus C-2020Z", 0, 0, 0, 0 }, {"Olympus C-2040Z", 0x07b4, 0x105, 0x83, 0x04}, {"Olympus C-2500Z", 0, 0, 0, 0 }, {"Olympus C-3000Z", 0x07b4, 0x100, 0x83, 0x04}, @@ -117,7 +113,8 @@ int camera_abilities (CameraAbilitiesList *list) a->speed[3] = 57600; a->speed[4] = 115200; a->speed[5] = 0; - a->operations = GP_OPERATION_CAPTURE_IMAGE; + a->operations = GP_OPERATION_CAPTURE_IMAGE | + GP_OPERATION_CAPTURE_PREVIEW; a->file_operations = GP_FILE_OPERATION_DELETE | GP_FILE_OPERATION_PREVIEW; a->folder_operations = GP_FOLDER_OPERATION_NONE; @@ -136,169 +133,196 @@ int camera_init (Camera *camera) int value=0, count; int x=0, ret; int vendor=0, product=0, inep=0, outep=0; - gp_port_settings settings; SierraData *fd; - if (!camera) - return (GP_ERROR); + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** camera_init"); + if (!camera) + return (GP_ERROR_BAD_PARAMETERS); + /* First, set up all the function pointers */ - camera->functions->id = camera_id; - camera->functions->abilities = camera_abilities; - camera->functions->init = camera_init; - camera->functions->exit = camera_exit; - camera->functions->folder_list_folders = camera_folder_list_folders; - camera->functions->folder_list_files = camera_folder_list_files; - camera->functions->file_get = camera_file_get; - camera->functions->file_get_preview = camera_file_get_preview; - camera->functions->file_delete = camera_file_delete; -// camera->functions->capture = camera_capture; - camera->functions->summary = camera_summary; - camera->functions->manual = camera_manual; - camera->functions->about = camera_about; + camera->functions->id = camera_id; + camera->functions->abilities = camera_abilities; + camera->functions->init = camera_init; + camera->functions->exit = camera_exit; + camera->functions->folder_list_folders = camera_folder_list_folders; + camera->functions->folder_list_files = camera_folder_list_files; + camera->functions->file_get = camera_file_get; + camera->functions->file_get_preview = camera_file_get_preview; + camera->functions->file_delete = camera_file_delete; + camera->functions->capture_preview = camera_capture_preview; + camera->functions->capture = camera_capture; + camera->functions->summary = camera_summary; + camera->functions->manual = camera_manual; + camera->functions->about = camera_about; fd = (SierraData*)malloc(sizeof(SierraData)); camera->camlib_data = fd; fd->first_packet = 1; - sierra_debug_print(fd, "Initializing camera"); - switch (camera->port->type) { - case GP_PORT_SERIAL: - sierra_debug_print(fd, "Serial Device"); - if ((ret = gp_port_new(&(fd->dev), GP_PORT_SERIAL)) < 0) { - free(fd); - return (ret); - } - strcpy(settings.serial.port, camera->port->path); - settings.serial.speed = 19200; - settings.serial.bits = 8; - settings.serial.parity = 0; - settings.serial.stopbits = 1; - break; - case GP_PORT_USB: - /* lookup the USB information */ - while (strlen(sierra_cameras[x].model)>0) { - if (strcmp(sierra_cameras[x].model, camera->model)==0) { - vendor = sierra_cameras[x].usb_vendor; - product = sierra_cameras[x].usb_product; - inep = sierra_cameras[x].usb_inep; - outep = sierra_cameras[x].usb_outep; - } - x++; - } - - /* Couldn't find the usb information */ - if ((vendor == 0) && (product == 0)) - return (GP_ERROR); - - sierra_debug_print(fd, "USB Device"); - if ((ret = gp_port_new(&(fd->dev), GP_PORT_USB)) < 0) { - free(fd); - return (GP_ERROR); - } - - if ((ret = gp_port_usb_find_device(fd->dev, vendor, product)) < 0) { - gp_port_free(fd->dev); - free (fd); - return (ret); - } - gp_port_timeout_set (fd->dev, 5000); - settings.usb.inep = inep; - settings.usb.outep = outep; - settings.usb.config = 1; - settings.usb.interface = 0; - settings.usb.altsetting = 0; - break; - default: - sierra_debug_print(fd, "Invalid Device"); + case GP_PORT_SERIAL: + ret = gp_port_new (&(fd->dev), GP_PORT_SERIAL); + if (ret != GP_OK) { free (fd); - return (GP_ERROR); + return (ret); + } + + strcpy (settings.serial.port, camera->port->path); + settings.serial.speed = 19200; + settings.serial.bits = 8; + settings.serial.parity = 0; + settings.serial.stopbits = 1; + break; + case GP_PORT_USB: + + /* Lookup the USB information */ + for (x = 0; strlen (sierra_cameras[x].model) > 0; x++) { + if (strcmp(sierra_cameras[x].model, camera->model)==0) { + vendor = sierra_cameras[x].usb_vendor; + product = sierra_cameras[x].usb_product; + inep = sierra_cameras[x].usb_inep; + outep = sierra_cameras[x].usb_outep; + } + } + + /* Couldn't find the usb information */ + if ((vendor == 0) && (product == 0)) + return (GP_ERROR); + + ret = gp_port_new (&(fd->dev), GP_PORT_USB); + if (ret != GP_OK) { + free (fd); + return (ret); + } + + ret = gp_port_usb_find_device (fd->dev, vendor, product); + if (ret != GP_OK) { + gp_port_free (fd->dev); + free (fd); + return (ret); + } + + gp_port_timeout_set (fd->dev, 5000); + settings.usb.inep = inep; + settings.usb.outep = outep; + settings.usb.config = 1; + settings.usb.interface = 0; + settings.usb.altsetting = 0; + break; + default: + free (fd); + return (GP_ERROR_IO_UNKNOWN_PORT); } - if ((ret = gp_port_settings_set(fd->dev, settings)) < 0) { - gp_port_free(fd->dev); + ret = gp_port_settings_set (fd->dev, settings); + if (ret != GP_OK) { + gp_port_free (fd->dev); free (fd); return (ret); } - gp_port_timeout_set(fd->dev, TIMEOUT); + gp_port_timeout_set (fd->dev, TIMEOUT); fd->type = camera->port->type; - if ((ret = gp_port_open(fd->dev)) < 0) { - gp_port_free(fd->dev); + ret = gp_port_open (fd->dev); + if (ret != GP_OK) { + gp_port_free (fd->dev); free (fd); return (ret); } switch (camera->port->type) { - case GP_PORT_SERIAL: - if (sierra_ping(camera) < 0) { - gp_port_free(fd->dev); - free (fd); - return (GP_ERROR); - } + case GP_PORT_SERIAL: - if (sierra_set_speed(camera, camera->port->speed) < 0) { - gp_port_free(fd->dev); - free (fd); - return (GP_ERROR); - } - fd->speed = camera->port->speed; - break; - case GP_PORT_USB: - gp_port_usb_clear_halt(fd->dev, GP_PORT_USB_ENDPOINT_IN); - break; - default: - break; + ret = sierra_ping (camera); + if (ret != GP_OK) { + gp_port_free (fd->dev); + free (fd); + return (ret); + } + + ret = sierra_set_speed (camera, camera->port->speed); + if (ret != GP_OK) { + gp_port_free (fd->dev); + free (fd); + return (ret); + } + + fd->speed = camera->port->speed; + break; + case GP_PORT_USB: + gp_port_usb_clear_halt (fd->dev, GP_PORT_USB_ENDPOINT_IN); + break; + default: + break; } - if (sierra_get_int_register(camera, 1, &value)< 0) { + ret = sierra_get_int_register (camera, 1, &value); + if (ret != GP_OK) { gp_port_free(fd->dev); free (fd); - return (GP_ERROR); + return (ret); } - sierra_set_int_register(camera, 83, -1); + ret = sierra_set_int_register (camera, 83, -1); + if (ret != GP_OK) { + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** Could not set " + "register 83 to -1: %s", + gp_camera_get_result_as_string (camera, ret)); + } - gp_port_timeout_set(fd->dev, 50); - if (sierra_set_string_register(camera, 84, "\\", 1)< 0) + ret = gp_port_timeout_set (fd->dev, 50); + if (ret != GP_OK) + return (ret); + + /* Folder support? */ + ret = sierra_set_string_register (camera, 84, "\\", 1); + if (ret != GP_OK) { fd->folders = 0; - else - fd->folders = 1; + gp_debug_printf (GP_DEBUG_LOW, "sierra", + "*** folder support: no"); + } else { + fd->folders = 1; + gp_debug_printf (GP_DEBUG_LOW, "sierra", + "*** folder support: yes"); + } - if (fd->folders) - sierra_debug_print(fd, "Camera supports folders"); - else - sierra_debug_print(fd, "Camera doesn't support folders. " - "Using CameraFilesystem emu."); + fd->fs = gp_filesystem_new (); + count = sierra_file_count (camera); + if (count < 0) + return (count); - fd->fs = gp_filesystem_new(); - count = sierra_file_count(camera); /* Populate the filesystem */ - gp_filesystem_populate(fd->fs, "/", "PIC%04i.jpg", count); + ret = gp_filesystem_populate (fd->fs, "/", "PIC%04i.jpg", count); + if (ret != GP_OK) + return (ret); - strcpy(fd->folder, "/"); + strcpy (fd->folder, "/"); - gp_port_timeout_set(fd->dev, TIMEOUT); + ret = gp_port_timeout_set (fd->dev, TIMEOUT); + if (ret != GP_OK) + return (ret); - camera_stop(camera); + camera_stop (camera); return (GP_OK); } -static int sierra_change_folder(Camera *camera, const char *folder) +static int sierra_change_folder (Camera *camera, const char *folder) { SierraData *fd = (SierraData*)camera->camlib_data; - - int st=0,i = 1; + int st = 0,i = 1, ret; char target[128]; + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** sierra_change_folder"); + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** folder: %s", folder); + if (!fd->folders) return GP_OK; - if (!folder) - return GP_ERROR; + if (!folder || !camera) + return GP_ERROR_BAD_PARAMETERS; if (folder[0]) { strncpy(target, folder, sizeof(target)-1); @@ -307,64 +331,70 @@ static int sierra_change_folder(Camera *camera, const char *folder) } else strcpy(target, "/"); - if (target[0] != '/') { - sierra_debug_print(fd, "Change dir called with relative path?"); + if (target[0] != '/') i = 0; - } else { - if (sierra_set_string_register(camera, 84, "\\", 1)< 0) - return GP_ERROR; + else { + ret = sierra_set_string_register (camera, 84, "\\", 1); + if (ret != GP_OK) + return (ret); } st = i; for (; target[i]; i++) { if (target[i] == '/') { target[i] = '\0'; - if (st == i-1) + if (st == i - 1) break; - if (sierra_set_string_register(camera, 84, target+st, strlen(target+st))< 0) - return GP_ERROR; - st = i+1; + ret = sierra_set_string_register (camera, 84, + target + st, strlen (target + st)); + if (ret != GP_OK) + return (ret); + st = i + 1; target[i] = '/'; } } - strcpy(fd->folder, folder); - + strcpy (fd->folder, folder); return GP_OK; } -int camera_start(Camera *camera) +int camera_start (Camera *camera) { SierraData *fd = (SierraData*)camera->camlib_data; + int ret; + + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** camera_start"); + + if (fd->type != GP_PORT_SERIAL) + return (GP_OK); - if (fd->type == GP_PORT_SERIAL) { - if (sierra_set_speed(camera, fd->speed)< 0) - return (GP_ERROR); - sierra_folder_set(camera, fd->folder); - } - return (GP_OK); + ret = sierra_set_speed (camera, fd->speed); + if (ret != GP_OK) + return (ret); + + return (sierra_folder_set (camera, fd->folder)); } -int camera_stop(Camera *camera) +int camera_stop (Camera *camera) { SierraData *fd = (SierraData*)camera->camlib_data; - if (fd->type == GP_PORT_SERIAL) { - if (sierra_set_speed(camera, -1)< 0) - return (GP_ERROR); - } + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** camera_stop"); - return (GP_OK); + if (fd->type != GP_PORT_SERIAL) + return (GP_OK); + + return (sierra_set_speed (camera, -1)); } int camera_exit (Camera *camera) { - SierraData *fd = (SierraData*)camera->camlib_data; +// SierraData *fd = (SierraData*)camera->camlib_data; - sierra_debug_print(fd, "Exiting camera"); + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** camera_exit"); - gp_port_close(fd->dev); - gp_port_free(fd->dev); - free(fd); +// gp_port_close (fd->dev); +// gp_port_free (fd->dev); +// free (fd); return (GP_OK); } @@ -373,410 +403,457 @@ int camera_folder_list_files (Camera *camera, const char *folder, CameraList *list) { SierraData *fd = (SierraData*)camera->camlib_data; - int x=0, error=0, count; + int x=0, count, ret; - if ((!fd->folders)&&(strcmp("/", folder)!=0)) + gp_debug_printf (GP_DEBUG_LOW, "sierra", + "*** camera_folder_list_files"); + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** folder: %s", folder); + + if ((!fd->folders) && (strcmp ("/", folder) != 0)) return (GP_ERROR); - if (camera_start(camera)< 0) - return (GP_ERROR); + ret = camera_start (camera); + if (ret != GP_OK) + return (ret); if (fd->folders) { - if (sierra_change_folder(camera, folder)) - return (GP_ERROR); + ret = sierra_change_folder (camera, folder); + if (ret != GP_OK) + return (ret); } - count = sierra_file_count(camera); + count = sierra_file_count (camera); + if (count < 0) + return (count); - while ((x 0) { + /* Filename supported. Use the camera filename */ - gp_list_append(list, buf, GP_LIST_FILE); + gp_list_append (list, buf, GP_LIST_FILE); gp_filesystem_append (fd->fs, folder, buf); + } else { + /* Filename not supported. Use CameraFileSystem entry */ - gp_list_append(list, gp_filesystem_name(fd->fs, folder, x), - GP_LIST_FILE); + gp_list_append (list, gp_filesystem_name (fd->fs, + folder, x), GP_LIST_FILE); } - x++; } - camera_stop(camera); - return GP_OK; + camera_stop (camera); + + return (GP_OK); } int camera_folder_list_folders (Camera *camera, const char *folder, CameraList *list) { SierraData *fd = (SierraData*)camera->camlib_data; - int count, i, bsize; + int count, i, bsize, ret; char buf[1024]; - sierra_debug_print(fd, "Listing folders"); + gp_debug_printf (GP_DEBUG_LOW, "sierra", + "*** camera_folder_list_folders"); + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** folder: %s", folder); - if ((!fd->folders)&&(strcmp(folder, "/")!=0)) + if ((!fd->folders) && (strcmp (folder, "/") !=0 )) return GP_ERROR; if (!fd->folders) return GP_OK; - if (camera_start(camera) != GP_OK) /* XXX */ - return GP_ERROR; + ret = camera_start (camera); + if (ret != GP_OK) + return (ret); - if ((sierra_change_folder(camera, folder) != GP_OK) || - (sierra_get_int_register(camera, 83, &count) != GP_OK)) { - camera_stop(camera); - return GP_ERROR; + ret = sierra_change_folder (camera, folder); + if (ret != GP_OK) { + camera_stop (camera); + return (ret); } - if (count) + + ret = sierra_get_int_register (camera, 83, &count); + if (ret != GP_OK) { + camera_stop (camera); + return (ret); + } + for (i = 0; i < count; i++) { - if (sierra_change_folder(camera, folder) != GP_OK) { - break; - } - if (sierra_set_int_register(camera, 83, i+1) != GP_OK) { - break; - } - bsize = 1024; - if (sierra_get_string_register(camera, 84, 0, NULL, buf, &bsize) != GP_OK) { - break; - } else { - /* remove trailing spaces */ - for (i = strlen(buf)-1; i >= 0 && buf[i] == ' '; i--) - buf[i]='\0'; - /* append the folder name on to the folder list */ - gp_list_append(list, buf, GP_LIST_FOLDER); - } + ret = sierra_change_folder (camera, folder); + if (ret != GP_OK) + break; + + ret = sierra_set_int_register (camera, 83, i+1); + if (ret != GP_OK) + break; + + bsize = 1024; + ret = sierra_get_string_register (camera, 84, 0, NULL, buf, + &bsize); + if (ret != GP_OK) + break; + + /* remove trailing spaces */ + for (i = strlen (buf)-1; i >= 0 && buf[i] == ' '; i--) + buf[i]='\0'; + + /* append the folder name on to the folder list */ + gp_list_append (list, buf, GP_LIST_FOLDER); } - camera_stop(camera); + + camera_stop (camera); return (GP_OK); } -int sierra_folder_set(Camera *camera, const char *folder) +int sierra_folder_set (Camera *camera, const char *folder) { - char buf[4096]; char tf[4096]; SierraData *fd = (SierraData*)camera->camlib_data; - /* If the camera doesn't support folders and it was passed something - other than "/", return an error! */ - if ((!fd->folders)&&(strcmp("/", folder)!=0)) - return (GP_ERROR); + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** sierra_folder_set"); + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** folder: %s"); - /* If the camera doesn't support folders and it was passed "/", - then that's OK */ - if ((!fd->folders)&&(strcmp("/", folder)==0)) - return (GP_OK); - - if (folder[0] != '/') { - strcat(tf, folder); - } else { - strcpy(tf, folder); + if (!fd->folders) { + if (strcmp ("/", folder) != 0) + return (GP_ERROR_DIRECTORY_NOT_FOUND); + else + return (GP_OK); } - if (tf[strlen(fd->folder)-1] != '/') - strcat(tf, "/"); + if (folder[0] != '/') + strcat (tf, folder); + else + strcpy (tf, folder); - printf(buf, "Folder set to %s", tf); + if (tf[strlen (fd->folder) - 1] != '/') + strcat (tf, "/"); /* TODO: check whether the selected folder is valid. It should be done after implementing camera_lock/unlock pair */ - if (fd->folders) { - if (sierra_change_folder(camera, tf)) - return (GP_ERROR); - } - - return (GP_OK); + return (sierra_change_folder (camera, tf)); } int camera_file_get_generic (Camera *camera, CameraFile *file, const char *folder, const char *filename, int thumbnail) { - char buf[4096]; - int regl, regd, file_number; + int regl, regd, file_number, ret; SierraData *fd = (SierraData*)camera->camlib_data; -if (camera_start(camera)< 0) -return (GP_ERROR); + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** sierra_file_get_generic"); + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** folder: %s", folder); + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** filename: %s", filename); + + ret = camera_start(camera); + if (ret != GP_OK) + return (ret); /* Get the file number from the CameraFileSystem */ file_number = gp_filesystem_number(fd->fs, folder, filename); - if (file_number < 0) - return GP_ERROR; + return (file_number); if (thumbnail) { - sprintf(buf, "Getting thumbnail \"%s\" (#%i)", filename, file_number+1); regl = 13; regd = 15; } else { - sprintf(buf, "Getting photo \"%s\" (#%i)", filename, file_number+1); regl = 12; regd = 14; } - sierra_debug_print(fd, buf); - /* Fill in the file structure */ - strcpy(file->type, "image/jpg"); - strcpy(file->name, filename); + strcpy (file->type, "image/jpeg"); + strcpy (file->name, filename); /* Get the picture data */ - if (sierra_get_string_register(camera, regd, file_number+1, file, NULL, NULL)< 0) - return (GP_ERROR); + ret = sierra_get_string_register (camera, regd, file_number + 1, file, + NULL, NULL); + if (ret != GP_OK) + return (ret); -if (camera_stop(camera)< 0) -return (GP_ERROR); - - return (GP_OK); + return (camera_stop (camera)); } int camera_file_get (Camera *camera, const char *folder, const char *filename, CameraFile *file) { - return (camera_file_get_generic(camera, file, folder, filename, 0)); + return (camera_file_get_generic (camera, file, folder, filename, 0)); } int camera_file_get_preview (Camera *camera, const char *folder, const char *filename, CameraFile *file) { - return (camera_file_get_generic(camera, file, folder, filename, 1)); + return (camera_file_get_generic (camera, file, folder, filename, 1)); } int camera_file_delete (Camera *camera, const char *folder, const char *filename) { int ret, file_number; - char buf[4096]; SierraData *fd = (SierraData*)camera->camlib_data; -if (camera_start(camera)< 0) -return (GP_ERROR); + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** sierra_file_delete"); + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** folder: %s", folder); + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** filename: %s", filename); - file_number = gp_filesystem_number(fd->fs, folder, filename); + ret = camera_start (camera); + if (ret != GP_OK) + return (ret); - sprintf(buf, "Deleting photo #%i", file_number+1); - sierra_debug_print(fd, buf); + file_number = gp_filesystem_number (fd->fs, folder, filename); - ret = sierra_delete(camera, file_number+1); - if (ret == GP_OK) - gp_filesystem_delete(fd->fs, folder, filename); + ret = sierra_delete (camera, file_number+1); + if (ret != GP_OK) + return (ret); -if (camera_stop(camera)< 0) -return (GP_ERROR); + ret = gp_filesystem_delete (fd->fs, folder, filename); + if (ret != GP_OK) + return (ret); - return (ret); + return (camera_stop(camera)); } -#if 0 -int camera_capture (Camera *camera, int capture_type, CameraFilePath *path) { +int camera_capture (Camera *camera, int capture_type, CameraFilePath *path) +{ + int ret; - SierraData *fd = (SierraData*)camera->camlib_data; - int retval; + ret = camera_start (camera); + if (ret != GP_OK) + return (ret); -if (camera_start(camera)< 0) -return (GP_ERROR); - - sierra_debug_print(fd, "Capturing image"); - retval = sierra_capture(camera, file, info); - -if (camera_stop(camera)< 0) -return (GP_ERROR); - - return (retval); + ret = sierra_capture (camera, capture_type, path); + if (ret != GP_OK) { + camera_stop (camera); + return (ret); + } + + return (camera_stop (camera)); +} + +int camera_capture_preview (Camera *camera, CameraFile *file) +{ + int ret; + + ret = camera_start (camera); + if (ret != GP_OK) + return (ret); + + ret = sierra_capture_preview (camera, file); + if (ret != GP_OK) { + camera_stop (camera); + return (ret); + } + + return (camera_stop (camera)); } -#endif int camera_summary (Camera *camera, CameraText *summary) { char buf[1024*32]; - int value; + int value, ret; char t[1024]; - SierraData *fd = (SierraData*)camera->camlib_data; -if (camera_start(camera)< 0) -return (GP_ERROR); + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** camera_summary"); + + ret = camera_start (camera); + if (ret != GP_OK) + return (ret); - sierra_debug_print(fd, "Getting camera summary"); strcpy(buf, ""); /* Get all the string-related info */ - if (sierra_get_string_register(camera, 22, 0, NULL, t, &value)!=GP_ERROR) + ret = sierra_get_string_register (camera, 22, 0, NULL, t, &value); + if (ret == GP_OK) sprintf(buf, "%sCamera ID : %s\n", buf, t); - if (sierra_get_string_register(camera, 25, 0, NULL, t, &value)!=GP_ERROR) + + ret = sierra_get_string_register (camera, 25, 0, NULL, t, &value); + if (ret == GP_OK) sprintf(buf, "%sSerial Number : %s\n", buf, t); - if (sierra_get_int_register(camera, 1, &value)!=GP_ERROR) { - switch(value) { - case 1: strcpy(t, "Standard"); - break; - case 2: strcpy(t, "High"); - break; - case 3: strcpy(t, "Best"); - break; - default: - sprintf(t, "%i (unknown)", value); + + ret = sierra_get_int_register (camera, 1, &value); + if (ret == GP_OK) { + switch (value) { + case 1: strcpy(t, "Standard"); + break; + case 2: strcpy(t, "High"); + break; + case 3: strcpy(t, "Best"); + break; + default: + sprintf(t, "%i (unknown)", value); } - sprintf(buf, "%sResolution : %s\n", buf, t); + sprintf (buf, "%sResolution : %s\n", buf, t); } - if (sierra_get_int_register(camera, 3, &value)!=GP_ERROR) { + + ret = sierra_get_int_register (camera, 3, &value); + if (ret == GP_OK) { if (value == 0) - strcpy(t, "Auto"); - else - sprintf(t, "%i microseconds", value); - sprintf(buf, "%sShutter Speed : %s\n", buf, t); - } - if (sierra_get_int_register(camera, 5, &value)!=GP_ERROR) { - switch(value) { - case 1: strcpy(t, "Low"); - break; - case 2: strcpy(t, "Medium"); - break; - case 3: strcpy(t, "High"); - break; - default: - sprintf(t, "%i (unknown)", value); - } - sprintf(buf, "%sAperture : %s\n", buf, t); - } - if (sierra_get_int_register(camera, 6, &value)!=GP_ERROR) { - switch(value) { - case 1: strcpy(t, "Color"); - break; - case 2: strcpy(t, "Black/White"); - break; - default: - sprintf(t, "%i (unknown)", value); - } - sprintf(buf, "%sColor Mode : %s\n", buf, t); + strcpy (t, "Auto"); + else + sprintf (t, "%i microseconds", value); + sprintf (buf, "%sShutter Speed : %s\n", buf, t); } - if (sierra_get_int_register(camera, 7, &value)!=GP_ERROR) { - switch(value) { - case 0: strcpy(t, "Auto"); - break; - case 1: strcpy(t, "Force"); - break; - case 2: strcpy(t, "Off"); - break; - case 3: strcpy(t, "Red-eye Reduction"); - break; - case 4: strcpy(t, "Slow Synch"); - break; - default: - sprintf(t, "%i (unknown)", value); + ret = sierra_get_int_register (camera, 5, &value); + if (ret == GP_OK) { + switch (value) { + case 1: strcpy (t, "Low"); + break; + case 2: strcpy (t, "Medium"); + break; + case 3: strcpy (t, "High"); + break; + default: + sprintf(t, "%i (unknown)", value); } - sprintf(buf, "%sFlash Mode : %s\n", buf, t); + sprintf (buf, "%sAperture : %s\n", buf, t); } - if (sierra_get_int_register(camera, 19, &value)!=GP_ERROR) { - switch(value) { - case 0: strcpy(t, "Normal"); - break; - case 1: strcpy(t, "Bright+"); - break; - case 2: strcpy(t, "Bright-"); - break; - case 3: strcpy(t, "Contrast+"); - break; - case 4: strcpy(t, "Contrast-"); - break; - default: - sprintf(t, "%i (unknown)", value); - } - sprintf(buf, "%sBright/Contrast : %s\n", buf, t); + + ret = sierra_get_int_register (camera, 6, &value); + if (ret == GP_OK) { + switch (value) { + case 1: strcpy (t, "Color"); + break; + case 2: strcpy (t, "Black/White"); + break; + default: + sprintf (t, "%i (unknown)", value); + } + sprintf (buf, "%sColor Mode : %s\n", buf, t); } - if (sierra_get_int_register(camera, 20, &value)!=GP_ERROR) { - switch(value) { - case 0: strcpy(t, "Auto"); - break; - case 1: strcpy(t, "Skylight"); - break; - case 2: strcpy(t, "Flourescent"); - break; - case 3: strcpy(t, "Tungsten"); - break; - case 255: strcpy(t, "Cloudy"); - break; - default: - sprintf(t, "%i (unknown)", value); + + ret = sierra_get_int_register (camera, 7, &value); + if (ret == GP_OK) { + switch (value) { + case 0: strcpy (t, "Auto"); + break; + case 1: strcpy (t, "Force"); + break; + case 2: strcpy (t, "Off"); + break; + case 3: strcpy (t, "Red-eye Reduction"); + break; + case 4: strcpy (t, "Slow Synch"); + break; + default: + sprintf (t, "%i (unknown)", value); } - sprintf(buf, "%sWhite Balance : %s\n", buf, t); + sprintf (buf, "%sFlash Mode : %s\n", buf, t); } - if (sierra_get_int_register(camera, 33, &value)!=GP_ERROR) { - switch(value) { - case 1: strcpy(t, "Macro"); - break; - case 2: strcpy(t, "Normal"); - break; - case 3: strcpy(t, "Infinity/Fish-eye"); - break; - default: - sprintf(t, "%i (unknown)", value); + + ret = sierra_get_int_register (camera, 19, &value); + if (ret == GP_OK) { + switch (value) { + case 0: strcpy (t, "Normal"); + break; + case 1: strcpy (t, "Bright+"); + break; + case 2: strcpy (t, "Bright-"); + break; + case 3: strcpy (t, "Contrast+"); + break; + case 4: strcpy (t, "Contrast-"); + break; + default: + sprintf (t, "%i (unknown)", value); } - sprintf(buf, "%sLens Mode : %s\n", buf, t); + sprintf (buf, "%sBright/Contrast : %s\n", buf, t); + } + + ret = sierra_get_int_register (camera, 20, &value); + if (ret == GP_OK) { + switch (value) { + case 0: strcpy (t, "Auto"); + break; + case 1: strcpy (t, "Skylight"); + break; + case 2: strcpy (t, "Flourescent"); + break; + case 3: strcpy (t, "Tungsten"); + break; + case 255: + strcpy (t, "Cloudy"); + break; + default: + sprintf (t, "%i (unknown)", value); + } + sprintf (buf, "%sWhite Balance : %s\n", buf, t); + } + + ret = sierra_get_int_register (camera, 33, &value); + if (ret == GP_OK) { + switch(value) { + case 1: strcpy (t, "Macro"); + break; + case 2: strcpy (t, "Normal"); + break; + case 3: strcpy (t, "Infinity/Fish-eye"); + break; + default: + sprintf (t, "%i (unknown)", value); + } + sprintf (buf, "%sLens Mode : %s\n", buf, t); } /* Get all the integer information */ - if (sierra_get_int_register(camera, 10, &value)!=GP_ERROR) - sprintf(buf, "%sFrames Taken : %i\n", buf, value); - if (sierra_get_int_register(camera, 11, &value)!=GP_ERROR) - sprintf(buf, "%sFrames Left : %i\n", buf, value); - if (sierra_get_int_register(camera, 16, &value)!=GP_ERROR) - sprintf(buf, "%sBattery Life : %i\n", buf, value); - if (sierra_get_int_register(camera, 23, &value)!=GP_ERROR) - sprintf(buf, "%sAutoOff (host) : %i seconds\n", buf, value); - if (sierra_get_int_register(camera, 24, &value)!=GP_ERROR) - sprintf(buf, "%sAutoOff (field) : %i seconds\n", buf, value); - if (sierra_get_int_register(camera, 28, &value)!=GP_ERROR) - sprintf(buf, "%sMemory Left : %i bytes\n", buf, value); - if (sierra_get_int_register(camera, 35, &value)!=GP_ERROR) - sprintf(buf, "%sLCD Brightness : %i (1-7)\n", buf, value); - if (sierra_get_int_register(camera, 38, &value)!=GP_ERROR) - sprintf(buf, "%sLCD AutoOff : %i seconds\n", buf, value); + if (sierra_get_int_register(camera, 10, &value) == GP_OK) + sprintf (buf, "%sFrames Taken : %i\n", buf, value); + if (sierra_get_int_register(camera, 11, &value) == GP_OK) + sprintf (buf, "%sFrames Left : %i\n", buf, value); + if (sierra_get_int_register(camera, 16, &value) == GP_OK) + sprintf (buf, "%sBattery Life : %i\n", buf, value); + if (sierra_get_int_register(camera, 23, &value) == GP_OK) + sprintf (buf, "%sAutoOff (host) : %i seconds\n", buf, value); + if (sierra_get_int_register(camera, 24, &value) == GP_OK) + sprintf (buf, "%sAutoOff (field) : %i seconds\n", buf, value); + if (sierra_get_int_register(camera, 28, &value) == GP_OK) + sprintf (buf, "%sMemory Left : %i bytes\n", buf, value); + if (sierra_get_int_register(camera, 35, &value) == GP_OK) + sprintf (buf, "%sLCD Brightness : %i (1-7)\n", buf, value); + if (sierra_get_int_register(camera, 38, &value) == GP_OK) + sprintf (buf, "%sLCD AutoOff : %i seconds\n", buf, value); strcpy(summary->text, buf); -if (camera_stop(camera)< 0) -return (GP_ERROR); - - return (GP_OK); + return (camera_stop(camera)); } int camera_manual (Camera *camera, CameraText *manual) { - SierraData *fd = (SierraData*)camera->camlib_data; + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** camera_manual"); - sierra_debug_print(fd, "Getting camera manual"); - - strcpy(manual->text, "Manual Not Available"); + strcpy (manual->text, "Manual Not Available"); return (GP_OK); } int camera_about (Camera *camera, CameraText *about) { - SierraData *fd = (SierraData*)camera->camlib_data; - - sierra_debug_print(fd, "Getting 'about' information"); - + gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** camera_about"); + strcpy (about->text, "sierra SPARClite library\n" "Scott Fritzinger \n" diff --git a/camlibs/sierra/sierra.h b/camlibs/sierra/sierra.h index da790e467..1ac8adb95 100644 --- a/camlibs/sierra/sierra.h +++ b/camlibs/sierra/sierra.h @@ -16,4 +16,3 @@ typedef struct { int usb_outep; } SierraCamera; -void sierra_debug_print(SierraData *fd, char *message);