1 /*************************************************************************** 2 * SANE - Scanner Access Now Easy. 3 4 gphoto2.h 5 6 03/12/01 - Peter Fales 7 8 Based on the dc210 driver, (C) 1998 Brian J. Murrell (which is 9 based on dc25 driver (C) 1998 by Peter Fales) 10 11 This file (C) 2001 by Peter Fales 12 13 This file is part of the SANE package. 14 15 This program is free software; you can redistribute it and/or 16 modify it under the terms of the GNU General Public License as 17 published by the Free Software Foundation; either version 2 of the 18 License, or (at your option) any later version. 19 20 This program is distributed in the hope that it will be useful, but 21 WITHOUT ANY WARRANTY; without even the implied warranty of 22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 General Public License for more details. 24 25 You should have received a copy of the GNU General Public License 26 along with this program. If not, see <https://www.gnu.org/licenses/>. 27 28 As a special exception, the authors of SANE give permission for 29 30 additional uses of the libraries contained in this release of SANE. 31 32 The exception is that, if you link a SANE library with other files 33 to produce an executable, this does not by itself cause the 34 resulting executable to be covered by the GNU General Public 35 License. Your use of that executable is in no way restricted on 36 account of linking the SANE library code into it. 37 38 This exception does not, however, invalidate any other reasons why 39 the executable file might be covered by the GNU General Public 40 License. 41 42 If you submit changes to SANE to the maintainers to be included in 43 a subsequent release, you agree by submitting the changes that 44 those changes may be distributed with this exception intact. 45 46 If you write modifications of your own for SANE, it is your choice 47 whether to permit this exception to apply to your modifications. 48 If you do not wish that, delete this exception notice. 49 50 *************************************************************************** 51 52 This file implements a SANE backend for the Kodak DC-240 53 digital camera. THIS IS EXTREMELY ALPHA CODE! USE AT YOUR OWN RISK!! 54 55 (feedback to: gphoto2-devel@fales-lorenz.net) 56 57 This backend is based somewhat on the dc25 backend included in this 58 package by Peter Fales, and the dc210 backend by Brian J. Murrell 59 60 ***************************************************************************/ 61 62 #include <stdio.h> 63 #include <stdlib.h> 64 #include <unistd.h> 65 #include <fcntl.h> 66 #include <termios.h> 67 #include <string.h> 68 69 #ifndef TRUE 70 #define TRUE (1==1) 71 #endif 72 73 #ifndef FALSE 74 #define FALSE (!TRUE) 75 #endif 76 77 #ifndef NULL 78 #define NULL 0L 79 #endif 80 81 typedef struct picture_info 82 { 83 int low_res; 84 int size; 85 } 86 PictureInfo; 87 88 typedef struct GPHOTO2_s 89 { 90 SANE_String port; /* the port name it's on */ 91 SANE_Int speed; /* current port speed */ 92 SANE_String camera_name; 93 SANE_Bool scanning; /* currently scanning an image? */ 94 SANE_Byte model; 95 SANE_Byte ver_major; 96 SANE_Byte ver_minor; 97 SANE_Int pic_taken; 98 SANE_Int pic_left; 99 struct 100 { 101 unsigned int low_res:1; 102 unsigned int low_batt:1; 103 } 104 flags; 105 PictureInfo *Pictures; /* array of pictures */ 106 SANE_Int current_picture_number; /* picture being operated on */ 107 } 108 GPHOTO2; 109 110 typedef struct gphoto2_info_s 111 { 112 SANE_Byte model; 113 SANE_Byte ver_major; 114 SANE_Byte ver_minor; 115 SANE_Int pic_taken; 116 SANE_Int pic_left; 117 struct 118 { 119 SANE_Int low_res:1; 120 SANE_Int low_batt:1; 121 } 122 flags; 123 } 124 Gphoto2Info, *Gphoto2InfoPtr; 125 126 static SANE_Int get_info (void); 127 128 #define HIGH_RES 0 129 #define LOW_RES 1 130 131 #define HIGHRES_WIDTH highres_width 132 #define HIGHRES_HEIGHT highres_height 133 134 #define LOWRES_WIDTH lowres_width 135 #define LOWRES_HEIGHT lowres_height 136 137 #define THUMB_WIDTH thumb_width 138 #define THUMB_HEIGHT thumb_height 139 140 /* 141 * External definitions 142 */ 143 144 extern char *__progname; /* Defined in /usr/lib/crt0.o */ 145 146 147 struct cam_dirent 148 { 149 SANE_Char name[11]; 150 SANE_Byte attr; 151 SANE_Byte create_time[2]; 152 SANE_Byte creat_date[2]; 153 long size; 154 }; 155 156 struct cam_dirlist 157 { 158 SANE_Char name[48]; 159 struct cam_dirlist *next; 160 }; 161 162 163 164 #include <sys/types.h> 165 166 FILE *sanei_config_open (const char *filename); 167 168 static SANE_Int init_gphoto2 (void); 169 170 static void close_gphoto2 (void); 171 172 static PictureInfo *get_pictures_info (void); 173 174 static SANE_Int get_picture_info (PictureInfo * pic, SANE_Int p); 175 176 static SANE_Status snap_pic (void); 177 178 char *sanei_config_read (char *str, int n, FILE * stream); 179 180 static SANE_Int read_dir (SANE_String dir, SANE_Bool read_files); 181 182 static void set_res (SANE_Int lowres); 183 184 static SANE_Int read_info (SANE_String_Const fname); 185 186 static SANE_Status converter_do_scan_complete_cleanup (void); 187 188 static SANE_Int converter_fill_buffer (void); 189 190 static SANE_Bool converter_scan_complete (void); 191 192 static SANE_Status converter_init (SANE_Handle handle); 193