diff --git a/camlibs/sierra/ChangeLog b/camlibs/sierra/ChangeLog index e493cf9d9..206b158d8 100644 --- a/camlibs/sierra/ChangeLog +++ b/camlibs/sierra/ChangeLog @@ -1,3 +1,8 @@ +2002-03-28 Lutz Müller + + * library.c: Formatting. + * sierra.c: Ping the camera before changing the speed. + 2002-03-14 Patrick Mansfield * sierra.c (camera_get_config_olympus, camera_set_config_olympus): diff --git a/camlibs/sierra/library.c b/camlibs/sierra/library.c index 002c254f8..90513a24a 100644 --- a/camlibs/sierra/library.c +++ b/camlibs/sierra/library.c @@ -322,7 +322,7 @@ sierra_get_memory_left (Camera *camera, int *memory, GPContext *context) static int sierra_write_packet (Camera *camera, char *packet) { - int x, ret, r, checksum=0, length; + int x, checksum=0, length; GP_DEBUG ("* sierra_write_packet"); @@ -345,26 +345,13 @@ sierra_write_packet (Camera *camera, char *packet) packet[length-1] = (checksum >> 8) & 0xff; } - /* USB */ - if (camera->port->type == GP_PORT_USB) { - if (camera->pl->usb_wrap) - return (usb_wrap_write_packet (camera->port, packet, - length)); - else - return (gp_port_write (camera->port, packet, length)); + if (camera->pl->usb_wrap) { + CHECK (usb_wrap_write_packet (camera->port, packet, length)); + } else { + CHECK (gp_port_write (camera->port, packet, length)); } - /* SERIAL */ - for (r = 0; r < RETRIES; r++) { - - ret = gp_port_write (camera->port, packet, length); - if (ret == GP_ERROR_TIMEOUT) - continue; - - return (ret); - } - - return (GP_ERROR_TIMEOUT); + return (GP_OK); } static int @@ -721,17 +708,13 @@ sierra_write_ack (Camera *camera) return (GP_OK); } -int sierra_ping (Camera *camera, GPContext *context) +int +sierra_ping (Camera *camera, GPContext *context) { char buf[4096], packet[4096]; - GP_DEBUG ("* sierra_ping"); + GP_DEBUG ("Pinging camera..."); - if (camera->port->type == GP_PORT_USB) { - GP_DEBUG ("* sierra_ping no ping for USB"); - return (GP_OK); - } - packet[0] = NUL; CHECK (sierra_write_packet (camera, packet)); @@ -742,7 +725,7 @@ int sierra_ping (Camera *camera, GPContext *context) return (GP_OK); default: gp_context_error (context, _("Got unexpected result " - "%i. Please contact " + "0x%x. Please contact " "."), buf[0]); return GP_ERROR; } diff --git a/camlibs/sierra/sierra.c b/camlibs/sierra/sierra.c index e6d36bf84..36f6fc0ee 100644 --- a/camlibs/sierra/sierra.c +++ b/camlibs/sierra/sierra.c @@ -100,8 +100,9 @@ } \ } -int camera_start(Camera *camera, GPContext *context); -int camera_stop(Camera *camera, GPContext *context); +static int camera_start (Camera *camera, GPContext *context); +static int camera_stop (Camera *camera, GPContext *context); + int get_jpeg_data(const char *data, int data_size, char **jpeg_data, int *jpeg_size); /* Useful markers */ @@ -362,9 +363,12 @@ set_info_func (CameraFilesystem *fs, const char *folder, const char *filename, return (camera_stop (camera, context)); } -int camera_start (Camera *camera, GPContext *context) +static int +camera_start (Camera *camera, GPContext *context) { - GP_DEBUG ("*** camera_start"); + GPPortSettings settings; + + GP_DEBUG ("Establishing connection..."); /* * Opening and closing of the port happens in libgphoto2. All we @@ -372,18 +376,26 @@ int camera_start (Camera *camera, GPContext *context) */ switch (camera->port->type) { case GP_PORT_SERIAL: - CHECK_STOP (camera, sierra_set_speed (camera, - camera->pl->speed, context)); + + /* Let's see if the camera is alive. */ + CHECK (sierra_ping (camera, context)); + + /* If needed, change speed. */ + if (camera->pl->speed != settings.serial.speed) + CHECK (sierra_set_speed (camera, camera->pl->speed, + context)); return (GP_OK); + case GP_PORT_USB: - CHECK_STOP (camera, gp_port_set_timeout (camera->port, 5000)); + CHECK (gp_port_set_timeout (camera->port, 5000)); return (GP_OK); default: return (GP_OK); } } -int camera_stop (Camera *camera, GPContext *context) +static int +camera_stop (Camera *camera, GPContext *context) { GP_DEBUG ("*** camera_stop");