1 /****************************************************************/
2 /* library.c - Gphoto2 library for the Mustek gSmart 300 */
4 /* Copyright (C) 2002 Jérôme Lodewyck */
6 /* Author: Jérôme Lodewyck <jerome.lodewyck@ens.fr> */
8 /* based on code by: Till Adam <till@adam-lilienthal.de> */
10 /* This library is free software; you can redistribute it */
11 /* and/or modify it under the terms of the GNU Library General */
12 /* Public License as published by the Free Software Foundation; */
13 /* either version 2 of the License, or (at your option) any */
16 /* This library is distributed in the hope that it will be */
17 /* useful, but WITHOUT ANY WARRANTY; without even the implied */
18 /* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR */
19 /* PURPOSE. See the GNU Library General Public License for */
22 /* You should have received a copy of the GNU Library General */
23 /* Public License along with this library; if not, write to the */
24 /* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */
25 /* Boston, MA 02111-1307, USA. */
26 /****************************************************************/
33 #include <gphoto2/gphoto2.h>
38 # define _(String) dgettext (PACKAGE, String)
40 # define N_(String) gettext_noop (String)
42 # define N_(String) (String)
45 # define _(String) (String)
46 # define N_(String) (String)
49 #include "gsmart300.h"
51 #define GP_MODULE "gsmart300"
55 /* forward declarations */
56 static int file_list_func (CameraFilesystem *fs, const char *folder,
57 CameraList *list, void *data, GPContext *context);
58 static int get_file_func (CameraFilesystem *fs, const char *folder,
59 const char *filename, CameraFileType type,
60 CameraFile *file, void *user_data, GPContext *context);
62 static int delete_file_func (CameraFilesystem *fs, const char *folder,
63 const char *filename, void *data, GPContext *context);
64 static int delete_all_func (CameraFilesystem *fs, const char *folder,
65 void *data, GPContext *context);
66 static int get_info_func (CameraFilesystem *fs, const char *folder,
67 const char *filename, CameraFileInfo *info,
68 void *data, GPContext *context);
70 /* define what cameras we support */
80 "Mustek:gSmart 300", 0x055f, 0xc200}
82 "Casio:LV 10", 0x055f, 0xc200}
89 camera_id (CameraText *id)
91 strcpy (id->text, "gsmart300");
96 camera_abilities (CameraAbilitiesList *list)
102 ptr = models[x].model;
104 memset (&a, 0, sizeof (a));
105 strcpy (a.model, ptr);
106 a.status = GP_DRIVER_STATUS_EXPERIMENTAL;
107 a.port = GP_PORT_USB;
110 a.file_operations = GP_FILE_OPERATION_PREVIEW | GP_FILE_OPERATION_DELETE;
112 a.folder_operations = GP_FOLDER_OPERATION_DELETE_ALL;
114 a.usb_vendor = models[x].usb_vendor;
115 a.usb_product = models[x].usb_product;
117 gp_abilities_list_append (list, a);
119 ptr = models[++x].model;
127 camera_exit (Camera *camera, GPContext *context)
130 if (camera->pl->fats) {
131 free (camera->pl->fats);
132 camera->pl->fats = NULL;
134 if (camera->pl->files) {
135 free (camera->pl->files);
136 camera->pl->files = NULL;
146 camera_summary (Camera *camera, CameraText *summary, GPContext *context)
150 if (camera->pl->dirty)
151 CHECK (gsmart300_get_info (camera->pl));
153 snprintf (tmp, sizeof (tmp), "Files: %d\n\n", camera->pl->num_files);
154 strcat (summary->text, tmp);
160 camera_about (Camera *camera, CameraText *about, GPContext *context)
163 _("gsmart300 library \n"
164 "Till Adam <till@adam-lilienthal.de>\n"
165 "Jerome Lodewyck <jerome.lodewyck@ens.fr>\n"
166 "Support for Mustek gSmart 300 digital cameras\n"
167 "based on several other gphoto2 camlib modules and "
168 "the specifications kindly provided by Mustek.\n" "\n"));
173 static CameraFilesystemFuncs fsfuncs = {
174 .file_list_func = file_list_func,
175 .get_file_func = get_file_func,
176 .get_info_func = get_info_func,
177 .del_file_func = delete_file_func,
178 .delete_all_func = delete_all_func
182 camera_init (Camera *camera, GPContext *context)
185 GPPortSettings settings;
187 /* First, set up all the function pointers */
188 camera->functions->exit = camera_exit;
189 camera->functions->summary = camera_summary;
190 camera->functions->about = camera_about;
192 CHECK (gp_port_get_settings (camera->port, &settings));
193 switch (camera->port->type) {
195 settings.usb.inep = 0x82;
196 settings.usb.outep = 0x03;
197 settings.usb.config = 1;
198 settings.usb.interface = 0;
199 settings.usb.altsetting = 0;
201 CHECK (gp_port_set_settings (camera->port, settings));
202 CHECK (gp_port_set_timeout (camera->port, TIMEOUT));
206 gp_context_error (context,
207 _("Unsupported port type: %d. "
208 "This driver only works with USB "
209 "cameras.\n"), camera->port->type);
214 camera->pl = malloc (sizeof (CameraPrivateLibrary));
216 return (GP_ERROR_NO_MEMORY);
217 memset (camera->pl, 0, sizeof (CameraPrivateLibrary));
218 camera->pl->gpdev = camera->port;
219 camera->pl->dirty = 1;
221 ret = gsmart300_reset (camera->pl);
224 gp_context_error (context, _("Could not reset camera.\n"));
230 /* Set up the CameraFilesystem */
231 return gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera);
236 file_list_func (CameraFilesystem *fs, const char *folder,
237 CameraList *list, void *data, GPContext *context)
239 Camera *camera = data;
243 if (camera->pl->dirty)
244 CHECK (gsmart300_get_info (camera->pl));
246 for (i = 0; i < camera->pl->num_files; i++) {
247 strncpy (temp_file, camera->pl->files[i].name, 12);
249 gp_list_append (list, temp_file, NULL);
256 get_file_func (CameraFilesystem *fs, const char *folder,
257 const char *filename, CameraFileType type,
258 CameraFile *file, void *user_data, GPContext *context)
260 Camera *camera = user_data;
261 int number, filetype;
263 CHECK (number = gp_filesystem_number (camera->fs, folder, filename,
266 case GP_FILE_TYPE_NORMAL:
267 CHECK (gsmart300_request_file (camera->pl, file, number));
269 case GP_FILE_TYPE_PREVIEW:
270 CHECK (gsmart300_request_thumbnail
271 (camera->pl, file, number, &filetype));
272 if (filetype == GSMART_FILE_TYPE_IMAGE) {
273 CHECK (gp_file_set_mime_type (file, GP_MIME_BMP));
277 return GP_ERROR_NOT_SUPPORTED;
279 CHECK (gp_file_set_name (file, filename));
284 get_info_func (CameraFilesystem *fs, const char *folder,
285 const char *filename, CameraFileInfo *info, void *data,
288 Camera *camera = data;
290 struct GsmartFile *file;
292 /* Get the file number from the CameraFileSystem */
293 CHECK (n = gp_filesystem_number (camera->fs, folder, filename,
296 CHECK (gsmart300_get_file_info (camera->pl, n, &file));
298 info->file.fields = GP_FILE_INFO_NAME
301 | GP_FILE_INFO_HEIGHT;
302 strncpy (info->file.name, filename, sizeof (info->file.name));
303 if (file->mime_type == GSMART_FILE_TYPE_IMAGE) {
304 strcpy (info->file.type, GP_MIME_JPEG);
305 info->preview.width = 80;
306 info->preview.height = 60;
308 info->file.width = file->width;
309 info->file.height = file->height;
311 info->preview.fields = GP_FILE_INFO_TYPE
313 | GP_FILE_INFO_HEIGHT;
314 strcpy (info->preview.type, GP_MIME_BMP);
320 delete_file_func (CameraFilesystem *fs, const char *folder,
321 const char *filename, void *data, GPContext *context)
323 Camera *camera = data;
326 /* Get the file number from the CameraFileSystem */
327 CHECK (n = gp_filesystem_number (camera->fs, folder, filename,
329 CHECK (c = gp_filesystem_count (camera->fs, folder, context));
333 gp_filesystem_name (fs, "/", c - 1, &name, context);
334 gp_context_error (context,
335 _("Your camera only supports deleting "
336 "the last file on the camera. In this "
337 "case, this is file '%s'."), name);
340 CHECK (gsmart300_delete_file (camera->pl, n));
345 delete_all_func (CameraFilesystem *fs, const char *folder, void *data,
348 Camera *camera = data;
350 CHECK (gsmart300_delete_all (camera->pl));