1 /* sane - Scanner Access Now Easy.
2 
3    Copyright (C) 2009-2012 stef.dev@free.fr
4 
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 
18 */
19 
20 /** @file p5.h
21  * @brief Declaration of high level structures used by the p5 backend.
22  *
23  * The structures and functions declared here are used to do the deal with
24  * the SANE API.
25  */
26 
27 
28 #ifndef P5_H
29 #define P5_H
30 
31 #include "../include/sane/config.h"
32 
33 #include <errno.h>
34 #include <fcntl.h>
35 #include <limits.h>
36 #include <signal.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <ctype.h>
41 #include <time.h>
42 
43 #include <sys/types.h>
44 #include <unistd.h>
45 
46 #include "../include/sane/sane.h"
47 #include "../include/sane/saneopts.h"
48 #include "../include/sane/sanei_config.h"
49 #include "../include/sane/sanei_backend.h"
50 
51 /**< macro to enable an option */
52 #define ENABLE(OPTION)  session->options[OPTION].descriptor.cap &= ~SANE_CAP_INACTIVE
53 
54 /**< macro to disable an option */
55 #define DISABLE(OPTION) session->options[OPTION].descriptor.cap |=  SANE_CAP_INACTIVE
56 
57 /** macro to test is an option is active */
58 #define IS_ACTIVE(OPTION) (((s->opt[OPTION].cap) & SANE_CAP_INACTIVE) == 0)
59 
60 /**< name of the configuration file */
61 #define P5_CONFIG_FILE "p5.conf"
62 
63 /**< macro to define texts that should translated */
64 #ifndef SANE_I18N
65 #define SANE_I18N(text) text
66 #endif
67 
68 /** color mode names
69  */
70 /* @{ */
71 #define COLOR_MODE              "Color"
72 #define GRAY_MODE               "Gray"
73 #define LINEART_MODE            "Lineart"
74 /* @} */
75 
76 #include "p5_device.h"
77 
78 /**
79  * List of all SANE options available for the frontend. Given a specific
80  * device, some options may be set to inactive when the scanner model is
81  * detected. The default values and the ranges they belong maybe also model
82  * dependent.
83  */
84 enum P5_Options
85 {
86   OPT_NUM_OPTS = 0,		/** first enum which must be zero */
87   /** @name standard options group
88    */
89   /* @{ */
90   OPT_STANDARD_GROUP,
91   OPT_MODE,			/** set the mode: color, grey levels or lineart */
92   OPT_PREVIEW,			/** set up for preview */
93   OPT_RESOLUTION,		/** set scan's resolution */
94   /* @} */
95 
96   /** @name geometry group
97    * geometry related options
98    */
99   /* @{ */
100   OPT_GEOMETRY_GROUP,		/** group of options defining the position and size of the scanned area */
101   OPT_TL_X,			/** top-left x of the scanned area*/
102   OPT_TL_Y,			/** top-left y of the scanned area*/
103   OPT_BR_X,			/** bottom-right x of the scanned area*/
104   OPT_BR_Y,			/** bottom-right y of the scanned area*/
105   /* @} */
106 
107   /** @name sensor group
108    * detectors group
109    */
110   /* @{ */
111   OPT_SENSOR_GROUP,
112   OPT_PAGE_LOADED_SW,
113   OPT_NEED_CALIBRATION_SW,
114   /* @} */
115 
116   /** @name button group
117    * buttons group
118    */
119   /* @{ */
120   OPT_BUTTON_GROUP,
121   OPT_CALIBRATE,
122   OPT_CLEAR_CALIBRATION,
123   /* @} */
124 
125   /** @name option list terminator
126    * must come last so it can be used for array and list size
127    */
128   NUM_OPTIONS
129 };
130 
131 /**
132  * Contains one SANE option description and its value.
133  */
134 typedef struct P5_Option
135 {
136   SANE_Option_Descriptor descriptor;	/** option description */
137   Option_Value value;			/** option value */
138 } P5_Option;
139 
140 /**
141  * Frontend session. This struct holds information useful for
142  * the functions defined in SANE's standard. Information closer
143  * to the hardware are in the P5_Device structure. There is
144  * as many session structure than frontends using the backend.
145  */
146 typedef struct P5_Session
147 {
148   /**
149    * Point to the next session in a linked list
150    */
151   struct P5_Session *next;
152 
153   /**
154    * low-level device object used by the session
155    */
156   P5_Device *dev;
157 
158   /**
159    * array of possible options and their values for the backend
160    */
161   P5_Option options[NUM_OPTIONS];
162 
163   /**
164    * SANE_True if a scan is in progress, ie sane_start has been called.
165    * Stay SANE_True until sane_cancel() is called.
166    */
167   SANE_Bool scanning;
168 
169   /** @brief non blocking flag
170    * SANE_TRUE if sane_read are non-blocking, ie returns immediately if there
171    * is no data available from the scanning device. Modified by sane_set_io_mode()
172    */
173   SANE_Bool non_blocking;
174 
175   /**
176    * SANE Parameters describes what the next or current scan will be
177    * according to the current values of the options
178    */
179   SANE_Parameters params;
180 
181    /**
182     * bytes to send to frontend for the scan
183     */
184   SANE_Int to_send;
185 
186    /**
187     * bytes currently sent to frontend during the scan
188     */
189   SANE_Int sent;
190 
191 } P5_Session;
192 
193 
194 static SANE_Status probe_p5_devices (void);
195 static P5_Model *probe (const char *devicename);
196 static SANE_Status config_attach (SANEI_Config * config, const char *devname,
197                                   void *data);
198 static SANE_Status attach_p5 (const char *name, SANEI_Config * config);
199 static SANE_Status init_options (struct P5_Session *session);
200 static SANE_Status compute_parameters (struct P5_Session *session);
201 
202 /* vim: set sw=2 cino=>2se-1sn-1s{s^-1st0(0u0 smarttab expandtab: */
203 
204 #endif /* not P5_H */
205