2001-05-03 19:40:35 +00:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
2010-06-23 16:21:38 +00:00
|
|
|
/* For putenv */
|
|
|
|
#define _XOPEN_SOURCE
|
2001-05-03 19:40:35 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define __MAIN__
|
|
|
|
|
|
|
|
#include "../backend/umax_pp_low.h"
|
2002-01-06 16:18:52 +00:00
|
|
|
#include "../backend/umax_pp_mid.h"
|
2001-05-03 19:40:35 +00:00
|
|
|
|
2001-09-16 05:57:02 +00:00
|
|
|
static void
|
2001-05-03 19:40:35 +00:00
|
|
|
Usage (char *name)
|
|
|
|
{
|
|
|
|
fprintf (stderr,
|
2004-08-25 19:51:58 +00:00
|
|
|
"%s [-c color_mode] [-x coord] [-y coord] [-w width] [-h height] [-g gain] [-z offset] [-d dpi] [-t level] [-s] [-p] [-l 0|1] [-a ioport_addr] [-r]\n",
|
2001-05-03 19:40:35 +00:00
|
|
|
name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
char dbgstr[80];
|
|
|
|
int probe = 0;
|
2004-06-12 05:20:53 +00:00
|
|
|
int port = 0;
|
2002-02-20 05:46:38 +00:00
|
|
|
char *name = NULL;
|
2001-05-03 19:40:35 +00:00
|
|
|
int scan = 0;
|
|
|
|
int lamp = -1;
|
2004-05-03 05:14:20 +00:00
|
|
|
int i, fd;
|
2001-05-03 19:40:35 +00:00
|
|
|
int found;
|
|
|
|
int recover = 0;
|
|
|
|
int trace = 0;
|
2004-05-15 05:03:42 +00:00
|
|
|
int maxw, maxh;
|
2001-05-03 19:40:35 +00:00
|
|
|
|
|
|
|
/* scanning parameters : defaults to preview (75 dpi color, full scan area) */
|
2004-08-25 19:51:58 +00:00
|
|
|
int gain = 0x0;
|
|
|
|
int offset = 0x646;
|
2001-05-03 19:40:35 +00:00
|
|
|
int dpi = 75;
|
|
|
|
int x = 0, y = 0;
|
2004-05-03 05:14:20 +00:00
|
|
|
int width = -1, height = -1;
|
2001-05-03 19:40:35 +00:00
|
|
|
int color = RGB_MODE;
|
|
|
|
|
2004-06-12 05:20:53 +00:00
|
|
|
char **ports;
|
|
|
|
int rc;
|
2001-05-03 19:40:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* option parsing */
|
|
|
|
/*
|
2003-02-25 07:04:12 +00:00
|
|
|
-c --color : color mode: RGB, BW, BW12, RGB12
|
|
|
|
-x : x coordinate
|
|
|
|
-y : y coordinate
|
|
|
|
-w --witdh : scan width
|
|
|
|
-h --height : scan height
|
|
|
|
-f --file : session file
|
|
|
|
-p --probe : probe scanner
|
|
|
|
-s --scan : scan
|
|
|
|
-t --trace : execution trace
|
|
|
|
-l --lamp : turn lamp on/off 1/0
|
|
|
|
-d --dpi : set scan resolution
|
2004-08-25 19:51:58 +00:00
|
|
|
-g --gain : set RVB gain
|
|
|
|
-z --offset: set offset
|
2003-02-25 07:04:12 +00:00
|
|
|
-a --addr : io port address
|
|
|
|
-n --name : ppdev device name
|
|
|
|
-r : recover from previous failed scan
|
|
|
|
-m --model : model revision
|
2001-05-03 19:40:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
i = 1;
|
|
|
|
trace = 0;
|
2002-02-05 07:16:12 +00:00
|
|
|
sanei_umax_pp_setauto (1);
|
2001-05-03 19:40:35 +00:00
|
|
|
while (i < argc)
|
|
|
|
{
|
|
|
|
found = 0;
|
|
|
|
|
|
|
|
if ((strcmp (argv[i], "-p") == 0) || (strcmp (argv[i], "--probe") == 0))
|
|
|
|
{
|
|
|
|
probe = 1;
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((strcmp (argv[i], "-c") == 0) || (strcmp (argv[i], "--color") == 0))
|
|
|
|
{
|
|
|
|
if (i == (argc - 1))
|
|
|
|
{
|
|
|
|
Usage (argv[0]);
|
|
|
|
fprintf (stderr, "expected color mode value\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
color = 0;
|
|
|
|
i++;
|
|
|
|
found = 1;
|
|
|
|
if (strcmp (argv[i], "RGB") == 0)
|
|
|
|
color = RGB_MODE;
|
|
|
|
if (strcmp (argv[i], "RGB12") == 0)
|
|
|
|
color = RGB12_MODE;
|
|
|
|
if (strcmp (argv[i], "BW") == 0)
|
|
|
|
color = BW_MODE;
|
|
|
|
if (strcmp (argv[i], "BW12") == 0)
|
|
|
|
color = BW12_MODE;
|
|
|
|
if (color == 0)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "unexpected color mode value <%s>\n", argv[i]);
|
|
|
|
fprintf (stderr, "Must be RGB, RGB12, BW, or BW12\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (strcmp (argv[i], "-x") == 0)
|
|
|
|
{
|
|
|
|
if (i == (argc - 1))
|
|
|
|
{
|
|
|
|
Usage (argv[0]);
|
|
|
|
fprintf (stderr, "expected x value\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
x = atoi (argv[i + 1]);
|
|
|
|
i++;
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp (argv[i], "-y") == 0)
|
|
|
|
{
|
|
|
|
if (i == (argc - 1))
|
|
|
|
{
|
|
|
|
Usage (argv[0]);
|
|
|
|
fprintf (stderr, "expected y value\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
y = atoi (argv[i + 1]);
|
|
|
|
i++;
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((strcmp (argv[i], "-w") == 0) || (strcmp (argv[i], "--witdh") == 0))
|
|
|
|
{
|
|
|
|
if (i == (argc - 1))
|
|
|
|
{
|
|
|
|
Usage (argv[0]);
|
|
|
|
fprintf (stderr, "expected width value\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
width = atoi (argv[i + 1]);
|
|
|
|
i++;
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((strcmp (argv[i], "-h") == 0)
|
|
|
|
|| (strcmp (argv[i], "--height") == 0))
|
|
|
|
{
|
|
|
|
if (i == (argc - 1))
|
|
|
|
{
|
|
|
|
Usage (argv[0]);
|
|
|
|
fprintf (stderr, "expected height value\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
height = atoi (argv[i + 1]);
|
|
|
|
i++;
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((strcmp (argv[i], "-t") == 0) || (strcmp (argv[i], "--trace") == 0))
|
|
|
|
{
|
|
|
|
if (i == (argc - 1))
|
|
|
|
{
|
|
|
|
Usage (argv[0]);
|
|
|
|
fprintf (stderr, "expected trace value\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
trace = atoi (argv[i + 1]);
|
|
|
|
i++;
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((strcmp (argv[i], "-r") == 0)
|
|
|
|
|| (strcmp (argv[i], "--recover") == 0))
|
|
|
|
{
|
|
|
|
recover = 1;
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((strcmp (argv[i], "-s") == 0) || (strcmp (argv[i], "--scan") == 0))
|
|
|
|
{
|
|
|
|
scan = 1;
|
2004-05-03 05:14:20 +00:00
|
|
|
/* we have to probe again if we scan */
|
|
|
|
probe = 1;
|
2001-05-03 19:40:35 +00:00
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((strcmp (argv[i], "-d") == 0) || (strcmp (argv[i], "--dpi") == 0))
|
|
|
|
{
|
|
|
|
if (i == (argc - 1))
|
|
|
|
{
|
|
|
|
Usage (argv[0]);
|
|
|
|
fprintf (stderr, "expected dpi value\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
dpi = atoi (argv[i + 1]);
|
|
|
|
if ((dpi < 75) || (dpi > 1200))
|
|
|
|
{
|
|
|
|
fprintf (stderr, "dpi value has to be between 75 and 1200\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
if ((dpi != 75)
|
|
|
|
&& (dpi != 150)
|
|
|
|
&& (dpi != 300) && (dpi != 600) && (dpi != 1200))
|
|
|
|
{
|
|
|
|
fprintf (stderr,
|
|
|
|
"dpi value has to be 75, 150, 300, 600 or 1200\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
2004-03-09 06:12:27 +00:00
|
|
|
if ((strcmp (argv[i], "-g") == 0)
|
2004-08-25 19:51:58 +00:00
|
|
|
|| (strcmp (argv[i], "--gain") == 0))
|
2001-05-03 19:40:35 +00:00
|
|
|
{
|
|
|
|
if (i == (argc - 1))
|
|
|
|
{
|
|
|
|
Usage (argv[0]);
|
2004-08-25 19:51:58 +00:00
|
|
|
fprintf (stderr, "expected hex gain value ( ex: A59 )\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
found = 1;
|
|
|
|
if (strlen (argv[i]) != 3)
|
|
|
|
{
|
|
|
|
Usage (argv[0]);
|
2004-08-25 19:51:58 +00:00
|
|
|
fprintf (stderr, "expected hex gain value ( ex: A59 )\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
2004-08-25 19:51:58 +00:00
|
|
|
gain = strtol (argv[i], NULL, 16);
|
2002-02-05 07:16:12 +00:00
|
|
|
sanei_umax_pp_setauto (0);
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((strcmp (argv[i], "-z") == 0)
|
2004-08-25 19:51:58 +00:00
|
|
|
|| (strcmp (argv[i], "--offset") == 0))
|
2001-05-03 19:40:35 +00:00
|
|
|
{
|
|
|
|
if (i == (argc - 1))
|
|
|
|
{
|
|
|
|
Usage (argv[0]);
|
2004-08-25 19:51:58 +00:00
|
|
|
fprintf (stderr, "expected hex offset value ( ex: A59 )\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
found = 1;
|
|
|
|
if (strlen (argv[i]) != 3)
|
|
|
|
{
|
|
|
|
Usage (argv[0]);
|
2004-08-25 19:51:58 +00:00
|
|
|
fprintf (stderr, "expected hex offset value ( ex: A59 )\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
2004-08-25 19:51:58 +00:00
|
|
|
offset = strtol (argv[i], NULL, 16);
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
|
2002-02-20 05:46:38 +00:00
|
|
|
if ((strcmp (argv[i], "-n") == 0) || (strcmp (argv[i], "--name") == 0))
|
|
|
|
{
|
|
|
|
if (i == (argc - 1))
|
|
|
|
{
|
|
|
|
Usage (argv[0]);
|
|
|
|
fprintf (stderr,
|
|
|
|
"expected device name ( ex: /dev/parport0 )\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2002-02-20 05:46:38 +00:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
found = 1;
|
|
|
|
name = argv[i];
|
|
|
|
}
|
2001-05-03 19:40:35 +00:00
|
|
|
if ((strcmp (argv[i], "-a") == 0) || (strcmp (argv[i], "--addr") == 0))
|
|
|
|
{
|
|
|
|
if (i == (argc - 1))
|
|
|
|
{
|
|
|
|
Usage (argv[0]);
|
|
|
|
fprintf (stderr, "expected hex io port value ( ex: 3BC )\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
i++;
|
|
|
|
found = 1;
|
2002-10-31 06:53:52 +00:00
|
|
|
if ((strlen (argv[i]) < 3) || (strlen (argv[i]) > 4))
|
2001-05-03 19:40:35 +00:00
|
|
|
{
|
|
|
|
Usage (argv[0]);
|
|
|
|
fprintf (stderr, "expected hex io port value ( ex: 378 )\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
port = strtol (argv[i], NULL, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((strcmp (argv[i], "-l") == 0) || (strcmp (argv[i], "--lamp") == 0))
|
|
|
|
{
|
|
|
|
if (i == (argc - 1))
|
|
|
|
{
|
|
|
|
Usage (argv[0]);
|
|
|
|
fprintf (stderr, "expected lamp value\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
lamp = atoi (argv[i + 1]);
|
|
|
|
i++;
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
Usage (argv[0]);
|
|
|
|
fprintf (stderr, "unexpected argument <%s>\n", argv[i]);
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* next arg */
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* since we use DBG, we have to set env var */
|
|
|
|
/* according to the required trace level */
|
|
|
|
if (trace)
|
|
|
|
{
|
|
|
|
sprintf (dbgstr, "SANE_DEBUG_UMAX_PP_LOW=%d", trace);
|
|
|
|
putenv (dbgstr);
|
|
|
|
}
|
|
|
|
|
2004-06-12 05:20:53 +00:00
|
|
|
/* no address or device given */
|
|
|
|
rc = 0;
|
|
|
|
if ((name == NULL) && (port == 0))
|
|
|
|
{
|
|
|
|
/* safe tests: user parallel port devices */
|
|
|
|
ports = sanei_parport_find_device ();
|
|
|
|
if (ports != NULL)
|
|
|
|
{
|
|
|
|
i = 0;
|
|
|
|
rc = 0;
|
|
|
|
while ((ports[i] != NULL) && (rc != 1))
|
|
|
|
{
|
|
|
|
rc = sanei_umax_pp_initPort (port, ports[i]);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2001-05-03 19:40:35 +00:00
|
|
|
|
2004-06-12 05:20:53 +00:00
|
|
|
/* try for direct hardware access */
|
|
|
|
if (rc != 1)
|
|
|
|
{
|
|
|
|
ports = sanei_parport_find_port ();
|
|
|
|
i = 0;
|
|
|
|
rc = 0;
|
|
|
|
while ((ports[i] != NULL) && (rc != 1))
|
|
|
|
{
|
|
|
|
rc = sanei_umax_pp_initPort (strtol (ports[i], NULL, 16), NULL);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rc != 1)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "failed to detect a valid device or port!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2001-05-03 19:40:35 +00:00
|
|
|
{
|
2004-06-12 05:20:53 +00:00
|
|
|
if (sanei_umax_pp_initPort (port, name) != 1)
|
|
|
|
{
|
|
|
|
if (port)
|
|
|
|
fprintf (stderr, "failed to gain direct acces to port 0x%X!\n",
|
|
|
|
port);
|
|
|
|
else
|
|
|
|
fprintf (stderr, "failed to gain acces to device %s!\n", name);
|
|
|
|
return 0;
|
|
|
|
}
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
if (trace)
|
2002-02-05 07:16:12 +00:00
|
|
|
{
|
2004-05-15 05:03:42 +00:00
|
|
|
printf
|
2005-08-24 05:35:06 +00:00
|
|
|
("UMAX 610P/1220P/2000P scanning program version 6.4 starting ...\n");
|
2002-02-05 07:16:12 +00:00
|
|
|
#ifdef HAVE_LINUX_PPDEV_H
|
|
|
|
printf ("ppdev character device built-in.\n");
|
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_PARPORT_DIRECTIO
|
2002-02-20 05:46:38 +00:00
|
|
|
printf ("direct hardware access built-in.\n");
|
2002-02-05 07:16:12 +00:00
|
|
|
#endif
|
|
|
|
}
|
2001-05-03 19:40:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* scanning is the default behaviour */
|
|
|
|
if ((!scan) && (lamp < 0) && (!probe))
|
|
|
|
scan = 1;
|
|
|
|
|
|
|
|
|
|
|
|
/* probe scanner */
|
2004-03-09 06:12:27 +00:00
|
|
|
if ((probe) || (lamp >= 0))
|
2001-05-03 19:40:35 +00:00
|
|
|
{
|
2002-01-06 16:18:52 +00:00
|
|
|
printf ("Probing scanner ....\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
if (sanei_umax_pp_probeScanner (recover) != 1)
|
2001-05-03 19:40:35 +00:00
|
|
|
{
|
|
|
|
if (recover)
|
|
|
|
{
|
2004-03-09 06:12:27 +00:00
|
|
|
sanei_umax_pp_initTransport (recover);
|
|
|
|
sanei_umax_pp_endSession ();
|
|
|
|
if (sanei_umax_pp_probeScanner (recover) != 1)
|
2001-05-03 19:40:35 +00:00
|
|
|
{
|
|
|
|
printf ("Recover failed ....\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
printf ("Recover done !\n");
|
|
|
|
}
|
|
|
|
else
|
2004-03-09 06:12:27 +00:00
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* could be written better .... but it is only test */
|
2004-03-09 06:12:27 +00:00
|
|
|
sanei_umax_pp_endSession ();
|
2004-03-15 13:21:13 +00:00
|
|
|
|
2001-05-03 19:40:35 +00:00
|
|
|
/* init transport layer */
|
2004-03-09 06:12:27 +00:00
|
|
|
if (sanei_umax_pp_initTransport (0) != 1)
|
2001-05-03 19:40:35 +00:00
|
|
|
{
|
2004-03-09 06:12:27 +00:00
|
|
|
printf ("initTransport() failed (%s:%d)\n", __FILE__, __LINE__);
|
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
2004-03-09 06:12:27 +00:00
|
|
|
i = sanei_umax_pp_checkModel ();
|
|
|
|
if (i < 600)
|
2001-05-03 19:40:35 +00:00
|
|
|
{
|
2004-03-09 06:12:27 +00:00
|
|
|
sanei_umax_pp_endSession ();
|
|
|
|
printf ("checkModel() failed (%s:%d)\n", __FILE__, __LINE__);
|
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
2004-05-13 05:00:28 +00:00
|
|
|
printf ("UMAX Astra %dP detected \n", i);
|
2001-05-03 19:40:35 +00:00
|
|
|
|
|
|
|
/* free scanner if a scan is planned */
|
|
|
|
if (scan)
|
2004-03-09 06:12:27 +00:00
|
|
|
sanei_umax_pp_endSession ();
|
2004-05-03 05:14:20 +00:00
|
|
|
printf ("Done ....\n");
|
2004-03-09 06:12:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* lamp on/off: must come after probing (610p handling) */
|
|
|
|
if (lamp >= 0)
|
|
|
|
{
|
|
|
|
/* init transport layer */
|
|
|
|
if (trace)
|
|
|
|
printf ("Tryning to set lamp %s\n", lamp ? "on" : "off");
|
|
|
|
if (sanei_umax_pp_initTransport (recover) != 1)
|
|
|
|
{
|
|
|
|
printf ("initTransport() failed (%s:%d)\n", __FILE__, __LINE__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (trace)
|
|
|
|
printf ("initTransport passed...\n");
|
|
|
|
}
|
|
|
|
if (sanei_umax_pp_setLamp (lamp) == 0)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Setting lamp state failed!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (trace)
|
|
|
|
printf ("sanei_umax_pp_setLamp passed...\n");
|
|
|
|
}
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* scan */
|
|
|
|
if (scan)
|
|
|
|
{
|
2004-05-03 05:14:20 +00:00
|
|
|
printf ("Scanning ....\n");
|
|
|
|
if (sanei_umax_pp_getastra () < 1210)
|
|
|
|
{
|
|
|
|
maxw = 2550;
|
|
|
|
maxh = 3500;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
maxw = 5100;
|
|
|
|
maxh = 7000;
|
|
|
|
}
|
|
|
|
if (width < 0)
|
|
|
|
width = maxw;
|
|
|
|
if (height < 0)
|
|
|
|
height = maxh;
|
|
|
|
|
|
|
|
if ((width < 1) || (width > maxw))
|
|
|
|
{
|
|
|
|
fprintf (stderr, "width must be between 1 and %d\n", maxw);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (x + width > maxw)
|
|
|
|
{
|
|
|
|
fprintf (stderr,
|
|
|
|
"Right side of scan area exceed physical limits (x+witdh>%d)\n",
|
|
|
|
maxw);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (y < 0 || y > maxh)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "y must be between 0 and %d\n", maxh - 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (x < 0 || x > maxw)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "x must be between 0 and %d\n", maxw - 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ((height < 1) || (height > maxh))
|
|
|
|
{
|
|
|
|
fprintf (stderr, "height must be between 1 and %d\n", maxh);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (y + height > maxh)
|
|
|
|
{
|
|
|
|
fprintf (stderr,
|
|
|
|
"Bottom side of scan area exceed physical limits (y+height>%d)\n",
|
|
|
|
maxh);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-05-03 19:40:35 +00:00
|
|
|
/* init transport layer */
|
|
|
|
/* 0: failed
|
|
|
|
1: success
|
|
|
|
2: retry
|
|
|
|
*/
|
|
|
|
do
|
|
|
|
{
|
2004-03-09 06:12:27 +00:00
|
|
|
i = sanei_umax_pp_initTransport (recover);
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
while (i == 2);
|
|
|
|
if (i != 1)
|
|
|
|
{
|
2004-03-09 06:12:27 +00:00
|
|
|
printf ("initTransport() failed (%s:%d)\n", __FILE__, __LINE__);
|
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
/* init scanner */
|
2004-03-09 06:12:27 +00:00
|
|
|
if (sanei_umax_pp_initScanner (recover) == 0)
|
2001-05-03 19:40:35 +00:00
|
|
|
{
|
2004-03-09 06:12:27 +00:00
|
|
|
sanei_umax_pp_endSession ();
|
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
2004-06-12 05:20:53 +00:00
|
|
|
|
|
|
|
/* set x origin left to right */
|
|
|
|
x = sanei_umax_pp_getLeft () + (maxw - x) - width;
|
|
|
|
|
2001-05-03 19:40:35 +00:00
|
|
|
/* scan */
|
2004-03-09 06:12:27 +00:00
|
|
|
if (sanei_umax_pp_scan
|
2004-08-25 19:51:58 +00:00
|
|
|
(x, y, width, height, dpi, color, gain, offset) != 1)
|
2001-05-03 19:40:35 +00:00
|
|
|
{
|
2004-03-09 06:12:27 +00:00
|
|
|
sanei_umax_pp_endSession ();
|
|
|
|
return 0;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for head parking */
|
2004-03-09 06:12:27 +00:00
|
|
|
sanei_umax_pp_parkWait ();
|
2004-05-03 05:14:20 +00:00
|
|
|
printf ("Done ....\n");
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|
2004-03-09 06:12:27 +00:00
|
|
|
sanei_umax_pp_endSession ();
|
2004-03-15 13:21:13 +00:00
|
|
|
#ifdef HAVE_LINUX_PPDEV_H
|
|
|
|
fd = sanei_umax_pp_getparport ();
|
|
|
|
if (fd > 0)
|
|
|
|
{
|
|
|
|
close (fd);
|
|
|
|
sanei_umax_pp_setparport (0);
|
|
|
|
}
|
|
|
|
#endif
|
2001-05-03 19:40:35 +00:00
|
|
|
|
2004-03-09 06:12:27 +00:00
|
|
|
return 1;
|
2001-05-03 19:40:35 +00:00
|
|
|
}
|