2001-09-22 Lutz M�ller <urc8@rz.uni-karlsruhe.de>

Patch from Fredrik <fredrik@krixor.xy.org>

        * include/gphoto2-port.h:
        * libgphoto2_port/gp_port.c:
        * serial/unix.c:
        * usb/libusb.c: Clean up settings code.


git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@2296 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
Lutz Mueller
2001-09-22 08:09:29 +00:00
parent 75f1a1c9f9
commit a424dea2cc
5 changed files with 77 additions and 49 deletions

View File

@@ -1,3 +1,12 @@
2001-09-22 Lutz Müller <urc8@rz.uni-karlsruhe.de>
Patch from Fredrik <fredrik@krixor.xy.org>
* include/gphoto2-port.h:
* libgphoto2_port/gp_port.c:
* serial/unix.c:
* usb/libusb.c: Clean up settings code.
2001-09-22 Lutz Müller <urc8@rz.uni-karlsruhe.de>
Patch from Carsten Pfeiffer <carpdjih@sp.zrz.tu-berlin.de>

View File

@@ -159,8 +159,6 @@ struct gp_port {
gp_port_settings settings;
gp_port_settings settings_pending;
gp_port_settings settings_saved;
int device_fd;
#ifdef WIN32
HANDLE device_handle;
@@ -173,7 +171,6 @@ struct gp_port {
void *library_handle;
int debug_level;
int previously_opened;
};
/* Core functions

View File

@@ -184,7 +184,6 @@ gp_port_new (gp_port **dev, gp_port_type type)
}
(*dev)->debug_level = glob_debug_level;
(*dev)->previously_opened = 0;
(*dev)->type = type;
(*dev)->device_fd = 0;
@@ -212,14 +211,12 @@ gp_port_new (gp_port **dev, gp_port_type type)
gp_port_timeout_set (*dev, 50000);
break;
case GP_PORT_USB:
/* Set some default settings */
settings.usb.inep = 0x81;
settings.usb.outep = 0x02;
settings.usb.config = 1;
settings.usb.interface = 0;
settings.usb.altsetting = 0;
gp_port_settings_set (*dev, settings);
/* Initialize settings.usb */
(*dev)->settings.usb.inep = -1;
(*dev)->settings.usb.outep = -1;
(*dev)->settings.usb.config = -1;
(*dev)->settings.usb.interface = 0;
(*dev)->settings.usb.altsetting = -1;
gp_port_timeout_set (*dev, 5000);
break;
@@ -260,18 +257,6 @@ gp_port_open (gp_port *dev)
if (retval < 0)
return (retval);
/* Now update the settings */
retval = dev->ops->update (dev);
if (retval != GP_OK) {
dev->device_fd = 0;
gp_port_debug_printf (GP_DEBUG_LOW, dev->debug_level,
"gp_port_open: update error");
return retval;
}
/* Set the default timeout */
gp_port_timeout_set (dev, dev->timeout);
return GP_OK;
}
@@ -396,10 +381,10 @@ gp_port_settings_set (gp_port *dev, gp_port_settings settings)
{
int retval;
/* need to memcpy() settings to dev->settings */
/* need to memcpy() settings to dev->settings_pending */
memcpy(&dev->settings_pending, &settings, sizeof(dev->settings_pending));
retval = dev->ops->update(dev);
retval = dev->ops->update(dev);
gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level,
"gp_port_set_settings: update %s", retval < 0? "error":"ok");
return (retval);

View File

@@ -332,7 +332,6 @@ gp_port_serial_init (gp_port *dev)
{
DeviceHandle *handle;
/* save previous setttings in to dev->settings_saved */
#if HAVE_TERMIOS_H
if (tcgetattr(dev->device_fd, &term_old) < 0) {
perror("tcgetattr2");

View File

@@ -130,11 +130,11 @@ int gp_port_usb_open(gp_port *dev)
ret = usb_claim_interface (dev->device_handle,
dev->settings.usb.interface);
if (ret < 0) {
fprintf (stderr, "gp_port_usb_open: could not claim intf %d: "
"%s\n", dev->settings.usb.interface, strerror (errno));
fprintf(stderr, "gp_port_usb_open: could not claim intf %d: "
"%s\n", dev->settings.usb.interface, strerror (errno));
return GP_ERROR_IO_OPEN;
}
return GP_OK;
}
@@ -250,33 +250,71 @@ int gp_port_usb_msg_read_lib(gp_port * dev, int request, int value, int index,
}
/*
* This function applys changes to the device
* This function applys changes to the device.
*
* New settings are in dev->settings_pending and the old ones
* are in dev->settings. Compare them first and only call
* usb_set_configuration() and usb_set_altinterface() if needed
* since some USB devices does not like it if this is done
* more than necessary (Canon Digital IXUS 300 for one).
*
*/
int gp_port_usb_update(gp_port * dev)
{
int ret;
memcpy(&dev->settings, &dev->settings_pending, sizeof(dev->settings));
if ((dev->device_handle != NULL) && (! dev->previously_opened)) {
ret = usb_set_configuration (dev->device_handle,
dev->settings.usb.config);
if (ret < 0) {
fprintf(stderr, "gp_port_usb_update: could not set config %d: "
"%s\n", dev->settings.usb.config, strerror (errno));
return GP_ERROR_IO_OPEN;
if (!dev) {
fprintf(stderr, "gp_port_usb_update: called on NULL device\n");
return GP_ERROR_IO_UPDATE;
}
if (dev->device_handle == NULL) {
fprintf(stderr, "gp_port_usb_update: called on non-open device\n");
return GP_ERROR_IO_UPDATE;
}
if (dev->debug_level)
printf("gp_port_usb_update() called\n");
if (memcmp(&dev->settings.usb, &dev->settings_pending.usb, sizeof(dev->settings.usb))) {
/* settings.usb structure is different than the old one */
if (dev->settings.usb.config != dev->settings_pending.usb.config) {
ret = usb_set_configuration(dev->device_handle,
dev->settings_pending.usb.config);
if (ret < 0) {
fprintf(stderr, "gp_port_usb_update: could not set config %d/%d: "
"%s\n", dev->settings_pending.usb.interface,
dev->settings_pending.usb.config, strerror(errno));
return GP_ERROR_IO_UPDATE;
}
if (dev->debug_level)
printf("gp_port_usb_update: changed usb.config from %d to %d\n",
dev->settings.usb.config, dev->settings_pending.usb.config);
/* copy at once if something else fails so that this does not get re-applied */
dev->settings.usb.config = dev->settings_pending.usb.config;
}
ret = usb_set_altinterface (dev->device_handle,
dev->settings.usb.altsetting);
if (ret < 0) {
fprintf (stderr, "gp_port_usb_update: could not set intf %d/%d: "
"%s\n", dev->settings.usb.interface,
dev->settings.usb.altsetting, strerror (errno));
return GP_ERROR_IO_OPEN;
}
if (dev->settings.usb.altsetting != dev->settings_pending.usb.altsetting) {
ret = usb_set_altinterface(dev->device_handle, dev->settings_pending.usb.altsetting);
if (ret < 0) {
fprintf(stderr, "gp_port_usb_update: could not set intf %d/%d: "
"%s\n", dev->settings_pending.usb.interface,
dev->settings_pending.usb.altsetting, strerror(errno));
dev->previously_opened = 1;
return GP_ERROR_IO_UPDATE;
}
if (dev->debug_level)
printf("gp_port_usb_update: changed usb.altsetting from %d to %d\n",
dev->settings.usb.altsetting, dev->settings_pending.usb.altsetting);
}
memcpy(&dev->settings.usb, &dev->settings_pending.usb, sizeof(dev->settings.usb));
}
return GP_OK;