| 1 |
/****************************************************************/ |
| 2 |
/* coolshot.c - Gphoto2 library for accessing the Panasonic */ |
| 3 |
/* Coolshot KXL-600A & KXL-601A digital cameras. */ |
| 4 |
/* */ |
| 5 |
/* Copyright 2001 Chris Pinkham */ |
| 6 |
/* */ |
| 7 |
/* Author: Chris Pinkham <[email protected]> */ |
| 8 |
/* */ |
| 9 |
/* This library is free software; you can redistribute it */ |
| 10 |
/* and/or modify it under the terms of the GNU Library General */ |
| 11 |
/* Public License as published by the Free Software Foundation; */ |
| 12 |
/* either version 2 of the License, or (at your option) any */ |
| 13 |
/* later version. */ |
| 14 |
/* */ |
| 15 |
/* This library is distributed in the hope that it will be */ |
| 16 |
/* useful, but WITHOUT ANY WARRANTY; without even the implied */ |
| 17 |
/* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR */ |
| 18 |
/* PURPOSE. See the GNU Library General Public License for */ |
| 19 |
/* more details. */ |
| 20 |
/* */ |
| 21 |
/* You should have received a copy of the GNU Library General */ |
| 22 |
/* Public License along with this library; if not, write to the */ |
| 23 |
/* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,*/ |
| 24 |
/* Boston, MA 02110-1301 USA */ |
| 25 |
/****************************************************************/ |
| 26 |
|
| 27 |
#include "config.h" |
| 28 |
|
| 29 |
#include <stdlib.h> |
| 30 |
#include <stdio.h> |
| 31 |
#include <string.h> |
| 32 |
#include <gphoto2/gphoto2.h> |
| 33 |
|
| 34 |
#include "libgphoto2/i18n.h" |
| 35 |
|
| 36 |
#include "library.h" |
| 37 |
|
| 38 |
|
| 39 |
#define GP_MODULE "coolshot" |
| 40 |
|
| 41 |
#define TIMEOUT 2000 |
| 42 |
#define DEFAULT_SPEED 9600 |
| 43 |
|
| 44 |
#define COOLSHOT_VERSION "0.4" |
| 45 |
#define COOLSHOT_LAST_MOD "09/06/2001 02:28 EST" |
| 46 |
|
| 47 |
/* define what cameras we support */ |
| 48 |
static char *coolshot_cameras[] = { |
| 49 |
"Panasonic:Coolshot KXL-600A", |
| 50 |
"Panasonic:Coolshot KXL-601A", |
| 51 |
"" |
| 52 |
}; |
| 53 |
|
| 54 |
struct _CameraPrivateLibrary { |
| 55 |
int speed; |
| 56 |
}; |
| 57 |
|
| 58 |
int camera_id (CameraText *id) |
| 59 |
{ |
| 60 |
/* GP_DEBUG ("* camera_id"); */ |
| 61 |
|
| 62 |
strcpy (id->text, "coolshot"); |
| 63 |
|
| 64 |
return (GP_OK); |
| 65 |
} |
| 66 |
|
| 67 |
int camera_abilities (CameraAbilitiesList *list) |
| 68 |
{ |
| 69 |
int x = 0; |
| 70 |
char *ptr; |
| 71 |
CameraAbilities a; |
| 72 |
|
| 73 |
/* GP_DEBUG ("* camera_abilities"); */ |
| 74 |
|
| 75 |
ptr = coolshot_cameras[x++]; |
| 76 |
while (*ptr) { |
| 77 |
memset(&a, 0, sizeof(a)); |
| 78 |
strcpy (a.model, ptr ); |
| 79 |
a.status = GP_DRIVER_STATUS_PRODUCTION; |
| 80 |
a.port = GP_PORT_SERIAL; |
| 81 |
a.speed[0] = 9600; |
| 82 |
a.speed[1] = 19200; |
| 83 |
a.speed[2] = 38400; |
| 84 |
a.speed[3] = 57600; |
| 85 |
a.speed[4] = 115200; |
| 86 |
a.speed[5] = 0; |
| 87 |
|
| 88 |
/* fixme, need to set these operations lists to correct values */ |
| 89 |
a.operations = GP_OPERATION_NONE; |
| 90 |
a.file_operations = GP_FILE_OPERATION_PREVIEW; |
| 91 |
|
| 92 |
/* fixme, believe supports GP_FOLDER_PUT_FILE */ |
| 93 |
a.folder_operations = GP_FOLDER_OPERATION_NONE; |
| 94 |
|
| 95 |
gp_abilities_list_append (list, a); |
| 96 |
|
| 97 |
ptr = coolshot_cameras[x++]; |
| 98 |
} |
| 99 |
|
| 100 |
return (GP_OK); |
| 101 |
} |
| 102 |
|
| 103 |
static int camera_start (Camera *camera) |
| 104 |
{ |
| 105 |
GP_DEBUG ("* camera_start"); |
| 106 |
|
| 107 |
/* coolshot_sb sets to default speed if speed == 0 */ |
| 108 |
CHECK (coolshot_sb (camera, camera->pl->speed)); |
| 109 |
return( GP_OK ); |
| 110 |
} |
| 111 |
|
| 112 |
static int camera_stop (Camera *camera) |
| 113 |
{ |
| 114 |
GP_DEBUG ("* camera_stop"); |
| 115 |
|
| 116 |
CHECK (coolshot_sb( camera, DEFAULT_SPEED)); |
| 117 |
return (GP_OK); |
| 118 |
} |
| 119 |
|
| 120 |
static int file_list_func (CameraFilesystem *fs, const char *folder, |
| 121 |
CameraList *list, void *data, GPContext *context) |
| 122 |
{ |
| 123 |
Camera *camera = data; |
| 124 |
int count; |
| 125 |
|
| 126 |
GP_DEBUG ("* file_list_func"); |
| 127 |
GP_DEBUG ("*** folder: %s", folder); |
| 128 |
|
| 129 |
CHECK (camera_start (camera)); |
| 130 |
CHECK (count = coolshot_file_count (camera)); |
| 131 |
CHECK (gp_list_populate (list, "pic_%04i.jpg", count)); |
| 132 |
|
| 133 |
return (camera_stop (camera)); |
| 134 |
} |
| 135 |
|
| 136 |
static int get_info_func (CameraFilesystem *fs, const char *folder, |
| 137 |
const char *filename, CameraFileInfo *info, void *data, |
| 138 |
GPContext *context) |
| 139 |
{ |
| 140 |
Camera *camera = data; |
| 141 |
int n; |
| 142 |
|
| 143 |
GP_DEBUG ("* get_info_func"); |
| 144 |
GP_DEBUG ("*** folder: %s", folder); |
| 145 |
GP_DEBUG ("*** filename: %s",filename); |
| 146 |
|
| 147 |
CHECK (camera_start (camera)); |
| 148 |
|
| 149 |
/* Get the file number from the CameraFileSystem */ |
| 150 |
CHECK (n = gp_filesystem_number (camera->fs, folder, filename, |
| 151 |
context)); |
| 152 |
|
| 153 |
/* fixme, get file size also */ |
| 154 |
info->file.fields = GP_FILE_INFO_TYPE; |
| 155 |
strcpy (info->file.type, GP_MIME_JPEG ); |
| 156 |
|
| 157 |
info->preview.fields = GP_FILE_INFO_TYPE; |
| 158 |
strcpy (info->preview.type, GP_MIME_JPEG); |
| 159 |
|
| 160 |
return (camera_stop (camera)); |
| 161 |
} |
| 162 |
|
| 163 |
static int camera_exit (Camera *camera, GPContext *context) |
| 164 |
{ |
| 165 |
free (camera->pl); |
| 166 |
camera->pl = NULL; |
| 167 |
|
| 168 |
return (GP_OK); |
| 169 |
} |
| 170 |
|
| 171 |
static int get_file_func (CameraFilesystem *fs, const char *folder, |
| 172 |
const char *filename, CameraFileType type, |
| 173 |
CameraFile *file, void *user_data, GPContext *context) |
| 174 |
{ |
| 175 |
Camera *camera = user_data; |
| 176 |
char data[128000]; |
| 177 |
int size, n; |
| 178 |
|
| 179 |
GP_DEBUG ("* camera_file_get"); |
| 180 |
GP_DEBUG ("*** folder: %s", folder); |
| 181 |
GP_DEBUG ("*** filename: %s",filename); |
| 182 |
GP_DEBUG ("*** type: %d", type); |
| 183 |
|
| 184 |
CHECK (camera_start (camera)); |
| 185 |
|
| 186 |
if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL) { |
| 187 |
camera_stop (camera); |
| 188 |
return (GP_ERROR_CANCEL); |
| 189 |
} |
| 190 |
|
| 191 |
/* |
| 192 |
* Get the file number from the CameraFileSystem (and increment |
| 193 |
* because we need numbers starting with 1) |
| 194 |
*/ |
| 195 |
CHECK (n = gp_filesystem_number (camera->fs, folder, filename, |
| 196 |
context)); |
| 197 |
n++; |
| 198 |
|
| 199 |
switch (type) { |
| 200 |
case GP_FILE_TYPE_PREVIEW: |
| 201 |
CHECK (coolshot_request_thumbnail (camera, file, data, &size, n, context)); |
| 202 |
CHECK (coolshot_build_thumbnail (data, &size)); |
| 203 |
CHECK (gp_file_set_mime_type (file, GP_MIME_PPM)); |
| 204 |
break; |
| 205 |
|
| 206 |
case GP_FILE_TYPE_NORMAL: |
| 207 |
CHECK (coolshot_request_image (camera, file, data, &size, n, context)); |
| 208 |
CHECK (gp_file_set_mime_type (file, GP_MIME_JPEG)); |
| 209 |
break; |
| 210 |
default: |
| 211 |
return (GP_ERROR_NOT_SUPPORTED); |
| 212 |
} |
| 213 |
|
| 214 |
CHECK (gp_file_append (file, data, size)); |
| 215 |
|
| 216 |
return (camera_stop (camera)); |
| 217 |
} |
| 218 |
|
| 219 |
static int camera_summary (Camera *camera, CameraText *summary, |
| 220 |
GPContext *context) |
| 221 |
{ |
| 222 |
int count; |
| 223 |
char tmp[1024]; |
| 224 |
|
| 225 |
GP_DEBUG ("* camera_summary"); |
| 226 |
|
| 227 |
CHECK (camera_start (camera)); |
| 228 |
|
| 229 |
/* possibly get # pics, mem free, etc. */ |
| 230 |
count = coolshot_file_count (camera); |
| 231 |
|
| 232 |
sprintf (tmp, "Frames Taken : %4d\n", count); |
| 233 |
strcat (summary->text, tmp ); |
| 234 |
|
| 235 |
return (camera_stop (camera)); |
| 236 |
} |
| 237 |
|
| 238 |
static int camera_about (Camera *camera, CameraText *about, GPContext *context) |
| 239 |
{ |
| 240 |
GP_DEBUG ("* camera_about"); |
| 241 |
|
| 242 |
strcpy (about->text, |
| 243 |
_("coolshot library v" COOLSHOT_VERSION |
| 244 |
" " COOLSHOT_LAST_MOD "\n" |
| 245 |
"Chris Pinkham <[email protected]>\n" |
| 246 |
"Support for Panasonic Coolshot digital cameras\n" |
| 247 |
"based on reverse engineering serial protocol.\n" |
| 248 |
"\n")); |
| 249 |
|
| 250 |
return (GP_OK); |
| 251 |
} |
| 252 |
|
| 253 |
static CameraFilesystemFuncs fsfuncs = { |
| 254 |
.file_list_func = file_list_func, |
| 255 |
.get_file_func = get_file_func, |
| 256 |
.get_info_func = get_info_func, |
| 257 |
}; |
| 258 |
|
| 259 |
int camera_init (Camera *camera, GPContext *context) |
| 260 |
{ |
| 261 |
int count; |
| 262 |
GPPortSettings settings; |
| 263 |
|
| 264 |
/* First, set up all the function pointers */ |
| 265 |
camera->functions->exit = camera_exit; |
| 266 |
camera->functions->summary = camera_summary; |
| 267 |
camera->functions->about = camera_about; |
| 268 |
|
| 269 |
camera->pl = malloc (sizeof (CameraPrivateLibrary)); |
| 270 |
if (!camera->pl) |
| 271 |
return (GP_ERROR_NO_MEMORY); |
| 272 |
|
| 273 |
/* Set up the port and remember the requested speed */ |
| 274 |
CHECK (gp_port_get_settings (camera->port, &settings)); |
| 275 |
camera->pl->speed = settings.serial.speed; |
| 276 |
settings.serial.speed = DEFAULT_SPEED; |
| 277 |
settings.serial.bits = 8; |
| 278 |
settings.serial.parity = 0; |
| 279 |
settings.serial.stopbits = 1; |
| 280 |
CHECK (gp_port_set_settings (camera->port, settings)); |
| 281 |
CHECK (gp_port_set_timeout (camera->port, TIMEOUT)); |
| 282 |
|
| 283 |
/* check to see if camera is really there */ |
| 284 |
CHECK (coolshot_enq (camera)); |
| 285 |
|
| 286 |
coolshot_sm (camera); |
| 287 |
|
| 288 |
/* get number of images */ |
| 289 |
CHECK (count = coolshot_file_count (camera)); |
| 290 |
|
| 291 |
CHECK (camera_start (camera)); |
| 292 |
CHECK (gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera)); |
| 293 |
|
| 294 |
/* coolshot_sb sets to default speed if speed == 0 */ |
| 295 |
CHECK (coolshot_sb (camera, camera->pl->speed)); |
| 296 |
|
| 297 |
return (camera_stop (camera)); |
| 298 |
} |