summaryrefslogtreecommitdiff
path: root/camlibs/mustek/mdc800.c
blob: 4390a7327e172090d9de3ebcef8f70571c7bfe1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/* mdc800.c
 *
 * Copyright 1999/2000 by Henning Zabel <henning@uni-paderborn.de>
 * Copyright 2001 Marcus Meissner <marcus@jet.franken.de>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301  USA
 */
#include <string.h>

#include <gphoto2/gphoto2-library.h>
#include <gphoto2/gphoto2-result.h>

#include "print.h"
#include "core.h"

#ifdef ENABLE_NLS
#  include <libintl.h>
#  undef _
#  define _(String) dgettext (GETTEXT_PACKAGE, String)
#  ifdef gettext_noop
#    define N_(String) gettext_noop (String)
#  else
#    define _(String) (String)
#    define N_(String) (String)
#  endif
#else
#  define _(String) (String)
#  define N_(String) (String)
#endif

int
camera_id (CameraText *id)
{
	strcpy(id->text, "Mustek MDC 800");
	return (GP_OK);
}

int
camera_abilities (CameraAbilitiesList *list)
{
	CameraAbilities a;

	memset(&a,0,sizeof(a));
	strcpy(a.model,	"Mustek:MDC 800");
	a.status	= GP_DRIVER_STATUS_EXPERIMENTAL;
	a.port		= GP_PORT_SERIAL | GP_PORT_USB;
	a.speed[0]	= 19200;
	a.speed[1]	= 57600;
	a.speed[2]	= 115200;
	a.speed[3]	= 0;

	a.usb_vendor	= 0x055f;
	a.usb_product	= 0xa800;
	a.operations        = 	GP_OPERATION_CAPTURE_PREVIEW |
				GP_CAPTURE_IMAGE;
	a.file_operations   = 	GP_FILE_OPERATION_DELETE |
				GP_FILE_OPERATION_PREVIEW;
	a.folder_operations = 	GP_FOLDER_OPERATION_NONE;
/* Deliberately commented out. this driver does not work due to USB interrupts
	gp_abilities_list_append(list, a);
 */
	return (GP_OK);
}

#if 0
static int
camera_exit (Camera *camera, GPContext *context)
{
	return (GP_OK);
}
#endif

static int
get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
	       CameraFileType type, CameraFile *file, void *data,
	       GPContext *context)
{
	Camera *camera = data;
	int	size, nr, result;

	nr = gp_filesystem_number(fs, folder, filename, context);
	if(nr < 0)
		return nr;

	switch (type) {
#if 0
	case GP_FILE_TYPE_RAW:
		result =  jd11_get_image_full (camera, nr, &data, (int*) &size, 1);
		break;
#endif
	case GP_FILE_TYPE_NORMAL:
		result = mdc800_getImage(camera,nr,&data,&size);
		break;
	case GP_FILE_TYPE_PREVIEW:
		result = mdc800_getThumbnail(camera,nr,&data,&size);
		break;
	default:
		return (GP_ERROR_NOT_SUPPORTED);
	}
	if (result < 0)
		return result;

	gp_file_set_mime_type (file, GP_MIME_JPEG);
	gp_file_set_data_and_size(file, data, size);
	return (GP_OK);
}

static int
delete_file_func (CameraFilesystem *fs, const char *folder,
		  const char *filename, void *data, GPContext *context)
{
	Camera *camera = data;
	int ret,nr ;

	nr = gp_filesystem_number(fs, folder, filename, context);
	if (nr < 0)
	    return nr;

	ret = mdc800_setTarget (camera,1);
	if (ret!=GP_OK)
	{
		printAPIError ("(mdc800_delete_image) can't set Target\n");
		return ret;
	}
	ret = mdc800_io_sendCommand(camera->port, COMMAND_DELETE_IMAGE,nr/100,(nr%100)/10,nr%10,0,0);
	if (ret != GP_OK)
	{
		printAPIError ("(mdc800_delete_image ) deleting Image %i fails !.\n",nr);
		return ret;
	}
	return GP_OK;
}

static int
delete_all_func (CameraFilesystem *fs, const char *folder, void *data,
	GPContext *context)
{
	/*Camera *camera = data;*/

	/*
	 * Delete all files in the given folder. If your camera doesn't have
	 * such a functionality, just don't implement this function.
	 */

	return (GP_OK);
}

static int
camera_config_get (Camera *camera, CameraWidget **window, GPContext *ctx)
{
	gp_widget_new (GP_WIDGET_WINDOW, "Camera Configuration", window);

	/* Append your sections and widgets here. */

	return (GP_OK);
}

static int
camera_config_set (Camera *camera, CameraWidget *window, GPContext *ctx)
{
	/*
	 * Check if the widgets' values have changed. If yes, tell the camera.
	 */

	return (GP_OK);
}

#if 0
static int
camera_capture_preview (Camera *camera, CameraFile *file, GPContext *context)
{
	/*
	 * Capture a preview and return the data in the given file (again,
	 * use gp_file_set_data_and_size, gp_file_set_mime_type, etc.).
	 * libgphoto2 assumes that previews are NOT stored on the camera's
	 * disk. If your camera does, please delete it from the camera.
	 */

	return (GP_OK);
}
#endif

static int
camera_capture (Camera *camera, CameraCaptureType type, CameraFilePath *path,
	GPContext *context)
{
	/*
	 * Capture an image and tell libgphoto2 where to find it by filling
	 * out the path.
	 */

	return (GP_OK);
}

static int
camera_summary (Camera *camera, CameraText *summary, GPContext *ctx)
{
	char mdc800_summary_output[500];
	char line[50];
	/*
	 * Fill out the summary with some information about the current
	 * state of the camera (like pictures taken, etc.).
	 */
	strcpy (mdc800_summary_output,_("Summary for Mustek MDC800:\n"));
	if (GP_OK!=mdc800_getSystemStatus (camera))
	{
		strcat(mdc800_summary_output,_("no status reported."));
		strcpy(summary->text, mdc800_summary_output);
		return GP_OK;
	}

	if (mdc800_isCFCardPresent (camera))
		strcpy (line,_("Compact Flash Card detected\n"));
	else
		strcpy (line,_("No Compact Flash Card detected\n"));
	strcat(mdc800_summary_output,line);

	if (mdc800_getMode (camera) == 0)
		strcpy (line, _("Current Mode: Camera Mode\n"));
	else
		strcpy (line, _("Current Mode: Playback Mode\n"));
	strcat (mdc800_summary_output,line);

	strcpy (line,mdc800_getFlashLightString (mdc800_getFlashLightStatus (camera)));
	strcat (line,"\n");
	strcat (mdc800_summary_output,line);


	if (mdc800_isBatteryOk (camera))
		strcpy (line, _("Batteries are ok."));
	else
		strcpy (line, _("Batteries are low."));
	strcat (mdc800_summary_output,line);
	strcpy(summary->text,mdc800_summary_output);
	return GP_OK;
}

static int
camera_manual (Camera *camera, CameraText *manual, GPContext *ctx)
{
	/*
	 * If you would like to tell the user some information about how
	 * to use the camera or the driver, this is the place to do.
	 */
	return (GP_OK);
}

static int
camera_about (Camera *camera, CameraText *about, GPContext *ctx)
{
	strcpy (about->text, _("Mustek MDC-800 gPhoto2 Library\n"
			       "Henning Zabel <henning@uni-paderborn.de>\n"
			       "Ported to gphoto2 by Marcus Meissner <marcus@jet.franken.de>\n"
			       "Supports Serial and USB Protocols."));
	return (GP_OK);
}

static int
get_info_func (CameraFilesystem *fs, const char *folder, const char *filename,
	       CameraFileInfo *info, void *data, GPContext *context)
{
	/*Camera *camera = data;*/

	/* Get the file info here and write it into <info> */

	return (GP_OK);
}

static int
folder_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
		  void *data, GPContext *context)
{
	/*Camera *camera = data;*/

	/* List your folders here */

	return (GP_OK);
}

static int
file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
		void *data, GPContext *context)
{
	Camera *camera = data;
	int count, result;

	result =  mdc800_number_of_pictures (camera, &count);
	if (result != GP_OK)
		return result;
	gp_list_populate(list, "image%02i.jpg", count);
	return (GP_OK);
}

static CameraFilesystemFuncs fsfuncs = {
	.file_list_func = file_list_func,
	.folder_list_func = folder_list_func,
	.get_file_func = get_file_func,
	.get_info_func = get_info_func,
	.del_file_func = delete_file_func,
	.delete_all_func = delete_all_func
};

int
camera_init (Camera *camera, GPContext *context)
{
        /* First, set up all the function pointers */
        /* camera->functions->exit                 = camera_exit; */
        camera->functions->get_config		= camera_config_get;
        camera->functions->set_config		= camera_config_set;
        camera->functions->capture              = camera_capture;
        camera->functions->summary              = camera_summary;
        camera->functions->manual               = camera_manual;
        camera->functions->about                = camera_about;

	/* Now, tell the filesystem where to get lists, files and info */
	gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera);

	/* Configure port */
	gp_port_set_timeout(camera->port,MDC800_DEFAULT_COMMAND_RETRY_DELAY);
	if (camera->port->type == GP_PORT_SERIAL) {
	    GPPortSettings settings;
	    gp_port_get_settings(camera->port, &settings);
	    settings.serial.speed   = 57600;
	    settings.serial.bits    = 8;
	    settings.serial.parity  = 0;
	    settings.serial.stopbits= 1;
	    gp_port_set_settings(camera->port, settings);
	}
	return mdc800_openCamera(camera);
}