| 1 |
/* dc240.c |
| 2 |
* |
| 3 |
* Copyright (C) 2001,2002 Hubert Figuiere <[email protected]> |
| 4 |
* Copyright (C) 2000,2001,2002 Scott Fritzinger |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 2 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Lesser General Public |
| 17 |
* License along with this library; if not, write to the |
| 18 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 |
* Boston, MA 02110-1301 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
/* |
| 23 |
Kodak DC 240/280/3400/5000 driver. |
| 24 |
Maintainer: |
| 25 |
Hubert Figuiere <[email protected]> |
| 26 |
*/ |
| 27 |
|
| 28 |
#include "config.h" |
| 29 |
|
| 30 |
#include <stdlib.h> |
| 31 |
#include <stdio.h> |
| 32 |
#include <string.h> |
| 33 |
|
| 34 |
#include <gphoto2/gphoto2.h> |
| 35 |
#include <gphoto2/gphoto2-port.h> |
| 36 |
|
| 37 |
#include "libgphoto2/i18n.h" |
| 38 |
|
| 39 |
#include "dc240.h" |
| 40 |
#include "library.h" |
| 41 |
|
| 42 |
|
| 43 |
int |
| 44 |
camera_id (CameraText *id) |
| 45 |
{ |
| 46 |
strcpy(id->text, "kodak-dc240"); |
| 47 |
|
| 48 |
return (GP_OK); |
| 49 |
} |
| 50 |
|
| 51 |
static const struct camera_to_usb { |
| 52 |
char *name; |
| 53 |
unsigned short idVendor; |
| 54 |
unsigned short idProduct; |
| 55 |
} camera_to_usb[] = { |
| 56 |
{ "Kodak:DC240", 0x040A, 0x0120 }, |
| 57 |
{ "Kodak:DC280", 0x040A, 0x0130 }, |
| 58 |
{ "Kodak:DC3400", 0x040A, 0x0132 }, |
| 59 |
{ "Kodak:DC5000", 0x040A, 0x0131 }, |
| 60 |
{ NULL, 0, 0 } |
| 61 |
}; |
| 62 |
|
| 63 |
/* |
| 64 |
Abilities are based upon what we can do with a DC240. |
| 65 |
Later cameras have a superset of the DC240 feature and are not |
| 66 |
currently supported. |
| 67 |
*/ |
| 68 |
int |
| 69 |
camera_abilities (CameraAbilitiesList *list) |
| 70 |
{ |
| 71 |
CameraAbilities a; |
| 72 |
int i; |
| 73 |
|
| 74 |
for (i = 0; camera_to_usb[i].name; i++) |
| 75 |
{ |
| 76 |
memset (&a, 0, sizeof (a)); |
| 77 |
strcpy(a.model, camera_to_usb[i].name); |
| 78 |
a.status = GP_DRIVER_STATUS_PRODUCTION; |
| 79 |
a.port = GP_PORT_SERIAL | GP_PORT_USB; |
| 80 |
a.speed[0] = 9600; |
| 81 |
a.speed[1] = 19200; |
| 82 |
a.speed[2] = 38400; |
| 83 |
a.speed[3] = 57600; |
| 84 |
a.speed[4] = 115200; |
| 85 |
a.speed[5] = 0; |
| 86 |
a.usb_vendor = camera_to_usb[i].idVendor; |
| 87 |
a.usb_product = camera_to_usb[i].idProduct; |
| 88 |
a.operations = GP_OPERATION_CAPTURE_IMAGE; |
| 89 |
a.file_operations = GP_FILE_OPERATION_DELETE | |
| 90 |
GP_FILE_OPERATION_PREVIEW; |
| 91 |
a.folder_operations = GP_FOLDER_OPERATION_NONE; |
| 92 |
|
| 93 |
gp_abilities_list_append(list, a); |
| 94 |
} |
| 95 |
return (GP_OK); |
| 96 |
} |
| 97 |
|
| 98 |
static int |
| 99 |
camera_exit (Camera *camera, GPContext *context) |
| 100 |
{ |
| 101 |
dc240_close (camera, context); |
| 102 |
|
| 103 |
return (GP_OK); |
| 104 |
} |
| 105 |
|
| 106 |
static int |
| 107 |
folder_list_func (CameraFilesystem *fs, const char *folder, CameraList *list, |
| 108 |
void *data, GPContext *context) |
| 109 |
{ |
| 110 |
Camera *camera = data; |
| 111 |
|
| 112 |
return dc240_get_directory_list(camera, list, folder, 0x10, context); |
| 113 |
} |
| 114 |
|
| 115 |
static int |
| 116 |
file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list, |
| 117 |
void *data, GPContext *context) |
| 118 |
{ |
| 119 |
Camera *camera = data; |
| 120 |
|
| 121 |
return dc240_get_directory_list(camera, list, folder, 0x00, context); |
| 122 |
} |
| 123 |
|
| 124 |
static int |
| 125 |
get_file_func (CameraFilesystem *fs, const char *folder, const char *filename, |
| 126 |
CameraFileType type, CameraFile *file, void *data, |
| 127 |
GPContext *context) |
| 128 |
{ |
| 129 |
Camera *camera = data; |
| 130 |
|
| 131 |
switch (type) { |
| 132 |
case GP_FILE_TYPE_NORMAL: |
| 133 |
case GP_FILE_TYPE_RAW: |
| 134 |
return dc240_file_action (camera, DC240_ACTION_IMAGE, file, |
| 135 |
folder, filename, context); |
| 136 |
case GP_FILE_TYPE_PREVIEW: |
| 137 |
return dc240_file_action (camera, DC240_ACTION_PREVIEW, file, |
| 138 |
folder, (char*) filename, context); |
| 139 |
default: |
| 140 |
return GP_ERROR_NOT_SUPPORTED; |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
static int |
| 145 |
delete_file_func (CameraFilesystem *fs, const char *folder, |
| 146 |
const char *filename, void *data, GPContext *context) |
| 147 |
{ |
| 148 |
Camera *camera = data; |
| 149 |
|
| 150 |
return (dc240_file_action (camera, DC240_ACTION_DELETE, NULL, folder, |
| 151 |
filename, context)); |
| 152 |
} |
| 153 |
|
| 154 |
static int |
| 155 |
camera_capture (Camera *camera, CameraCaptureType type, |
| 156 |
CameraFilePath *path, GPContext *context) |
| 157 |
{ |
| 158 |
int result; |
| 159 |
|
| 160 |
if (type != GP_CAPTURE_IMAGE) |
| 161 |
return (GP_ERROR_NOT_SUPPORTED); |
| 162 |
|
| 163 |
/* Capture the image */ |
| 164 |
result = dc240_capture (camera, path, context); |
| 165 |
if (result < 0) |
| 166 |
return (result); |
| 167 |
|
| 168 |
/* Tell the filesystem about it */ |
| 169 |
result = gp_filesystem_append (camera->fs, path->folder, path->name, context); |
| 170 |
if (result < 0) |
| 171 |
return (result); |
| 172 |
|
| 173 |
return (GP_OK); |
| 174 |
} |
| 175 |
|
| 176 |
static int |
| 177 |
camera_summary (Camera *camera, CameraText *summary, GPContext *context) |
| 178 |
{ |
| 179 |
char buf[32 * 1024]; |
| 180 |
char temp[1024]; |
| 181 |
int retval; |
| 182 |
DC240StatusTable table; |
| 183 |
|
| 184 |
retval = dc240_get_status (camera, &table, context); |
| 185 |
if (retval == GP_OK) { |
| 186 |
sprintf (buf, _("Model: Kodak %s\n"), dc240_convert_type_to_camera(table.cameraType)); |
| 187 |
sprintf (temp, _("Firmware version: %d.%02d\n"), table.fwVersInt, table.fwVersDec); |
| 188 |
strcat (buf, temp); |
| 189 |
sprintf (temp, _("Battery status: %s, AC Adapter: %s\n"), |
| 190 |
dc240_get_battery_status_str(table.battStatus), |
| 191 |
dc240_get_ac_status_str(table.acAdapter)); |
| 192 |
strcat (buf, temp); |
| 193 |
sprintf (temp, _("Number of pictures: %d\n"), table.numPict); |
| 194 |
strcat (buf, temp); |
| 195 |
sprintf (temp, _("Space remaining: High: %d, Medium: %d, Low: %d\n"), |
| 196 |
table.remPictHigh, table.remPictMed, table.remPictLow); |
| 197 |
strcat (buf, temp); |
| 198 |
|
| 199 |
sprintf (temp, _("Memory card status (%d): %s\n"), table.memCardStatus, |
| 200 |
dc240_get_memcard_status_str(table.memCardStatus)); |
| 201 |
strcat (buf, temp); |
| 202 |
|
| 203 |
sprintf (temp, _("Total pictures captured: %d, Flashes fired: %d\n"), |
| 204 |
table.totalPictTaken, table.totalStrobeFired); |
| 205 |
strcat (buf, temp); |
| 206 |
|
| 207 |
|
| 208 |
strcpy(summary->text, buf); |
| 209 |
} |
| 210 |
return retval; |
| 211 |
} |
| 212 |
|
| 213 |
static int |
| 214 |
camera_about (Camera *camera, CameraText *about, GPContext *context) |
| 215 |
{ |
| 216 |
strcpy (about->text, |
| 217 |
_("Kodak DC240 Camera Library\n" |
| 218 |
"Scott Fritzinger <[email protected]> and Hubert Figuiere <[email protected]>\n" |
| 219 |
"Camera Library for the Kodak DC240, DC280, DC3400 and DC5000 cameras.\n" |
| 220 |
"Rewritten and updated for gPhoto2.")); |
| 221 |
|
| 222 |
return (GP_OK); |
| 223 |
} |
| 224 |
|
| 225 |
static CameraFilesystemFuncs fsfuncs = { |
| 226 |
.file_list_func = file_list_func, |
| 227 |
.folder_list_func = folder_list_func, |
| 228 |
.get_file_func = get_file_func, |
| 229 |
.del_file_func = delete_file_func |
| 230 |
}; |
| 231 |
|
| 232 |
int |
| 233 |
camera_init (Camera *camera, GPContext *context) |
| 234 |
{ |
| 235 |
int ret, selected_speed = 0; |
| 236 |
GPPortSettings settings; |
| 237 |
|
| 238 |
/* First, set up all the function pointers */ |
| 239 |
camera->functions->exit = camera_exit; |
| 240 |
camera->functions->capture = camera_capture; |
| 241 |
camera->functions->summary = camera_summary; |
| 242 |
camera->functions->about = camera_about; |
| 243 |
|
| 244 |
/* Set up the CameraFilesystem */ |
| 245 |
gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera); |
| 246 |
|
| 247 |
ret = gp_port_get_settings (camera->port, &settings); |
| 248 |
if (ret < 0) |
| 249 |
return (ret); |
| 250 |
switch (camera->port->type) { |
| 251 |
case GP_PORT_SERIAL: |
| 252 |
|
| 253 |
/* Remember the selected speed */ |
| 254 |
selected_speed = settings.serial.speed; |
| 255 |
|
| 256 |
settings.serial.speed = 9600; |
| 257 |
settings.serial.bits = 8; |
| 258 |
settings.serial.parity = 0; |
| 259 |
settings.serial.stopbits = 1; |
| 260 |
break; |
| 261 |
case GP_PORT_USB: |
| 262 |
settings.usb.inep = 0x82; |
| 263 |
settings.usb.outep = 0x01; |
| 264 |
settings.usb.config = 1; |
| 265 |
settings.usb.interface = 0; |
| 266 |
settings.usb.altsetting = 0; |
| 267 |
break; |
| 268 |
default: |
| 269 |
return (GP_ERROR_UNKNOWN_PORT); |
| 270 |
} |
| 271 |
|
| 272 |
ret = gp_port_set_settings (camera->port, settings); |
| 273 |
if (ret < 0) |
| 274 |
return (ret); |
| 275 |
|
| 276 |
ret = gp_port_set_timeout (camera->port, TIMEOUT); |
| 277 |
if (ret < 0) |
| 278 |
return (ret); |
| 279 |
|
| 280 |
if (camera->port->type == GP_PORT_SERIAL) { |
| 281 |
char buf[8]; |
| 282 |
/* Reset the camera to 9600 */ |
| 283 |
gp_port_send_break(camera->port, 1); |
| 284 |
|
| 285 |
/* Used to have a 1500 msec pause here to give |
| 286 |
* the camera time to reset - but, since |
| 287 |
* the serial port sometimes returns a garbage |
| 288 |
* character or two after the break, we do |
| 289 |
* a couple of TIMEOUT (750 msec) pauses here |
| 290 |
* force the delay as well as flush the port |
| 291 |
*/ |
| 292 |
gp_port_read(camera->port, buf, 8); |
| 293 |
gp_port_read(camera->port, buf, 8); |
| 294 |
|
| 295 |
ret = dc240_set_speed (camera, selected_speed); |
| 296 |
if (ret < 0) |
| 297 |
return (ret); |
| 298 |
} |
| 299 |
|
| 300 |
/* Open the CF card */ |
| 301 |
ret = dc240_open (camera); |
| 302 |
if (ret < 0) |
| 303 |
return (ret); |
| 304 |
|
| 305 |
ret = dc240_packet_set_size (camera, HPBS+2); |
| 306 |
if (ret < 0) |
| 307 |
return (ret); |
| 308 |
|
| 309 |
return (GP_OK); |
| 310 |
} |