p5 (Parallel Port Primax PagePartner) backend files addition

merge-requests/1/head
Stphane Voltz 2010-02-15 06:46:04 +01:00
rodzic f8b3f9c7ab
commit 982bf43a64
7 zmienionych plików z 4351 dodań i 0 usunięć

2044
backend/p5.c 100644

Plik diff jest za duży Load Diff

10
backend/p5.conf.in 100644
Wyświetl plik

@ -0,0 +1,10 @@
# configuration file for the p5 backend.
# configuration option to override detected model name
#option modelname "Prima PagePartner"
# when the parser find this line, it detects it is not an option,
# then it calls the attach function with this value.
# Currently only user mode parallel port support is possible:
# auto, /dev/paraport* (ppdev device name)
auto

206
backend/p5.h 100644
Wyświetl plik

@ -0,0 +1,206 @@
/* sane - Scanner Access Now Easy.
Copyright (C) 2009 stef.dev@free.fr
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.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
*/
/** @file p5.h
* @brief Declaration of high level structures used by the p5 backend.
*
* The structures and functions declared here are used to do the deal with
* the SANE API.
*/
#ifndef P5_H
#define P5_H
#include "../include/sane/config.h"
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <sys/types.h>
#include <unistd.h>
#ifdef HAVE_LIBC_H
# include <libc.h>
#endif
#include "../include/sane/sane.h"
#include "../include/sane/saneopts.h"
#include "../include/sane/sanei_config.h"
#include "../include/sane/sanei_backend.h"
/**< macro to enable an option */
#define ENABLE(OPTION) session->options[OPTION].cap &= ~SANE_CAP_INACTIVE
/**< macro to disable an option */
#define DISABLE(OPTION) session->options[OPTION].cap |= SANE_CAP_INACTIVE
/** macro to test is an option is active */
#define IS_ACTIVE(OPTION) (((s->opt[OPTION].cap) & SANE_CAP_INACTIVE) == 0)
/**< name of the configuration file */
#define P5_CONFIG_FILE "p5.conf"
/**< macro to define texts that should translated */
#ifndef SANE_I18N
#define SANE_I18N(text) text
#endif
/** color mode names
*/
/* @{ */
#define COLOR_MODE "Color"
#define GRAY_MODE "Gray"
#define LINEART_MODE "Lineart"
/* @} */
#include "p5_device.h"
/**
* List of all SANE options available for the frontend. Given a specific
* device, some options may be set to inactive when the scanner model is
* detected. The default values and the ranges they belong maybe also model
* dependent.
*/
enum P5_Options
{
OPT_NUM_OPTS = 0, /** first enum which must be zero */
/** @name standard options group
*/
/* @{ */
OPT_STANDARD_GROUP,
OPT_MODE, /** set the mode: color, grey levels or lineart */
OPT_PREVIEW, /** set up for preview */
OPT_RESOLUTION, /** set scan's resolution */
/* @} */
/** @name geometry group
* geometry related options
*/
/* @{ */
OPT_GEOMETRY_GROUP, /** group of options defining the position and size of the scanned area */
OPT_TL_X, /** top-left x of the scanned area*/
OPT_TL_Y, /** top-left y of the scanned area*/
OPT_BR_X, /** bottom-right x of the scanned area*/
OPT_BR_Y, /** bottom-right y of the scanned area*/
/* @} */
/** @name sensor group
* detectors group
*/
/* @{ */
OPT_SENSOR_GROUP,
OPT_PAGE_LOADED_SW,
OPT_NEED_CALIBRATION_SW,
/* @} */
/** @name button group
* buttons group
*/
/* @{ */
OPT_BUTTON_GROUP,
OPT_CALIBRATE,
OPT_CLEAR_CALIBRATION,
/* @} */
/** @name option list terminator
* must come last so it can be used for array and list size
*/
NUM_OPTIONS
};
/**
* Contains one SANE option description and its value.
*/
typedef struct P5_Option
{
SANE_Option_Descriptor descriptor; /** option description */
Option_Value value; /** option value */
} P5_Option;
/**
* Frontend session. This struct holds informations usefull for
* the functions defined in SANE's standard. Informations closer
* to the hardware are in the P5_Device structure. There is
* as many session structure than frontends using the backend.
*/
typedef struct P5_Session
{
/**
* Point to the next session in a linked list
*/
struct P5_Session *next;
/**
* low-level device object used by the session
*/
P5_Device *dev;
/**
* array of possible options and their values for the backend
*/
P5_Option options[NUM_OPTIONS];
/**
* SANE_True if a scan is in progress, ie sane_start has been called.
* Stay SANE_True until sane_cancel() is called.
*/
SANE_Bool scanning;
/** @brief non blocking flag
* SANE_TRUE if sane_read are non-blocking, ie returns immediatly if there
* is no data available from the scanning device. Modified by sane_set_io_mode()
*/
SANE_Bool non_blocking;
/**
* SANE Parameters describes what the next or current scan will be
* according to the current values of the options
*/
SANE_Parameters params;
/**
* bytes to send to frontend for the scan
*/
SANE_Int to_send;
/**
* bytes currently sent to frontend during the scan
*/
SANE_Int sent;
} P5_Session;
static SANE_Status probe_p5_devices (void);
static P5_Model *probe (const char *devicename);
static SANE_Status config_attach (SANEI_Config * config, const char *devname);
static SANE_Status attach_p5 (const char *name, SANEI_Config * config);
static SANE_Status init_options (struct P5_Session *session);
static SANE_Status compute_parameters (struct P5_Session *session);
#endif /* not P5_H */

1596
backend/p5_device.c 100644

Plik diff jest za duży Load Diff

304
backend/p5_device.h 100644
Wyświetl plik

@ -0,0 +1,304 @@
/* sane - Scanner Access Now Easy.
Copyright (C) 2009 stef.dev@free.fr
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.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
*/
/** @file p5_device.h
* @brief Declaration of low level structures used by the p5 backend.
*
* The structures and function declared here are used to do the low level
* communication with the physical device.
*/
#ifndef P5_DEVICE_H
#define P5_DEVICE_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_LINUX_PPDEV_H
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/ppdev.h>
#include <linux/parport.h>
#endif
/** @name debugging levels
*/
/* @{ */
#define DBG_error0 0 /* errors/warnings printed even with devuglevel 0 */
#define DBG_error 1 /* fatal errors */
#define DBG_warn 2 /* warnings and non-fatal errors */
#define DBG_info 4 /* informational messages */
#define DBG_proc 8 /* starting/finishing functions */
#define DBG_trace 16 /* tracing messages */
#define DBG_io 32 /* io functions */
#define DBG_io2 64 /* io functions that are called very often */
#define DBG_data 128 /* log image data */
/* @} */
/**
* maximal number of resolutions
*/
#define MAX_RESOLUTIONS 8
/**> sensor's number of pixels 8.5' @ 300 dpi */
#define MAX_SENSOR_PIXELS 2550
/**> number of lines to skip when doing calibration */
#define CALIBRATION_SKIP_LINES 80
/**> last value considered as black for calibration */
#define BLACK_LEVEL 40
/**> white target value for calibration */
#define WHITE_TARGET 220.0
/** per dpi calibration rgb data
* Calibration data structure
*/
typedef struct P5_Calibration_Data
{
unsigned int dpi;
u_int8_t black_data[MAX_SENSOR_PIXELS * 3];
u_int8_t white_data[MAX_SENSOR_PIXELS * 3];
} P5_Calibration_Data;
/**
* This structure describes a particular model which is handled by the backend.
* Contained data is immutable and is used to initalize the P5_Device
* structure.
*/
typedef struct P5_Model
{
/** @name device identifier
* These values are set up once the physical device has been detected. They
* are used to build the return value of sane_get_devices().
*/
/* @{ */
SANE_String_Const name;
SANE_String_Const vendor;
SANE_String_Const product;
SANE_String_Const type;
/* @} */
/** @name resolution
* list of avalailable physical resolution.
* The resolutions must sorted from lower to higher value. The list is terminated
* by a value of 0.
*/
/* @{ */
int xdpi_values[MAX_RESOLUTIONS]; /** possible x resolutions */
int ydpi_values[MAX_RESOLUTIONS]; /** possible y resolutions */
/* @} */
/** @name scan area description
* Minimal and maximal values. It's easier to have dedicated members instead
* of searching these values in the dpi lists. They are initialized from dpi
* lists.
*/
/* @{ */
int max_xdpi; /** physical maximum x dpi */
int max_ydpi; /** physical maximum y dpi */
int min_xdpi; /** physical minimum x dpi */
int min_ydpi; /** physical minimum y dpi */
/* @} */
/** @name line distance shift
* Distance between CCD arrays for each color. Expressed in line
* number at maximum motor resolution.
*/
int lds;
/** @name scan area description
* The geometry values are expressed from the head parking position,
* or the start. For a given model, the scan area selected by a frontend
* will have to fit within these values.
*/
/* @{ */
SANE_Fixed x_offset; /** Start of scan area in mm */
SANE_Fixed y_offset; /** Start of scan area in mm */
SANE_Fixed x_size; /** Size of scan area in mm */
SANE_Fixed y_size; /** Size of scan area in mm */
/* @} */
} P5_Model;
/**
* Enumeration of configuration options for a device. It must starts at 0.
*/
enum P5_Configure_Option
{
CFG_MODEL_NAME = 0, /**<option to override model name */
NUM_CFG_OPTIONS /** MUST be last to give the actual number of configuration options */
};
/**
* Device specific configuration structure to hold option values for
* devices handled by the p5 backend. There must one member for
* each configuration option.
*/
typedef struct P5_Config
{
SANE_String modelname; /** model name to use, overrinding the one from detection */
} P5_Config;
/**
* Hardware device description.
* Since the settings used for a scan may actually differ from the one of the
* SANE level, it may contains scanning parameters and data relative to a current
* scan such as data buffers and counters.
*/
typedef struct P5_Device
{
/**
* Point to the next device in a linked list
*/
struct P5_Device *next;
/**
* Points to a structure that decribes model capabilities, geometry
* and default settings.
*/
P5_Model *model;
/**
* @brief name of the device
* Name of the device: it may be the file name used to access the hardware.
* For instance parport0 for a parallel port device, or the libusb file name
* for an USB scanner.
*/
SANE_String name;
/**
* SANE_TRUE if the device is local (ie not over network)
*/
SANE_Bool local;
/**
* True if device has been intialized.
*/
SANE_Bool initialized;
/**
* Configuration options for the device read from
* configuration file at attach time. This member is filled at
* attach time.
*/
P5_Config *config;
/** @brief scan parameters
* The scan done by the hardware can be different from the one at the SANE
* frontend session. For instance:
* - xdpy and ydpi may be different to accomodate hardware capabilites.
* - many CCD scanners need to scan more lines to correct the 'line
* distance shift' effect.
* - emulated modes (lineart from gray scan, or gray scan for color one)
*/
/* @{ */
int xdpi; /** real horizontal resolution */
int ydpi; /** real vertical resolution */
int lines; /** physical lines to scan */
int pixels; /** physical width of scan area */
int bytes_per_line; /** number of bytes per line */
int xstart; /** x start coordinate */
int ystart; /** y start coordinate */
int mode; /** color, gray or lineart mode */
int lds; /** line distance shift */
/* @} */
/** @brief device file descriptor
* low level device file descriptor
*/
int fd;
/**
* work buffer for scans
*/
u_int8_t *buffer;
/**
* buffer size
*/
size_t size;
/**
* position in buffer
*/
size_t position;
/**
* top value of available bytes in buffer
*/
size_t top;
/**
* bottom value of available bytes in buffer
*/
size_t bottom;
/**
* True if device has been calibrated.
*/
SANE_Bool calibrated;
P5_Calibration_Data *calibration_data[MAX_RESOLUTIONS * 2];
/**> correction coefficient for the current scan */
float *gain;
u_int8_t *offset;
} P5_Device;
#define DATA 0
#define STATUS 1
#define CONTROL 2
#define EPPADR 3
#define EPPDATA 4
#define REG0 0x00
#define REG1 0x11
#define REG2 0x22
#define REG3 0x33
#define REG4 0x44
#define REG5 0x55
#define REG6 0x66
#define REG7 0x77
#define REG8 0x88
#define REG9 0x99
#define REGA 0xAA
#define REGB 0xBB
#define REGC 0xCC
#define REGD 0xDD
#define REGE 0xEE
#define REGF 0xFF
#define MODE_COLOR 0
#define MODE_GRAY 1
#define MODE_LINEART 2
#endif /* not P5_DEVICE_H */
/* vim: set sw=2 cino=>2se-1sn-1s{s^-1st0(0u0 smarttab expandtab: */

Wyświetl plik

@ -0,0 +1,31 @@
;
; SANE Backend specification file
;
; It's basically emacs-lisp --- so ";" indicates comment to end of line.
; All syntactic elements are keyword tokens, followed by a string or
; keyword argument, as specified.
;
; ":backend" *must* be specified.
; All other information is optional (but what good is the file without it?).
;
:backend "p5" ; name of backend
:version "1" ; version of backend
:manpage "sane-p5" ; name of manpage (if it exists)
; backend's web page
:url "http://www.sane-project.org/"
:devicetype :scanner ; start of a list of devices....
; other types: :stillcam, :vidcam,
; :meta, :api
:mfg "PRIMAX" ; name a manufacturer
:url "http://www.primax.com.tw"
:model "PagePartner"
:interface "Parport (EPP/ECP)"
:status :basic
:comment "Sheetfed scanner, work in gray and color, but uncalibrated scans"
; :comment and :url specifiers are optional after :mfg, :model, :desc,
; and at the top-level.

160
doc/sane-p5.man 100644
Wyświetl plik

@ -0,0 +1,160 @@
.TH "sane\-p5" "5" "15 Feb 2010" "@PACKAGEVERSION@" "SANE Scanner Access Now Easy"
.IX sane\-p5
.SH "NAME"
sane\-p5 \- SANE backend for the Primax PagePartner
.SH "DESCRIPTION"
The
.B sane\-p5
library implements a SANE (Scanner Access Now Easy) backend that
provides access to the Primax PagePartner parallel port sheet fed scanner.
.PP
This backend handles 100, 150, 200, 300 and 600 dpi scan resolutions,
in color and gray modes. The 600 dpi is actually 300x600 with lines
enlarged to match the vertical resolution.
.PP
.B EPP/ECP MODES ONLY
The current version of the backend uses only EPP or ECP mode to communicate
with the scanner. It is
recommended that you set your parallel port to EPP in BIOS with the current
version of this backend. ECPEPP will only
work if you use a 2.4 or 2.6 kernel with ppdev character device support.
.PP
.SH "DEVICE NAMES"
This backend expects device names of the form:
.PP
.RS
.I port value
.RE
.PP
Where
\fBvalue\fR is :
.RS
.TP
auto
autodetect all parallel ports and probe
them for scanner
.TP
/dev/parport0
uses linux ppdev device, depending on the
number of available parallel port, you
have to use /dev/parport1, /dev/parport2, ...
.PP
.RE
You can rename any device using the
.PP
.RS
.br
.I option name my_name
.RE
.PP
option. This option apply to the last port option.
.SH "CONFIGURATION"
Please make sure to edit dll.conf
.B before
you use the backend, since this backend isn't enabled by default.
.PP
.PP
.SH "FILES"
.TP
.I @CONFIGDIR@/p5.conf
The backend configuration file (see also description of
.B SANE_CONFIG_DIR
below).
.TP
.I @LIBDIR@/libsane\-p5.a
The static library implementing this backend.
.TP
.I @LIBDIR@/libsane\-p5.so
The shared library implementing this backend (present on systems that
support dynamic loading).
.SH "ENVIRONMENT"
.TP
.B SANE_CONFIG_DIR
This environment variable specifies the list of directories that may
contain the configuration file. Under UNIX, the directories are
separated by a colon (`:'), under OS/2, they are separated by a
semi-colon (`;'). If this variable is not set, the configuration file
is searched in two default directories: first, the current working
directory (".") and then in @CONFIGDIR@. If the value of the
environment variable ends with the directory separator character, then
the default directories are searched after the explicitly specified
directories. For example, setting
.B SANE_CONFIG_DIR
to "/tmp/config:" would result in directories "tmp/config", ".", and
"@CONFIGDIR@" being searched (in this order).
.TP
.B SANE_DEBUG_P5
If the library was compiled with debug support enabled, this
environment variable controls the debug level for this backend. E.g.,
a value of 255 requests all debug output to be printed. Smaller
levels reduce verbosity.
.PP
.RS
.ft CR
.nf
level debug output
\-\-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
0 critical errors
1 errors
2 warnings & minor errors
4 information messages
8 start/stop of functions
16 tracing messages
32 I/O functions
64 I/O functions with traces
128 scanned/calibration data
.fi
.ft R
.RE
.PP
.TP
.PP
.RS
.ft CR
.nf
.PP
.PP
.SH "SEE ALSO"
sane(7), sane\-net(5), saned(8)
.SH "AUTHOR"
St\['e]phane VOLTZ <stef.dev@free.fr>
.SH "CREDITS"
Support for the Prima PagePartner has been made possible thank to an hardware donation
by Sébastien Lange.
.SH "BUG REPORTS"
If something doesn't work mail sane-devel@lists.alioth.debian.org or use the bug
tracker at https://alioth.debian.org/tracker/?atid=410366&group_id=30186 .
Please give as much information as you can.
.TP
.I SANE version
run "scanimage \-V" to determine this
.TP
.I the backend version and your scanner hardware
run "SANE_DEBUG_P5=255 scanimage \-L 2>log" as root. If you don't get any output
from the p5 backend, make sure a line "p5" is included into
your @CONFIGDIR@/dll.conf.
If your scanner isn't detected, make sure you've defined the right port address, or the
correct device
in your p5.conf.
.TP
.I the name of your scanner/vendor
also a worthy information. Please also include the optical resolution and lamp type of your scanner, both can be found in the manual of your scanner.
.TP
.I any further comments
if you have comments about the documentation (what could be done better), or you
think I should know something, please include it.