summaryrefslogtreecommitdiff
path: root/backend/p5.h
blob: 14e953a64f482d84c652e794db95883eb73c4ed4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/* sane - Scanner Access Now Easy.

   Copyright (C) 2009-2012 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, see <https://www.gnu.org/licenses/>.

*/

/** @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>

#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].descriptor.cap &= ~SANE_CAP_INACTIVE

/**< macro to disable an option */
#define DISABLE(OPTION) session->options[OPTION].descriptor.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 information useful for
 * the functions defined in SANE's standard. Information 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 immediately 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,
                                  void *data);
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);

/* vim: set sw=2 cino=>2se-1sn-1s{s^-1st0(0u0 smarttab expandtab: */

#endif /* not P5_H */