Changed timeouts and added scanner sleeps to improve reliability of 6x0P

models.  Also corrected typo which caused full bed scans to fail.  Disabled
problematic detect for now, will make detection slightly slower. Patch from
Matthew Duggan <stauff1@users.sourceforge.net>.
Henning Meier-Geinitz <henning@meier-geinitz.de>
DEVEL_2_0_BRANCH-1
Henning Geinitz 2002-04-07 11:20:46 +00:00
rodzic 63bfda58be
commit 8e952f2ec6
2 zmienionych plików z 75 dodań i 34 usunięć

Wyświetl plik

@ -138,11 +138,7 @@ int sanei_canon_pp_wake_scanner(struct parport *port)
if (readstatus(port) != READY)
{
DBG(40, "Scanner not ready. Attempting to reset...\n");
if (scanner_reset(port))
{
DBG(10, "Could not gracefully reset scanner.\n");
return 1;
}
scanner_reset(port);
}
do
@ -168,13 +164,12 @@ int sanei_canon_pp_wake_scanner(struct parport *port)
Reply 1 (S3 and S4 on, S5 and S7 off) */
outcont(port, 0, HOSTBUSY); /* C1 off */
/* Reply 2 */
if (expect(port, "Reply 2", 12, 0x1f, 1000000))
return 1;
expect(port, "Reply 2", 12, 0x1f, 800000);
outcont(port, HOSTBUSY, HOSTBUSY); /* C1 on */
if (expect(port, "Reply 3", 0x0b, 0x1f, 1000000))
return 1;
expect(port, "Reply 3", 0x0b, 0x1f, 800000);
outboth(port, 0, NSELECTIN | NINIT | HOSTCLK); /* Clear D, C3+, C1- */
return 0;
}
@ -358,22 +353,25 @@ int sanei_canon_pp_check_status(struct parport *port)
if (verbose)
DBG(10, "* Check Status:\n");
sanei_canon_pp_read(port, 2, data);
if (sanei_canon_pp_read(port, 2, data))
return -1;
status = data[0] | (data[1] << 8);
switch(status)
{
case 0x0606:
if (verbose)
DBG(10, "Ready - 0x0606\n");
if (verbose) DBG(10, "Ready - 0x0606\n");
return 0;
break;
case 0x1414:
if (verbose)
DBG(10, "Busy - 0x1414\n");
if (verbose) DBG(10, "Busy - 0x1414\n");
return 1;
break;
case 0x0805:
if (verbose) DBG(10, "Resetting - 0x0805\n");
return 3;
break;
case 0x1515:
DBG(1, "!! Invalid Command - 0x1515\n");
return 2;
@ -482,7 +480,7 @@ static int scanner_reset(struct parport *port)
outboth(port, 0x04, 0x0d);
/* Specifically, we want this: 00111 on S */
if (expect(port, "Reset 2 response 1", 0x7, 0x1f, 100000))
if (expect(port, "Reset 2 response 1", 0x7, 0x1f, 500000))
return 1;
outcont(port, 0, HOSTCLK);
@ -491,7 +489,7 @@ static int scanner_reset(struct parport *port)
/* All lines 1 */
if (expect(port, "Reset 2 response 2 (READY)",
0x1f, 0x1f, 100000))
0x1f, 0x1f, 500000))
return 1;
outcont(port, 0, HOSTBUSY);
@ -503,7 +501,7 @@ static int scanner_reset(struct parport *port)
outboth(port, 0x04, 0x0d);
/* Specifically, we want this: 00111 on S */
if (expect(port, "Reset 2 response 1", 0x7, 0x1f, 100000))
if (expect(port, "Reset 2 response 1", 0x7, 0x1f, 500000))
return 1;
outcont(port, 0, HOSTCLK);
@ -512,7 +510,7 @@ static int scanner_reset(struct parport *port)
/* All lines 1 */
if (expect(port, "Reset 2 response 2 (READY)",
0x1f, 0x1f, 1000000))
0x1f, 0x1f, 500000))
return 1;
outcont(port, 0, HOSTBUSY);
@ -549,21 +547,38 @@ static int expect(struct parport *port, const char *step, int s,
int sanei_canon_pp_scanner_init(struct parport *port)
{
int tries = 0;
int tmp = 0;
/* Put the scanner in nibble mode */
ieee_negotiation(port, 0x0);
/* No data to read yet - return to idle mode */
scanner_endtransfer(port);
/* Send Command 1 (unknown purpose) */
sanei_canon_pp_write(port, 10, command_1);
/* In Windows, this is always ECP (or an attempt at it) */
sanei_canon_pp_check_status(port);
/* Scanner status check */
sanei_canon_pp_write(port, 10, command_1);
sanei_canon_pp_check_status(port);
/* Note that we don't really mind what the status was as long as it
* wasn't a read error (returns -1) */
if (sanei_canon_pp_check_status(port) < 0)
return -1;
/* Try until it's ready */
sanei_canon_pp_write(port, 10, command_1);
while ((tries < 3) && (tmp = sanei_canon_pp_check_status(port)))
{
if (tmp < 0)
return -1;
DBG(10, "scanner_init: Giving the scanner a snooze "
"(sleeping for 4 seconds)\n");
usleep(4000000);
tries++;
sanei_canon_pp_write(port, 10, command_1);
}
if (tries == 3) return 1;
return 0;
}

Wyświetl plik

@ -291,8 +291,10 @@ sane_init (SANE_Int *vc, SANE_Auth_Callback cb)
/* detect_mode suceeded, so the port is open. This beholdens
* us to call ieee1284_close in any of the remaining error
* cases in this loop. */
#if 0
tmp = sanei_canon_pp_detect(s_tmp->params.port);
if (tmp && (s_tmp->ieee1284_mode != M1284_NIBBLE))
{
/* A failure, try again in nibble mode... */
@ -313,6 +315,7 @@ sane_init (SANE_Int *vc, SANE_Auth_Callback cb)
continue;
}
#endif
/* all signs point to yes, try it out */
if (ieee1284_claim(s_tmp->params.port) != E1284_OK) {
DBG(10, "sane_init: Couldn't claim port %s.\n",
@ -325,9 +328,22 @@ sane_init (SANE_Int *vc, SANE_Auth_Callback cb)
DBG(2, "sane_init: >> initialise\n");
tmp = sanei_canon_pp_initialise(&(s_tmp->params));
DBG(2, "sane_init: << %d initialise\n", tmp);
/* put it back to sleep until we're ready to
* open for business again */
sanei_canon_pp_sleep_scanner(s_tmp->params.port);
/* leave the port open but not claimed - this is regardless
* of the return value of initialise */
ieee1284_release(s_tmp->params.port);
if (tmp && (s_tmp->ieee1284_mode != M1284_NIBBLE))
{
/* A failure, try again in nibble mode... */
DBG(1, "sane_init: Failed on ECP mode, falling "
"back to nibble mode\n");
s_tmp->ieee1284_mode = M1284_NIBBLE;
sanei_canon_pp_set_ieee1284_mode(s_tmp->ieee1284_mode);
tmp = sanei_canon_pp_initialise(&(s_tmp->params));
}
if (tmp) {
DBG(10, "sane_init: Couldn't contact scanner on port "
"%s. Maybe it's not a scanner?\n",
@ -349,6 +365,7 @@ sane_init (SANE_Int *vc, SANE_Auth_Callback cb)
}
/* Cocked, locked and ready to rock */
s_tmp->hw.model = s_tmp->params.name;
s_tmp->scanner_present = SANE_TRUE;
}
@ -386,6 +403,7 @@ sane_get_devices (const SANE_Device ***dl, SANE_Bool local)
{
/* this has been called already */
*dl = devlist;
return SANE_STATUS_GOOD;
}
devlist = malloc ((num_devices + 1) * sizeof (devlist[0]));
if (devlist == NULL)
@ -502,8 +520,7 @@ sane_open (SANE_String_Const name, SANE_Handle *h)
return SANE_STATUS_IO_ERROR;
}
/* Call whatever in simon's code starts the scanner and looks at
* its hairy bits - also sorts IEEE1284 stuff */
/* I put the scanner to sleep before, better wake it back up */
DBG(2, "sane_open: >> initialise\n");
tmp = sanei_canon_pp_initialise(&(cs->params));
@ -515,6 +532,7 @@ sane_open (SANE_String_Const name, SANE_Handle *h)
DBG(1, "sane_open: Can't contact scanner. Try power "
"cycling scanner, and unplug any "
"printers\n");
ieee1284_release(cs->params.port);
return SANE_STATUS_IO_ERROR;
}
@ -705,7 +723,8 @@ sane_control_option (SANE_Handle h, SANE_Int opt, SANE_Action act,
}
break;
case SANE_ACTION_SET_VALUE:
if (val != NULL) i = *((int *)val);
/* val has been checked for NULL if opt != OPT_CAL */
if (opt != OPT_CAL) i = *((int *)val);
if (info != NULL) *info = 0;
switch (opt) {
case OPT_NUM_OPTIONS:
@ -726,8 +745,13 @@ sane_control_option (SANE_Handle h, SANE_Int opt, SANE_Action act,
if (cs->vals[opt] != i)
{
update_ranges(cs);
/* shouldn't have to reload
* params too, but xsane
* seems a bit buggy in that
* respect. it's ok for us
* not to change them */
if (info != NULL) *info |=
SANE_INFO_RELOAD_OPTIONS;
SANE_INFO_RELOAD_OPTIONS | SANE_INFO_RELOAD_PARAMS;
}
if (res630[cs->vals[opt]] !=
*((int *)val))
@ -1413,9 +1437,11 @@ sane_exit (void)
first_dev = NULL;
/* FIXME: this creates a segfault in DLL code. */
/* freeing something it shouldn't perhaps? Leaving this disabled
* leaves a small memory leak between init and exit */
/* FIXEDME: this creates a segfault in DLL code. */
/* freeing something it shouldn't perhaps? */
/* Turns out to be a bug in libieee1284 0.1.4 and only occurs on 2.2
* kernels - have sent mail to Tim Waugh, will leave commented out
* until I receive a reply */
/* ieee1284_free_ports(&pl); */
DBG(2, "<< sane_exit\n");
@ -1673,7 +1699,7 @@ static void update_ranges(CANONP_Scanner *cs)
new_width = cs->params.scanheadwidth /
(max_res / res630[cs->vals[OPT_RESOLUTION]]);
new_height = (cs->params.scanheadwidth == 2552 ? 3508 : 8016) /
new_height = (cs->params.scanheadwidth == 2552 ? 3508 : 7016) /
(max_res / res630[cs->vals[OPT_RESOLUTION]]);
/* Max width has to be divisible by 4 */