kopia lustrzana https://gitlab.com/sane-project/backends
- handle the case where the attach callback or the config struct
is NULL - make use of new configuration parsing frameworkmerge-requests/1/head
rodzic
9d605a2143
commit
fb5ade52ad
|
@ -1,3 +1,8 @@
|
||||||
|
2008-07-10 Stéphane Voltz <stef.dev@free.fr>
|
||||||
|
* sanei/sanei_config.c: handle cases where config or callback
|
||||||
|
function is NULL
|
||||||
|
* backend/rts8891.c: use new configuration parsing framework
|
||||||
|
|
||||||
2008-07-10 Stéphane Voltz <stef.dev@free.fr>
|
2008-07-10 Stéphane Voltz <stef.dev@free.fr>
|
||||||
* include/sane/sanei_config.h: doxygen fix for new function
|
* include/sane/sanei_config.h: doxygen fix for new function
|
||||||
|
|
||||||
|
|
|
@ -144,6 +144,9 @@ static Rts8891_Session *first_handle = NULL;
|
||||||
static Rts8891_Device *first_device = NULL;
|
static Rts8891_Device *first_device = NULL;
|
||||||
static SANE_Int num_devices = 0;
|
static SANE_Int num_devices = 0;
|
||||||
|
|
||||||
|
static SANE_Word modelnumber = -1;
|
||||||
|
static SANE_Bool allowsharing = SANE_TRUE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* needed by sane_get_devices
|
* needed by sane_get_devices
|
||||||
*/
|
*/
|
||||||
|
@ -169,6 +172,14 @@ static SANE_Range y_range = {
|
||||||
SANE_FIX (0.0) /* quantization */
|
SANE_FIX (0.0) /* quantization */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* model number ranges from 0 to 2, must be cvhnaged if
|
||||||
|
* Rts8891_USB_Device_Entry changes */
|
||||||
|
static const SANE_Range model_range = {
|
||||||
|
0, /* minimum */
|
||||||
|
2, /* maximum */
|
||||||
|
0 /* quantization */
|
||||||
|
};
|
||||||
|
|
||||||
static const SANE_Range u8_range = {
|
static const SANE_Range u8_range = {
|
||||||
0, /* minimum */
|
0, /* minimum */
|
||||||
255, /* maximum */
|
255, /* maximum */
|
||||||
|
@ -197,7 +208,8 @@ max_string_size (const SANE_String_Const strings[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
static SANE_Status config_attach_rts8891 (SANEI_Config * config,
|
||||||
|
const char *devname);
|
||||||
static SANE_Status attach_Rts8891 (const char *name);
|
static SANE_Status attach_Rts8891 (const char *name);
|
||||||
static SANE_Status set_lamp_brightness (struct Rts8891_Device *dev,
|
static SANE_Status set_lamp_brightness (struct Rts8891_Device *dev,
|
||||||
int level);
|
int level);
|
||||||
|
@ -283,10 +295,19 @@ write_rgb_data (char *name, unsigned char *image, SANE_Int width,
|
||||||
SANE_Status
|
SANE_Status
|
||||||
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
|
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
|
||||||
{
|
{
|
||||||
SANE_Char line[PATH_MAX];
|
int i;
|
||||||
SANE_Int vendor, product, len;
|
|
||||||
const char *lp;
|
/**> configuration structure used during attach */
|
||||||
FILE *fp;
|
SANEI_Config config;
|
||||||
|
|
||||||
|
/**> list of configuration options */
|
||||||
|
SANE_Option_Descriptor *options[2];
|
||||||
|
|
||||||
|
/**> placeholders for option values */
|
||||||
|
void *values[2];
|
||||||
|
|
||||||
|
SANE_Status status;
|
||||||
|
|
||||||
authorize = authorize; /* get rid of compiler warning */
|
authorize = authorize; /* get rid of compiler warning */
|
||||||
|
|
||||||
/* init ASIC libraries */
|
/* init ASIC libraries */
|
||||||
|
@ -304,54 +325,48 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
|
||||||
if (version_code)
|
if (version_code)
|
||||||
*version_code = SANE_VERSION_CODE (V_MAJOR, V_MINOR, 0);
|
*version_code = SANE_VERSION_CODE (V_MAJOR, V_MINOR, 0);
|
||||||
|
|
||||||
/* loop on 'usb' entries in rts8891.conf, and try to
|
/* initialize configuration options */
|
||||||
attach with it.
|
i = 0;
|
||||||
Reading the conf file allow to test only for desired
|
options[i] =
|
||||||
devices, not the all range of supported devices.
|
(SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor));
|
||||||
*/
|
options[i]->name = "modelnumber";
|
||||||
fp = sanei_config_open (RTS8891_CONFIG_FILE);
|
options[i]->desc = "user provided scanner's internal model number";
|
||||||
if (!fp)
|
options[i]->type = SANE_TYPE_INT;
|
||||||
|
options[i]->unit = SANE_UNIT_NONE;
|
||||||
|
options[i]->size = sizeof (SANE_Word);
|
||||||
|
options[i]->cap = SANE_CAP_SOFT_SELECT;
|
||||||
|
options[i]->constraint_type = SANE_CONSTRAINT_RANGE;
|
||||||
|
options[i]->constraint.range = &model_range;
|
||||||
|
values[i] = &modelnumber;
|
||||||
|
i++;
|
||||||
|
|
||||||
|
options[i] =
|
||||||
|
(SANE_Option_Descriptor *) malloc (sizeof (SANE_Option_Descriptor));
|
||||||
|
options[i]->name = "allowsharing";
|
||||||
|
options[i]->desc = "allow sharing of the scanner by several frontends";
|
||||||
|
options[i]->type = SANE_TYPE_BOOL;
|
||||||
|
options[i]->unit = SANE_UNIT_NONE;
|
||||||
|
options[i]->size = sizeof (SANE_Bool);
|
||||||
|
options[i]->cap = SANE_CAP_SOFT_SELECT;
|
||||||
|
options[i]->constraint_type = SANE_CONSTRAINT_NONE;
|
||||||
|
values[i] = &allowsharing;
|
||||||
|
i++;
|
||||||
|
|
||||||
|
/* set configuration options structure */
|
||||||
|
config.descriptors = options;
|
||||||
|
config.values = values;
|
||||||
|
config.count = i;
|
||||||
|
|
||||||
|
/* generic configure and attach function */
|
||||||
|
status = sanei_configure_attach (RTS8891_CONFIG_FILE, &config,
|
||||||
|
config_attach_rts8891);
|
||||||
|
/* free allocated options */
|
||||||
|
while (i > 0)
|
||||||
{
|
{
|
||||||
DBG (DBG_error, "sane_init: couldn't access %s\n", RTS8891_CONFIG_FILE);
|
i--;
|
||||||
DBG (DBG_proc, "sane_init: exit\n");
|
free (options[i]);
|
||||||
return SANE_STATUS_ACCESS_DENIED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* scan the conf file to find lines like 'usb 0x.... 0x....' */
|
|
||||||
while (sanei_config_read (line, PATH_MAX, fp))
|
|
||||||
{
|
|
||||||
/* ignore comments */
|
|
||||||
if (line[0] == '#')
|
|
||||||
continue;
|
|
||||||
len = strlen (line);
|
|
||||||
|
|
||||||
/* delete newline characters at end */
|
|
||||||
if (line[len - 1] == '\n')
|
|
||||||
line[--len] = '\0';
|
|
||||||
|
|
||||||
lp = sanei_config_skip_whitespace (line);
|
|
||||||
/* skip empty lines */
|
|
||||||
if (*lp == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (sscanf (lp, "usb %i %i", &vendor, &product) == 2)
|
|
||||||
;
|
|
||||||
else if (strncmp ("libusb", lp, 6) == 0)
|
|
||||||
;
|
|
||||||
else if ((strncmp ("usb", lp, 3) == 0) && isspace (lp[3]))
|
|
||||||
{
|
|
||||||
lp += 3;
|
|
||||||
lp = sanei_config_skip_whitespace (lp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
continue;
|
|
||||||
|
|
||||||
DBG (DBG_error, "sane_init: trying to attach with '%s'\n", lp);
|
|
||||||
sanei_usb_attach_matching_devices (lp, attach_Rts8891);
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose (fp);
|
|
||||||
|
|
||||||
DBG (DBG_proc, "sane_init: exit\n");
|
DBG (DBG_proc, "sane_init: exit\n");
|
||||||
return SANE_STATUS_GOOD;
|
return SANE_STATUS_GOOD;
|
||||||
}
|
}
|
||||||
|
@ -550,7 +565,10 @@ sane_open (SANE_String_Const name, SANE_Handle * handle)
|
||||||
first_handle = session;
|
first_handle = session;
|
||||||
|
|
||||||
/* release the interface to allow device sharing */
|
/* release the interface to allow device sharing */
|
||||||
|
if (allowsharing == SANE_TRUE)
|
||||||
|
{
|
||||||
sanei_usb_release_interface (device->devnum, 0);
|
sanei_usb_release_interface (device->devnum, 0);
|
||||||
|
}
|
||||||
|
|
||||||
DBG (DBG_proc, "sane_open: exit\n");
|
DBG (DBG_proc, "sane_open: exit\n");
|
||||||
return SANE_STATUS_GOOD;
|
return SANE_STATUS_GOOD;
|
||||||
|
@ -1083,12 +1101,15 @@ sane_start (SANE_Handle handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* claim the interface reserve device */
|
/* claim the interface reserve device */
|
||||||
|
if (allowsharing == SANE_TRUE)
|
||||||
|
{
|
||||||
status = sanei_usb_claim_interface (dev->devnum, 0);
|
status = sanei_usb_claim_interface (dev->devnum, 0);
|
||||||
if (status != SANE_STATUS_GOOD)
|
if (status != SANE_STATUS_GOOD)
|
||||||
{
|
{
|
||||||
DBG (DBG_warn, "sane_start: cannot claim usb interface\n");
|
DBG (DBG_warn, "sane_start: cannot claim usb interface\n");
|
||||||
return SANE_STATUS_DEVICE_BUSY;
|
return SANE_STATUS_DEVICE_BUSY;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* check if we need warming-up */
|
/* check if we need warming-up */
|
||||||
sanei_rts88xx_get_lamp_status (dev->devnum, dev->regs);
|
sanei_rts88xx_get_lamp_status (dev->devnum, dev->regs);
|
||||||
|
@ -1133,7 +1154,8 @@ sane_start (SANE_Handle handle)
|
||||||
return SANE_STATUS_WARMING_UP;
|
return SANE_STATUS_WARMING_UP;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
DBG (DBG_info, "sane_start: waiting 15s to let lamp getting warm enough ...\n");
|
DBG (DBG_info,
|
||||||
|
"sane_start: waiting 15s to let lamp getting warm enough ...\n");
|
||||||
sleep (15);
|
sleep (15);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1151,8 +1173,11 @@ sane_start (SANE_Handle handle)
|
||||||
changed = SANE_FALSE;
|
changed = SANE_FALSE;
|
||||||
status = find_origin (dev, &changed);
|
status = find_origin (dev, &changed);
|
||||||
if (status != SANE_STATUS_GOOD)
|
if (status != SANE_STATUS_GOOD)
|
||||||
|
{
|
||||||
|
if (allowsharing == SANE_TRUE)
|
||||||
{
|
{
|
||||||
sanei_usb_release_interface (dev->devnum, 0);
|
sanei_usb_release_interface (dev->devnum, 0);
|
||||||
|
}
|
||||||
DBG (DBG_error, "sane_start: failed to find origin!\n");
|
DBG (DBG_error, "sane_start: failed to find origin!\n");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -1187,8 +1212,11 @@ sane_start (SANE_Handle handle)
|
||||||
/* step 2: dark calibration */
|
/* step 2: dark calibration */
|
||||||
status = dark_calibration (dev, light);
|
status = dark_calibration (dev, light);
|
||||||
if (status != SANE_STATUS_GOOD)
|
if (status != SANE_STATUS_GOOD)
|
||||||
|
{
|
||||||
|
if (allowsharing == SANE_TRUE)
|
||||||
{
|
{
|
||||||
sanei_usb_release_interface (dev->devnum, 0);
|
sanei_usb_release_interface (dev->devnum, 0);
|
||||||
|
}
|
||||||
DBG (DBG_error, "sane_start: failed to do dark calibration!\n");
|
DBG (DBG_error, "sane_start: failed to do dark calibration!\n");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -1196,8 +1224,11 @@ sane_start (SANE_Handle handle)
|
||||||
/* step 3: find left margin */
|
/* step 3: find left margin */
|
||||||
status = find_margin (dev);
|
status = find_margin (dev);
|
||||||
if (status != SANE_STATUS_GOOD)
|
if (status != SANE_STATUS_GOOD)
|
||||||
|
{
|
||||||
|
if (allowsharing == SANE_TRUE)
|
||||||
{
|
{
|
||||||
sanei_usb_release_interface (dev->devnum, 0);
|
sanei_usb_release_interface (dev->devnum, 0);
|
||||||
|
}
|
||||||
DBG (DBG_error, "sane_start: failed find left margin!\n");
|
DBG (DBG_error, "sane_start: failed find left margin!\n");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -1210,8 +1241,11 @@ sane_start (SANE_Handle handle)
|
||||||
/* step 4: gain calibration */
|
/* step 4: gain calibration */
|
||||||
status = gain_calibration (dev, light);
|
status = gain_calibration (dev, light);
|
||||||
if (status != SANE_STATUS_GOOD)
|
if (status != SANE_STATUS_GOOD)
|
||||||
|
{
|
||||||
|
if (allowsharing == SANE_TRUE)
|
||||||
{
|
{
|
||||||
sanei_usb_release_interface (dev->devnum, 0);
|
sanei_usb_release_interface (dev->devnum, 0);
|
||||||
|
}
|
||||||
DBG (DBG_error, "sane_start: failed to do gain calibration!\n");
|
DBG (DBG_error, "sane_start: failed to do gain calibration!\n");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -1219,8 +1253,11 @@ sane_start (SANE_Handle handle)
|
||||||
/* step 5: fine offset calibration */
|
/* step 5: fine offset calibration */
|
||||||
status = offset_calibration (dev, light);
|
status = offset_calibration (dev, light);
|
||||||
if (status != SANE_STATUS_GOOD)
|
if (status != SANE_STATUS_GOOD)
|
||||||
|
{
|
||||||
|
if (allowsharing == SANE_TRUE)
|
||||||
{
|
{
|
||||||
sanei_usb_release_interface (dev->devnum, 0);
|
sanei_usb_release_interface (dev->devnum, 0);
|
||||||
|
}
|
||||||
DBG (DBG_error, "sane_start: failed to do offset calibration!\n");
|
DBG (DBG_error, "sane_start: failed to do offset calibration!\n");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -1252,8 +1289,11 @@ sane_start (SANE_Handle handle)
|
||||||
shading_calibration (dev, session->params.format == SANE_FRAME_RGB
|
shading_calibration (dev, session->params.format == SANE_FRAME_RGB
|
||||||
|| session->emulated_gray == SANE_TRUE, light);
|
|| session->emulated_gray == SANE_TRUE, light);
|
||||||
if (status != SANE_STATUS_GOOD)
|
if (status != SANE_STATUS_GOOD)
|
||||||
|
{
|
||||||
|
if (allowsharing == SANE_TRUE)
|
||||||
{
|
{
|
||||||
sanei_usb_release_interface (dev->devnum, 0);
|
sanei_usb_release_interface (dev->devnum, 0);
|
||||||
|
}
|
||||||
DBG (DBG_error, "sane_start: failed to do shading calibration!\n");
|
DBG (DBG_error, "sane_start: failed to do shading calibration!\n");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -1264,8 +1304,11 @@ sane_start (SANE_Handle handle)
|
||||||
{
|
{
|
||||||
status = move_to_scan_area (session);
|
status = move_to_scan_area (session);
|
||||||
if (status != SANE_STATUS_GOOD)
|
if (status != SANE_STATUS_GOOD)
|
||||||
|
{
|
||||||
|
if (allowsharing == SANE_TRUE)
|
||||||
{
|
{
|
||||||
sanei_usb_release_interface (dev->devnum, 0);
|
sanei_usb_release_interface (dev->devnum, 0);
|
||||||
|
}
|
||||||
DBG (DBG_error, "sane_start: failed to move to scan area!\n");
|
DBG (DBG_error, "sane_start: failed to move to scan area!\n");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -1275,8 +1318,11 @@ sane_start (SANE_Handle handle)
|
||||||
/* build register set and send it */
|
/* build register set and send it */
|
||||||
status = write_scan_registers (session);
|
status = write_scan_registers (session);
|
||||||
if (status != SANE_STATUS_GOOD)
|
if (status != SANE_STATUS_GOOD)
|
||||||
|
{
|
||||||
|
if (allowsharing == SANE_TRUE)
|
||||||
{
|
{
|
||||||
sanei_usb_release_interface (dev->devnum, 0);
|
sanei_usb_release_interface (dev->devnum, 0);
|
||||||
|
}
|
||||||
DBG (DBG_error, "sane_start: failed to write scan registers!\n");
|
DBG (DBG_error, "sane_start: failed to write scan registers!\n");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -1284,8 +1330,11 @@ sane_start (SANE_Handle handle)
|
||||||
/* step 8: send calibration data */
|
/* step 8: send calibration data */
|
||||||
status = send_calibration_data (session);
|
status = send_calibration_data (session);
|
||||||
if (status != SANE_STATUS_GOOD)
|
if (status != SANE_STATUS_GOOD)
|
||||||
|
{
|
||||||
|
if (allowsharing == SANE_TRUE)
|
||||||
{
|
{
|
||||||
sanei_usb_release_interface (dev->devnum, 0);
|
sanei_usb_release_interface (dev->devnum, 0);
|
||||||
|
}
|
||||||
DBG (DBG_error, "sane_start: failed to send calibration data!\n");
|
DBG (DBG_error, "sane_start: failed to send calibration data!\n");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -2014,7 +2063,7 @@ sane_cancel (SANE_Handle handle)
|
||||||
#ifdef HAVE_SYS_TIME_H
|
#ifdef HAVE_SYS_TIME_H
|
||||||
/* store last scan time for the device */
|
/* store last scan time for the device */
|
||||||
gettimeofday (¤t, NULL);
|
gettimeofday (¤t, NULL);
|
||||||
dev->last_scan.tv_sec=current.tv_sec;
|
dev->last_scan.tv_sec = current.tv_sec;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* if scanning, abort and park head */
|
/* if scanning, abort and park head */
|
||||||
|
@ -2049,7 +2098,10 @@ sane_cancel (SANE_Handle handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* release the interface to allow device sharing */
|
/* release the interface to allow device sharing */
|
||||||
|
if (allowsharing == SANE_TRUE)
|
||||||
|
{
|
||||||
sanei_usb_release_interface (dev->devnum, 0);
|
sanei_usb_release_interface (dev->devnum, 0);
|
||||||
|
}
|
||||||
|
|
||||||
DBG (DBG_proc, "sane_cancel: exit\n");
|
DBG (DBG_proc, "sane_cancel: exit\n");
|
||||||
}
|
}
|
||||||
|
@ -2103,7 +2155,10 @@ sane_close (SANE_Handle handle)
|
||||||
first_handle = session->next;
|
first_handle = session->next;
|
||||||
|
|
||||||
/* switch off lamp and close usb */
|
/* switch off lamp and close usb */
|
||||||
|
if (allowsharing == SANE_TRUE)
|
||||||
|
{
|
||||||
sanei_usb_claim_interface (session->dev->devnum, 0);
|
sanei_usb_claim_interface (session->dev->devnum, 0);
|
||||||
|
}
|
||||||
set_lamp_state (session, 0);
|
set_lamp_state (session, 0);
|
||||||
sanei_usb_close (session->dev->devnum);
|
sanei_usb_close (session->dev->devnum);
|
||||||
|
|
||||||
|
@ -2186,6 +2241,32 @@ sane_exit (void)
|
||||||
DBG (DBG_proc, "sane_exit: exit\n");
|
DBG (DBG_proc, "sane_exit: exit\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** This function is called by sanei_configure_attach to try
|
||||||
|
* to attach the backend to a device specified by the configuration file.
|
||||||
|
*
|
||||||
|
* @param config configuration structure filled with values read
|
||||||
|
* from configuration file
|
||||||
|
* @param devname name of the device to try to attach to, it is
|
||||||
|
* the unprocessed line of the configuration file
|
||||||
|
*
|
||||||
|
* @return status SANE_STATUS_GOOD if no errors (even if no matching
|
||||||
|
* devices found)
|
||||||
|
* SANE_STATUS_INVAL in case of error
|
||||||
|
*/
|
||||||
|
static SANE_Status
|
||||||
|
config_attach_rts8891 (SANEI_Config * config, const char *devname)
|
||||||
|
{
|
||||||
|
/* the placeholder is a global var which is used below */
|
||||||
|
config = config;
|
||||||
|
|
||||||
|
/* the devname has been processed and is ready to be used
|
||||||
|
* directly. Since the backend is an USB only one, we can
|
||||||
|
* call sanei_usb_attach_matching_devices straight */
|
||||||
|
sanei_usb_attach_matching_devices (devname, attach_Rts8891);
|
||||||
|
|
||||||
|
return SANE_STATUS_GOOD;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The attach tries to open the given usb device and match it
|
* The attach tries to open the given usb device and match it
|
||||||
* with devices handled by the backend.
|
* with devices handled by the backend.
|
||||||
|
@ -2241,6 +2322,8 @@ attach_Rts8891 (const char *devicename)
|
||||||
sanei_usb_close (dn);
|
sanei_usb_close (dn);
|
||||||
|
|
||||||
/* walk the list of devices to find matching entry */
|
/* walk the list of devices to find matching entry */
|
||||||
|
if (modelnumber < 0)
|
||||||
|
{
|
||||||
dn = 0;
|
dn = 0;
|
||||||
while ((vendor != rts8891_usb_device_list[dn].vendor_id
|
while ((vendor != rts8891_usb_device_list[dn].vendor_id
|
||||||
|| product != rts8891_usb_device_list[dn].product_id)
|
|| product != rts8891_usb_device_list[dn].product_id)
|
||||||
|
@ -2255,6 +2338,11 @@ attach_Rts8891 (const char *devicename)
|
||||||
DBG (DBG_proc, "attach_Rts8891: exit\n");
|
DBG (DBG_proc, "attach_Rts8891: exit\n");
|
||||||
return SANE_STATUS_UNSUPPORTED;
|
return SANE_STATUS_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dn = modelnumber;
|
||||||
|
}
|
||||||
|
|
||||||
/* allocate device struct */
|
/* allocate device struct */
|
||||||
device = malloc (sizeof (*device));
|
device = malloc (sizeof (*device));
|
||||||
|
@ -6327,6 +6415,8 @@ update_button_status (struct Rts8891_Session *session)
|
||||||
lock = SANE_TRUE;
|
lock = SANE_TRUE;
|
||||||
|
|
||||||
/* claim the interface to reserve device */
|
/* claim the interface to reserve device */
|
||||||
|
if (allowsharing == SANE_TRUE)
|
||||||
|
{
|
||||||
status = sanei_usb_claim_interface (session->dev->devnum, 0);
|
status = sanei_usb_claim_interface (session->dev->devnum, 0);
|
||||||
if (status != SANE_STATUS_GOOD)
|
if (status != SANE_STATUS_GOOD)
|
||||||
{
|
{
|
||||||
|
@ -6335,15 +6425,19 @@ update_button_status (struct Rts8891_Session *session)
|
||||||
return SANE_STATUS_DEVICE_BUSY;
|
return SANE_STATUS_DEVICE_BUSY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* effective button reading */
|
/* effective button reading */
|
||||||
status = rts8891_read_buttons (session->dev->devnum, &mask);
|
status = rts8891_read_buttons (session->dev->devnum, &mask);
|
||||||
|
|
||||||
/* release interface if needed */
|
/* release interface if needed */
|
||||||
if (lock == SANE_TRUE)
|
if (lock == SANE_TRUE)
|
||||||
|
{
|
||||||
|
if (allowsharing == SANE_TRUE)
|
||||||
{
|
{
|
||||||
sanei_usb_release_interface (session->dev->devnum, 0);
|
sanei_usb_release_interface (session->dev->devnum, 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < session->dev->model->buttons; i++)
|
for (i = 0; i < session->dev->model->buttons; i++)
|
||||||
{
|
{
|
||||||
|
@ -6366,12 +6460,15 @@ set_lamp_state (struct Rts8891_Session *session, int on)
|
||||||
SANE_Byte reg;
|
SANE_Byte reg;
|
||||||
|
|
||||||
/* claim the interface reserve device */
|
/* claim the interface reserve device */
|
||||||
|
if (allowsharing == SANE_TRUE)
|
||||||
|
{
|
||||||
status = sanei_usb_claim_interface (session->dev->devnum, 0);
|
status = sanei_usb_claim_interface (session->dev->devnum, 0);
|
||||||
if (status != SANE_STATUS_GOOD)
|
if (status != SANE_STATUS_GOOD)
|
||||||
{
|
{
|
||||||
DBG (DBG_warn, "set_lamp_state: cannot claim usb interface\n");
|
DBG (DBG_warn, "set_lamp_state: cannot claim usb interface\n");
|
||||||
return SANE_STATUS_DEVICE_BUSY;
|
return SANE_STATUS_DEVICE_BUSY;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
status = sanei_rts88xx_read_reg (session->dev->devnum, LAMP_REG, ®);
|
status = sanei_rts88xx_read_reg (session->dev->devnum, LAMP_REG, ®);
|
||||||
if (on)
|
if (on)
|
||||||
|
@ -6385,12 +6482,15 @@ set_lamp_state (struct Rts8891_Session *session, int on)
|
||||||
reg = session->dev->regs[LAMP_REG] & 0x7F;
|
reg = session->dev->regs[LAMP_REG] & 0x7F;
|
||||||
#ifdef HAVE_SYS_TIME_H
|
#ifdef HAVE_SYS_TIME_H
|
||||||
/* if lamp is switched off, warming up will be needed */
|
/* if lamp is switched off, warming up will be needed */
|
||||||
session->dev->last_scan.tv_sec=0;
|
session->dev->last_scan.tv_sec = 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
status = sanei_rts88xx_write_reg (session->dev->devnum, LAMP_REG, ®);
|
status = sanei_rts88xx_write_reg (session->dev->devnum, LAMP_REG, ®);
|
||||||
|
|
||||||
/* release interface and return status from lamp setting */
|
/* release interface and return status from lamp setting */
|
||||||
|
if (allowsharing == SANE_TRUE)
|
||||||
|
{
|
||||||
sanei_usb_release_interface (session->dev->devnum, 0);
|
sanei_usb_release_interface (session->dev->devnum, 0);
|
||||||
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,7 +286,7 @@ sanei_configure_attach (const char *config_file, SANEI_Config * config,
|
||||||
/* search for a matching descriptor */
|
/* search for a matching descriptor */
|
||||||
i = 0;
|
i = 0;
|
||||||
found = SANE_FALSE;
|
found = SANE_FALSE;
|
||||||
while (i < config->count && !found)
|
while (config!=NULL && i < config->count && !found)
|
||||||
{
|
{
|
||||||
if (strcmp (config->descriptors[i]->name, token) == 0)
|
if (strcmp (config->descriptors[i]->name, token) == 0)
|
||||||
{
|
{
|
||||||
|
@ -422,6 +422,7 @@ sanei_configure_attach (const char *config_file, SANEI_Config * config,
|
||||||
* function. */
|
* function. */
|
||||||
DBG (3, "sanei_configure_attach: trying to attach with '%s'\n",
|
DBG (3, "sanei_configure_attach: trying to attach with '%s'\n",
|
||||||
lp2);
|
lp2);
|
||||||
|
if(attach!=NULL)
|
||||||
attach (config, lp2);
|
attach (config, lp2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue