summaryrefslogtreecommitdiff
path: root/camlibs/jd11/jd11.c
blob: ef1c733efcba78cb9945a027a84574aface3390e (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
/*
 * Jenoptik JD11 Driver
 * Copyright (C) 1999-2001 Marcus Meissner <marcus@jet.franken.de>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   
 */

#include <config.h>

#include <string.h>
#include <stdlib.h>
#include <stdio.h>

#include <gphoto2.h>
#include <gphoto2-port.h>

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

#include "serial.h"

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

int camera_abilities (CameraAbilitiesList *list) 
{
	CameraAbilities a;

	a.status		= GP_DRIVER_STATUS_TESTING;
	a.port			= GP_PORT_SERIAL;
	a.speed[0]		= 115200;
	a.speed[1]		= 0;
	a.operations		= GP_OPERATION_CONFIG;
	a.file_operations	= GP_FILE_OPERATION_PREVIEW;
	a.folder_operations	= GP_FOLDER_OPERATION_DELETE_ALL;

	strcpy(a.model, "Jenoptik JD11");
	gp_abilities_list_append(list, a);

	/* Reported to be just a rebranded version by Russ Burdick
	 * <grub@extrapolation.net> */
	/* from Gallantcom, http://www.gallantcom.com/prodfaq-probe99.htm */
	strcpy(a.model, "Quark Probe 99");
	gp_abilities_list_append(list, a);

	/* 'Argus DC-100' looks the same, see:
	 * http://www.aaadigitalcameras.com/argus_digital_vga_compact_camera.html
	 * but not reported yet.
	 */
	strcpy(a.model, "Argus DC-100");
	gp_abilities_list_append(list, a);
	/* 'Argus DC-2000' is the same (or uses the same software), check
	 * http://www.arguscamera.com/tech_supp/camoper.htm
	 */
	strcpy(a.model, "Argus DC-2000");
	gp_abilities_list_append(list, a);

	/* The I/O Magic MagicImage 420 has a black cover, but otherwise
	 * appears to be the same. (Not 100% sure.)
	 * http://www.iomagic.com/support/digitalcameras/magicimage420/magicimage420main.htm
	 */
	strcpy(a.model, "I/O Magic MagicImage 420");
	gp_abilities_list_append(list, a);
	return (GP_OK);
}

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

	result =  jd11_file_count(camera->port, &count);
	if (result != GP_OK)
		return result;

	gp_list_populate(list, "image%02i.pnm", count);

	return (GP_OK);
}

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

	image_no = gp_filesystem_number(fs, folder, filename);

	if(image_no < 0)
		return image_no;

	switch (type) {
	case GP_FILE_TYPE_RAW:
		result =  jd11_get_image_full (camera, image_no, &data,
					    (int*) &size, 1);
		break;
	case GP_FILE_TYPE_NORMAL:
		result =  jd11_get_image_full (camera, image_no, &data,
					    (int*) &size, 0);
		break;
	case GP_FILE_TYPE_PREVIEW:
		result =  jd11_get_image_preview (camera, image_no,
						&data, (int*) &size);
		break;
	default:
		return (GP_ERROR_NOT_SUPPORTED);
	}

	if (result < 0)
		return result;

	gp_file_set_name (file, filename);
	gp_file_set_mime_type (file, "image/pnm");
	gp_file_set_data_and_size (file, data, size);

	return (GP_OK);
}

static int
delete_all_func (CameraFilesystem *fs, const char* folder, void *data)
{
    Camera *camera = data;
    if (strcmp (folder, "/"))
	return (GP_ERROR_DIRECTORY_NOT_FOUND);
    return jd11_erase_all(camera->port);
}

static int camera_summary (Camera *camera, CameraText *summary) 
{
	strcpy(summary->text, _("No summary available."));
	return (GP_OK);
}

static int camera_manual (Camera *camera, CameraText *manual) 
{
	strcpy(manual->text, 
	_(
	"The JD11 camera works rather well with this driver.\n"
	"It gets a bit confused if some data is left over on the serial line,\n"
	"and will report I/O errors on startup. Just switch the camera off and\n"
	"on again and it will no longer do that.\n"
	"An RS232 interface @ 115 kbit is required for image transfer.\n"
	"The driver allows you to get\n\n"
	"   - thumbnails (64x48 PGM format)\n"
	"   - full images (640x480 PPM format)\n"
	"No color correction and no interpolation is applied as of this time.\n"
	"\n\n")); 

	return (GP_OK);
}

static int camera_about (Camera *camera, CameraText *about) 
{
	strcpy (about->text, 
		_("JD11\n"
		"Marcus Meissner <marcus@jet.franken.de>\n"
		"Driver for the Jenoptik JD11 camera.\n"
		"Protocol reverse engineered using WINE and IDA."));

	return (GP_OK);
}
static int camera_config_get (Camera *camera, CameraWidget **window) 
{
	CameraWidget *widget,*section;
	float value_float,red,green,blue;
	int ret;
	gp_widget_new (GP_WIDGET_WINDOW, "JD11 Configuration", window);

	gp_widget_new (GP_WIDGET_SECTION, _("Other Settings"), &section);
	gp_widget_append (*window, section);


       /* Bulb Exposure Time */
	gp_widget_new (GP_WIDGET_RANGE, _("Bulb Exposure Time"), &widget);
	gp_widget_append (section, widget);
	gp_widget_set_range (widget, 1, 9, 1);
	/* this is a write only capability */
	value_float = 1;
	gp_widget_set_value (widget, &value_float);
	gp_widget_changed(widget);

	gp_widget_new (GP_WIDGET_SECTION, _("Color Settings"), &section);
	gp_widget_append (*window, section);

	ret = jd11_get_rgb(camera->port,&red,&green,&blue);
	if (ret != GP_OK)
	    return ret;
	gp_widget_new (GP_WIDGET_RANGE, _("Red"), &widget);
	gp_widget_append (section, widget);
	gp_widget_set_range (widget, 50, 150, 1);
	red*=100.0;
	gp_widget_set_value (widget, &red);
	gp_widget_changed(widget);

	gp_widget_new (GP_WIDGET_RANGE, _("Green"), &widget);
	gp_widget_append (section, widget);
	gp_widget_set_range (widget, 50, 150, 1);
	green*=100.0;
	gp_widget_set_value (widget, &green);
	gp_widget_changed(widget);

	gp_widget_new (GP_WIDGET_RANGE, _("Blue"), &widget);
	gp_widget_append (section, widget);
	gp_widget_set_range (widget, 50, 150, 1);
	blue*=100.0;
	gp_widget_set_value (widget, &blue);
	gp_widget_changed(widget);

	return (GP_OK);
}

static int camera_config_set (Camera *camera, CameraWidget *window) 
{
	float f,red,green,blue;
	CameraWidget *widget,*section;
	int ret,changed = 0;
	/*
	 * Check if the widgets' values have changed. If yes, tell the camera.
	 */
	gp_widget_get_child_by_label (window, _("Other Settings"), &section);
	gp_widget_get_child_by_label (section,_("Bulb Exposure Time"), &widget);
	if (gp_widget_changed (widget)) {
		gp_widget_get_value (widget, &f);
		ret = jd11_set_bulb_exposure(camera->port,(int)f);
		if (ret != GP_OK)
		    return ret;
	}

	gp_widget_get_child_by_label (window, _("Color Settings"), &section);

	gp_widget_get_child_by_label (section,_("Red"), &widget);
	changed|=gp_widget_changed (widget);
	gp_widget_get_value (widget, &red);
	red/=100.0;

	gp_widget_get_child_by_label (section,_("Green"), &widget);
	changed|=gp_widget_changed (widget);
	gp_widget_get_value (widget, &green);
	green/=100.0;

	gp_widget_get_child_by_label (section,_("Blue"), &widget);
	changed|=gp_widget_changed (widget);
	gp_widget_get_value (widget, &blue);
	blue/=100.0;

	ret = GP_OK;
	if (changed)
	    ret =jd11_set_rgb(camera->port,red,green,blue);
	return ret;

}

int camera_init (Camera *camera) 
{
        gp_port_settings settings;
	int ret;

        /* First, set up all the function pointers */
        camera->functions->summary	= camera_summary;
        camera->functions->manual	= camera_manual;
        camera->functions->about	= camera_about;
	camera->functions->get_config	= camera_config_get;
	camera->functions->set_config	= camera_config_set;

        /* Configure port */
        gp_port_set_timeout(camera->port, 1000);
	gp_port_get_settings(camera->port, &settings);
        settings.serial.speed	= 115200;
        settings.serial.bits	= 8;
        settings.serial.parity	= 0;
        settings.serial.stopbits= 1;
        gp_port_set_settings(camera->port, settings);

	/* Set up the filesystem */
	gp_filesystem_set_list_funcs(camera->fs, file_list_func, NULL,camera);
	gp_filesystem_set_file_funcs(camera->fs,get_file_func,NULL,camera);
	gp_filesystem_set_folder_funcs(camera->fs,NULL,delete_all_func, NULL,NULL,camera);
        /* test camera */
        ret = jd11_ping(camera->port);
	return (ret);
}