1#ifndef CARDSCAN_H 2#define CARDSCAN_H 3 4/* 5 * Part of SANE - Scanner Access Now Easy. 6 * Please see opening comment in cardscan.c 7 */ 8 9/* ------------------------------------------------------------------------- 10 * This option list has to contain all options for all scanners supported by 11 * this driver. If a certain scanner cannot handle a certain option, there's 12 * still the possibility to say so, later. 13 */ 14enum scanner_Option 15{ 16 OPT_NUM_OPTS = 0, 17 18 OPT_MODE_GROUP, 19 OPT_MODE, /*mono/gray/color*/ 20 21 /* must come last: */ 22 NUM_OPTIONS 23}; 24 25/* values common to calib and image data */ 26#define HEADER_SIZE 64 27#define PIXELS_PER_LINE 1208 28 29/* values for calib data */ 30#define CAL_COLOR_SIZE (PIXELS_PER_LINE * 3) 31#define CAL_GRAY_SIZE PIXELS_PER_LINE 32 33/* values for image data */ 34#define MAX_PAPERLESS_LINES 210 35 36struct scanner 37{ 38 /* --------------------------------------------------------------------- */ 39 /* immutable values which are set during init of scanner. */ 40 struct scanner *next; 41 char *device_name; /* The name of the scanner device for sane */ 42 43 /* --------------------------------------------------------------------- */ 44 /* immutable values which are set during inquiry probing of the scanner. */ 45 SANE_Device sane; 46 char * vendor_name; 47 char * product_name; 48 49 /* --------------------------------------------------------------------- */ 50 /* immutable values which are set during reading of config file. */ 51 int has_cal_buffer; 52 int lines_per_block; 53 int color_block_size; 54 int gray_block_size; 55 56 /* --------------------------------------------------------------------- */ 57 /* changeable SANE_Option structs provide our interface to frontend. */ 58 59 /* long array of option structs */ 60 SANE_Option_Descriptor opt[NUM_OPTIONS]; 61 62 /* --------------------------------------------------------------------- */ 63 /* some options require lists of strings or numbers, we keep them here */ 64 /* instead of in global vars so that they can differ for each scanner */ 65 66 /*mode group*/ 67 SANE_String_Const mode_list[3]; 68 69 /* --------------------------------------------------------------------- */ 70 /* changeable vars to hold user input. modified by SANE_Options above */ 71 72 /*mode group*/ 73 int mode; /*color,lineart,etc*/ 74 75 /* --------------------------------------------------------------------- */ 76 /* values which are derived from setting the options above */ 77 /* the user never directly modifies these */ 78 79 /* this is defined in sane spec as a struct containing: 80 SANE_Frame format; 81 SANE_Bool last_frame; 82 SANE_Int lines; 83 SANE_Int depth; ( binary=1, gray=8, color=8 (!24) ) 84 SANE_Int pixels_per_line; 85 SANE_Int bytes_per_line; 86 */ 87 SANE_Parameters params; 88 89 /* --------------------------------------------------------------------- */ 90 /* calibration data read once */ 91 unsigned char cal_color_b[CAL_COLOR_SIZE]; 92 unsigned char cal_gray_b[CAL_GRAY_SIZE]; 93 unsigned char cal_color_w[CAL_COLOR_SIZE]; 94 unsigned char cal_gray_w[CAL_GRAY_SIZE]; 95 96 /* --------------------------------------------------------------------- */ 97 /* values which are set by scanning functions to keep track of pages, etc */ 98 int started; 99 int paperless_lines; 100 101 /* buffer part of image */ 102 unsigned char buffer[PIXELS_PER_LINE * 3 * 32]; 103 104 /* how far we have read from scanner into buffer */ 105 int bytes_rx; 106 107 /* how far we have written from buffer to frontend */ 108 int bytes_tx; 109 110 /* --------------------------------------------------------------------- */ 111 /* values used by the command and data sending function */ 112 int fd; /* The scanner device file descriptor. */ 113 114}; 115 116#define USB_COMMAND_TIME 10000 117#define USB_DATA_TIME 10000 118 119#define MODE_COLOR 0 120#define MODE_GRAYSCALE 1 121 122/* ------------------------------------------------------------------------- */ 123 124#define MM_PER_UNIT_UNFIX SANE_UNFIX(SANE_FIX(MM_PER_INCH / 1200.0)) 125#define MM_PER_UNIT_FIX SANE_FIX(SANE_UNFIX(SANE_FIX(MM_PER_INCH / 1200.0))) 126 127#define SCANNER_UNIT_TO_FIXED_MM(number) SANE_FIX((number) * MM_PER_UNIT_UNFIX) 128#define FIXED_MM_TO_SCANNER_UNIT(number) SANE_UNFIX(number) / MM_PER_UNIT_UNFIX 129 130#define CONFIG_FILE "cardscan.conf" 131 132#ifndef PATH_MAX 133# define PATH_MAX 1024 134#endif 135 136/* ------------------------------------------------------------------------- */ 137 138SANE_Status sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize); 139 140SANE_Status sane_get_devices (const SANE_Device *** device_list, 141 SANE_Bool local_only); 142 143SANE_Status sane_open (SANE_String_Const name, SANE_Handle * handle); 144 145SANE_Status sane_set_io_mode (SANE_Handle h, SANE_Bool non_blocking); 146 147SANE_Status sane_get_select_fd (SANE_Handle h, SANE_Int * fdp); 148 149const SANE_Option_Descriptor * sane_get_option_descriptor (SANE_Handle handle, 150 SANE_Int option); 151 152SANE_Status sane_control_option (SANE_Handle handle, SANE_Int option, 153 SANE_Action action, void *val, 154 SANE_Int * info); 155 156SANE_Status sane_start (SANE_Handle handle); 157 158SANE_Status sane_get_parameters (SANE_Handle handle, 159 SANE_Parameters * params); 160 161SANE_Status sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, 162 SANE_Int * len); 163 164void sane_cancel (SANE_Handle h); 165 166void sane_close (SANE_Handle h); 167 168void sane_exit (void); 169 170/* ------------------------------------------------------------------------- */ 171 172static SANE_Status attach_one (const char *devicename); 173static SANE_Status connect_fd (struct scanner *s); 174static SANE_Status disconnect_fd (struct scanner *s); 175 176static SANE_Status 177do_cmd(struct scanner *s, int shortTime, 178 unsigned char * cmdBuff, size_t cmdLen, 179 unsigned char * outBuff, size_t outLen, 180 unsigned char * inBuff, size_t * inLen 181); 182 183static SANE_Status load_calibration (struct scanner *s); 184 185static SANE_Status heat_lamp_color(struct scanner *s); 186static SANE_Status heat_lamp_gray(struct scanner *s); 187 188static SANE_Status read_from_scanner_color(struct scanner *s); 189static SANE_Status read_from_scanner_gray(struct scanner *s); 190 191static SANE_Status power_down(struct scanner *s); 192 193static void hexdump (int level, char *comment, unsigned char *p, int l); 194 195static size_t maxStringSize (const SANE_String_Const strings[]); 196 197#endif /* CARDSCAN_H */ 198