summaryrefslogtreecommitdiff
path: root/camlibs/mustek/core.c
blob: 52bf8d4d048bcecffd15474f2b0df2e03ff1adfc (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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
/*
 * Copyright 1999/2000 by Henning Zabel <henning@uni-paderborn.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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 * gphoto driver for the Mustek MDC800 Digital Camera. The driver
 * supports rs232 and USB.
 */

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

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

#include "libgphoto2/i18n.h"

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


/*----------------------  Funktion for Communication ------------------------ */

/*
 * Send the Initial Command. If the device is rs232 this
 * function will probe for the baudrate.
 */
static int
mdc800_sendInitialCommand (Camera *camera, unsigned char* answer)
{
	int	baud_rates[3]={19200,57600,115200};
	int	rate,ret;
	unsigned char	command [8]={COMMAND_BEGIN,COMMAND_INIT_CONNECT,0,0,0,COMMAND_END,0,0};

	if (camera->port->type == GP_PORT_USB)
	    return mdc800_io_sendCommand_with_retry(camera->port,command,answer,8,1,1);
	for (rate=0;rate<3;rate++)
	{
	    GPPortSettings settings;

	    ret = gp_port_get_settings(camera->port,&settings);
	    if (ret != GP_OK) return ret;
	    settings.serial.speed = baud_rates[rate];
	    ret = gp_port_set_settings(camera->port, settings);
	    if (ret != GP_OK) return ret;
	    if (GP_OK==mdc800_io_sendCommand_with_retry(camera->port,command,answer,8,1,1)) {
		printCoreNote("RS232 Baudrate probed at %d.\n",baud_rates[rate]);
		return GP_OK;
	    }
	    printCoreError("Probing RS232 Baudrate with %d fails.\n",baud_rates[rate]);
	}
	printCoreError ("Probing failed completely.\n");
	return GP_ERROR_IO;
}

/*
 * Opens the Camera:
 *     (camera is already opened by gphoto2)
 * (1) send Initial command
 */
int mdc800_openCamera (Camera *camera)
{
	unsigned char answer [8];
	int  i,ret;

	if (camera->port->type == GP_PORT_USB) {
		printCoreNote ("Device Registered as USB.\n");
	} else {
		printCoreNote ("Device Registered as RS232. \n");
	}

	camera->pl = malloc(sizeof(struct _CameraPrivateLibrary));
	if (!camera->pl)
	    return GP_ERROR_NO_MEMORY;
	camera->pl->system_flags_valid = 0;
	camera->pl->memory_source = -1;

	/* Send initial command */
	ret = mdc800_sendInitialCommand(camera,answer);
	if (ret != GP_OK)
	{
		printCoreError ("(mdc800_openCamera) can't send initial command.\n");
		return ret;
	}
	printCoreNote ("Firmware info (last 5 Bytes) : ");
	for (i=0; i<8; i++)
		printCoreNote ("%i ", answer[i]);
	printCoreNote ("\n");
	camera->pl->system_flags_valid=0;
	camera->pl->memory_source=-1;
	ret = mdc800_setDefaultStorageSource(camera);
	if (ret != GP_OK) {
		printCoreError ("(mdc800_openCamera) can't set Storage Source.\n");
		return ret;
	}
	return GP_OK;
}

int mdc800_closeCamera (Camera *camera)
{
    if (camera->pl) {
	free(camera->pl);
	camera->pl = NULL;
    }
    return GP_OK;
}


/*
 * Sets the camera speed to the defined value:
 * 0: 19200, 1:57600, 2: 115200
 */
int mdc800_changespeed (Camera *camera,int new)
{
	int baud_rate [3]={19200,57600,115200};
	GPPortSettings settings;
	int ret;
	unsigned int oldrate;

	printFnkCall ("(mdc800_changespeed) called.\n");
	if (camera->port->type != GP_PORT_SERIAL) /* USB ... */
	    return GP_OK;

	gp_port_get_settings(camera->port,&settings);

	if (settings.serial.speed == baud_rate[new]) /* nothing to do */
	    return GP_OK;

	for (oldrate=0;oldrate<sizeof(baud_rate)/sizeof(baud_rate[0]);oldrate++)
	    if (baud_rate[oldrate] == settings.serial.speed)
		break;

	/* We did not find it? Can't happen? */
	if (oldrate == sizeof(baud_rate)/sizeof(baud_rate[0]))
	    return GP_ERROR_IO;

	/* Setting comunication speed */
	ret = mdc800_io_sendCommand(camera->port,COMMAND_CHANGE_RS232_BAUD_RATE,new,oldrate,0,0,0);
	if (ret != GP_OK)
	{
		printCoreError ("(mdc800_changespeed) can't send first command.\n");
		return GP_ERROR_IO;
	}
	settings.serial.speed = baud_rate[new];
	ret = gp_port_set_settings(camera->port,settings);
	if (ret != GP_OK)
	{
		printCoreError ("(mdc800_changespeed) Changing Baudrate fails.\n");
		return ret;
	}
	/* Second Command */
	ret = mdc800_io_sendCommand(camera->port,COMMAND_CHANGE_RS232_BAUD_RATE,new,new,0,0,0);
	if (ret != GP_OK)
	{
		printCoreError ("(mdc800_changespeed) can't send second command.\n");
		return ret;
	}
	printCoreNote ("Set Baudrate to %d\n", baud_rate[new]);
	return GP_OK;
}

/*
 * Get the current Bautrate
 */
int mdc800_getSpeed (Camera *camera, int *speed)
{
	int rate, ret, baud_rate [3]={19200,57600,115200};
	GPPortSettings settings;

	if (camera->port->type != GP_PORT_SERIAL)
	    return GP_ERROR_IO;

	ret = gp_port_get_settings(camera->port,&settings);
	if (ret!=GP_OK) return ret;

	for (rate=0;rate<3;rate++)
	    if (settings.serial.speed == baud_rate[rate])
		break;
	if (rate == 3)
	    return GP_ERROR_IO;
	*speed = rate;
	return GP_OK;
}


/*
 * Sets Target
 * 1: image, 2:thumbnail, 3:video, 4:not setting
 */
int mdc800_setTarget (Camera *camera,int value)
{
	return mdc800_io_sendCommand(camera->port,COMMAND_SET_TARGET,value,0,0,0,0);
}


/*
 * Loads a thumbnail from the cam .
 */
int mdc800_getThumbnail (Camera *camera,int index, void **data, int *size)
{
	int ret;

	printFnkCall ("(mdc800_getThumbNail) called for %i . \n",index);

	*size = 4096;
	*data = malloc(4096);
	if (!*data)
	    return GP_ERROR_NO_MEMORY;
	ret = mdc800_io_sendCommand(camera->port,COMMAND_GET_THUMBNAIL,index/100,(index%100)/10,index%10,*data,4096);
	if (ret != GP_OK)
	{
		printCoreError ("(mdc800_getThumbNail) can't get Thumbnail.\n");
		return ret;
	}
	mdc800_correctImageData(*data,1,0,camera->pl->memory_source == 1);
	return GP_OK;
}



/*
 * Load an Image from the cam ..
 */
int mdc800_getImage (Camera *camera, int nr, void **data, int *size)
{
	unsigned char buffer[3];
	int imagequality=-1;
	int imagesize=0;
	int ret;

	printFnkCall ("(mdc800_getImage) called for %i . \n",nr);

	ret = mdc800_setTarget (camera,1);
	if (GP_OK != ret) {
		printCoreError ("(mdc800_getImage) can't set Target. \n");
		return ret;
	}
	ret = mdc800_io_sendCommand(camera->port,COMMAND_GET_IMAGE_SIZE,nr/100,(nr%100)/10,nr%10,buffer,3);
	if (ret != GP_OK)
	{
		printCoreError ("(mdc800_getImage) request for Imagesize of %i fails.\n",nr);
		return ret;
	}

	imagesize = buffer[0]*65536+buffer[1]*256+buffer[2];
	printCoreNote ("Imagesize of %i is %i ",nr,imagesize);
	switch (imagesize/1024)
	{
	case 48:
		imagequality=0;
		printCoreNote ("(Economic Quality 506x384)\n");
		break;
	case 128:
		imagequality=1;
		printCoreNote ("(Standard Quality 1012x768)\n");
		break;
	case 320:
		imagequality=2;
		printCoreNote ("(High Quality 1012x768)\n");
		break;
	case 4:
		printCoreNote ("(ThumbNail ? 112x96)\n");
		imagequality=-1;
		break;
	default:
		printCoreNote ("(not detected)\n");
		return 0;
	}
	*size = imagesize;
	*data = malloc(imagesize);
	ret = mdc800_io_sendCommand(camera->port,COMMAND_GET_IMAGE,nr/100,(nr%100)/10,nr%10,*data,imagesize);
	if (ret != GP_OK) {
		printCoreError ("(mdc800_getImage) request fails for Image %i.\n",nr);
		return 0;
	}
	mdc800_correctImageData(*data,imagequality == -1,imagequality,camera->pl->memory_source == 1);
	return GP_OK;
}



/* ------	SystemStatus of the Camera ------------------------------------------/ */


/* Load the Status from the camera if necessary */
int mdc800_getSystemStatus (Camera *camera)
{
	int ret = GP_OK;
	int tries = 3;
	if (camera->pl->system_flags_valid)
		return GP_OK;
	fprintf(stderr,"mdc800_getSystemStatus entered...\n");
	while (tries--) {
	    ret = mdc800_io_sendCommand(camera->port,COMMAND_GET_SYSTEM_STATUS,0,0,0,camera->pl->system_flags,4);
	    if (ret == GP_OK)
		break;
	}
	if (ret!=GP_OK)
	{
		printCoreError ("(mdc800_getSystemStatus) request fails.\n");
		return ret;
	}
	fprintf(stderr,"mdc800_getSystemStatus leaving.\n");
	camera->pl->system_flags_valid=1;
	return GP_OK;
}


int mdc800_isCFCardPresent(Camera *camera)
{
	mdc800_getSystemStatus(camera);
	if (camera->pl->system_flags_valid)
		return ((camera->pl->system_flags[0]&1) == 0);
	else
	{
		printCoreError ("(mdc800_isCFCardPresent) detection fails.\n");
		return 0;
	}
}


int mdc800_isBatteryOk(Camera *camera)
{
	mdc800_getSystemStatus(camera);
	return ((camera->pl->system_flags[0]&4) == 0)?1:0;
}


/*
 * Gets CamMode.
 * 0: Camera, 1: Playback, 2:VCam
 */
int mdc800_getMode(Camera *camera)
{
	mdc800_getSystemStatus(camera);
	if ((camera->pl->system_flags[1]&16) == 0)
		return ((camera->pl->system_flags[1]&32) == 0)?1:0;
	else
		return 2;
}


/*
 * Return status of Flashlight. The
 * answer is one of MDC800_FLASHLIGHT_ Mask.
 */
int mdc800_getFlashLightStatus(Camera *camera)
{
	mdc800_getSystemStatus(camera);
	return (camera->pl->system_flags[3]&7);
}


int mdc800_isLCDEnabled(Camera *camera)
{
	mdc800_getSystemStatus(camera);
	return ((camera->pl->system_flags[1]&4) == 4);
}


int mdc800_isMenuOn(Camera *camera)
{
	mdc800_getSystemStatus(camera);
	return ((camera->pl->system_flags[1]&1) == 1);
}

int mdc800_isAutoOffEnabled(Camera *camera)
{
	mdc800_getSystemStatus(camera);
	return ((camera->pl->system_flags[1]&8) == 8);
}

/* ----- Other fine functions------------------------------------------------- */


/*
 * Sets Source of Images :
 * 0: FlashCard, 1: Internal Memory
 */
int mdc800_setStorageSource (Camera *camera,int flag)
{
	int ret;
	if (flag == camera->pl->memory_source)
		return GP_OK;

	/* Check wether FlashCard is present */
	if ((flag == 0) && mdc800_isCFCardPresent (camera))
	{
		printCoreNote ("There's is no FlashCard in the Camera !\n");
		return GP_OK;
	}
	printFnkCall ("(mdc800_setStorageSource) called with flag=%i\n",flag);
	ret=mdc800_io_sendCommand(camera->port,COMMAND_SET_STORAGE_SOURCE,flag,0,0,0,0);
	if (ret != GP_OK)
	{
		if (flag)
		{
			printCoreError ("Can't set InternalMemory as Input!\n");
		}
		else
		{
			printCoreError ("Can't set FlashCard as Input!\n");
		}
		return ret;
	}

	printCoreNote ("Storage Source set to ");
	if (flag) {
		printCoreNote ("Internal Memory.\n");
	} else {
		printCoreNote ("Compact Flash Card.\n");
	}
	camera->pl->system_flags_valid=0;
	camera->pl->memory_source=flag;
	return GP_OK;
}


/*
 * Sets the default storage source.
 * Default means, that if there's a FlashCard, the Flashcard
 * is used, else the InternalMemory
 *
 * If camera->pl->memory_source is set ( after driver has been closed ),
 * this value will be used.
 */
int mdc800_setDefaultStorageSource (Camera *camera)
{
	int ret,source;

	if (camera->pl->memory_source != -1)
	{
		source=camera->pl->memory_source;
		camera->pl->memory_source=-1;
	}
	else
	{
		source=mdc800_isCFCardPresent (camera)?0:1;
	}
	ret=mdc800_setStorageSource (camera,source);
	if (ret!=GP_OK)
	{
		printCoreError ("(mdc800_setDefaultStorageSource) Setting Storage Source fails\n");
		return ret;
	}
	return GP_OK;
}


/*
 *	Returns what StorageSource is selected by the driver
 * 0: FlashCard, 1: Internal
 */
int mdc800_getStorageSource(Camera *camera)
{
	if (camera->pl->memory_source == -1)
		mdc800_setDefaultStorageSource(camera);
	return camera->pl->memory_source;
}



/*
 * Sets Camera to Camera- or PlaybackMode
 * m: 0 Camera, 1 Playback, 2:VCam (USB)
 */
int mdc800_setMode (Camera *camera,int m)
{
	int last=mdc800_getMode (camera);
	int ret;
/*
	if (mdc800_getMode () == m)
		return 1;
*/
	switch (m)
	{
		case 0:
			ret = mdc800_io_sendCommand(camera->port,COMMAND_SET_CAMERA_MODE,0,0,0,0,0);
			if (ret != GP_OK)
			{
				printCoreError ("(mdc800_setMode) setting Camera Mode fails\n");
				return ret;
			}
			if (last != m)
				printCoreNote ("Mode set to Camera Mode.\n");
			break;

		case 1:
			ret = mdc800_io_sendCommand(camera->port,COMMAND_SET_PLAYBACK_MODE,0,0,0,0,0);
			if (ret != GP_OK)
			{
				printCoreError ("(mdc800_setMode) setting Playback Mode fails\n");
				return ret;
			}
			if (last != m)
				printCoreNote ("Mode set to Payback Mode.\n");
			break;

	}
	camera->pl->system_flags_valid=0;
	return GP_OK;
}


/*
 * Sets up Flashlight. The waitForCommit waits a long
 * time, to give the camera enough time to load the
 * flashlight.
 */
int mdc800_setFlashLight (Camera* camera,int value)
{
	int command=0,redeye_flag=0,ret;

	if (mdc800_getFlashLightStatus (camera) == value)
		return GP_OK;

	redeye_flag=(value&MDC800_FLASHLIGHT_REDEYE) != 0;

	if ((value&MDC800_FLASHLIGHT_ON) != 0)
		command=COMMAND_SET_FLASHMODE_ON;
	else if ((value&MDC800_FLASHLIGHT_OFF) != 0)
	{
		command=COMMAND_SET_FLASHMODE_OFF;
		redeye_flag=0;
	}
	else
		command=COMMAND_SET_FLASHMODE_AUTO;

	camera->pl->system_flags_valid=0;
	ret = mdc800_io_sendCommand(camera->port,command,redeye_flag,0,0,0,0);
	if (ret != GP_OK)
	{
		printCoreError ("(mdc800_setFlashLight) sending command fails.\n");
		return ret;
	}
	printCoreNote ("%s", mdc800_getFlashLightString(value));
	printCoreNote ("\n");
	return GP_OK;
}

/*
 * Gets a String with the Text of the Flashlight-Status
 * depending on value
 */
char* mdc800_getFlashLightString (int value)
{
	switch (value)
	{
		case ( MDC800_FLASHLIGHT_REDEYE | MDC800_FLASHLIGHT_AUTO ) :
			return _("FlashLight : Auto (RedEye Reduction)");
		case MDC800_FLASHLIGHT_AUTO :
			return _("FlashLight : Auto");
		case ( MDC800_FLASHLIGHT_REDEYE | MDC800_FLASHLIGHT_ON ) :
			return _("FlashLight : On (RedEye Reduction)");
		case MDC800_FLASHLIGHT_ON :
			return _("FlashLight : On");
		case MDC800_FLASHLIGHT_OFF :
			return _("FlashLight : Off");
	}
	return _("FlashLight : undefined");
}


/*
 * Enable/Disable the LCD
 */
int mdc800_enableLCD (Camera*camera,int enable)
{
	int ret,command;
	if (enable == mdc800_isLCDEnabled (camera))
		return GP_OK;

	if (enable)
		command=COMMAND_SET_LCD_ON;
	else
		command=COMMAND_SET_LCD_OFF;

	camera->pl->system_flags_valid=0;
	ret = mdc800_io_sendCommand (camera->port,command,0,0,0,0,0);
	if (ret!=GP_OK)
	{
		printCoreError ("(mdc800_enableLCD) can't enable/disable LCD\n");
		return ret;
	}
	if (enable)
	{
		printCoreNote ("LCD is enabled\n");
	}
	else
	{
		printCoreNote ("LCD is disabled\n");
	}
	return GP_OK;
}


/*
 * Shows the specified Image, the Camera has to
 * be in Playback Mode !
 */
int mdc800_playbackImage (Camera *camera,int nr )
{
	int ret;
	ret = mdc800_getMode (camera);
	if (ret != GP_OK)
	{
		printCoreError ("(mdc800_showImage) camera must be in Playback Mode !");
		return ret;
	}

	ret = mdc800_io_sendCommand (camera->port,COMMAND_PLAYBACK_IMAGE,nr/100,(nr%100)/10,nr%10,0,0);
	if (ret!=GP_OK)
	{
		printCoreError ("(mdc800_showImage) can't playback Image %i \n",nr);
		return ret;
	}
	return GP_OK;
}

/*
 * With ths function you can get information about, how many
 * pictures can be stored in the free memory of the camera.
 *
 * h: High Quality, s: Standard Quality, e: Economy Quality
 * If one of these Pointers are 0 the will be ignored.
 */
int mdc800_getRemainFreeImageCount (Camera *camera,int* h,int* s,int *e)
{
	unsigned char data [6];
	int ret;

	ret = mdc800_io_sendCommand (camera->port,COMMAND_GET_REMAIN_FREE_IMAGE_COUNT,0,0,0,data,6);
	if (ret != GP_OK)
	{
		printCoreError ("(mdc800_getRemainFreeImageCount) Error sending Command.\n");
		return ret;
	}

	if (h)
		*h=(int)((data[0]/16)*1000)+((data[0]%16)*100)+((data[1]/16)*10)+(data[1]%16);
	if (s)
		*s=(int)((data[2]/16)*1000)+((data[2]%16)*100)+((data[3]/16)*10)+(data[3]%16);
	if (e)
		*e=(int)((data[4]/16)*1000)+((data[4]%16)*100)+((data[5]/16)*10)+(data[5]%16);
	return GP_OK;
}


/*
 * Get Image Quallity
 * 0: Economic, 1:Standard, 2:High
 */
int mdc800_getImageQuality (Camera *camera, unsigned char *retval)
{
	int ret;
	ret = mdc800_io_sendCommand (camera->port,COMMAND_GET_IMAGE_QUALITY,0,0,0,retval,1);
	if (ret!=GP_OK)
	{
		printCoreError ("(mdc800_getImageQuality) fails.\n");
		return ret;
	}
	return GP_OK;
}


/*
 *	Set Image Quality, return GP_OK if ok.
 */
int mdc800_setImageQuality (Camera *camera,int v)
{
    return mdc800_io_sendCommand (camera->port,COMMAND_SET_IMAGE_QUALITY,v,0,0,0,0);
}



/*
 * Set the WhiteBalance value
 * 1:auto ,2:indoor, 4:indoor with flashlight, 8:outdoor
 */
int mdc800_setWB (Camera *camera, int v)
{
    return mdc800_io_sendCommand(camera->port,COMMAND_SET_WB,v,0,0,0,0);
}


/*
 * Return the Exposure settings and W.B.
 */
int mdc800_getWBandExposure (Camera *camera,int* exp, int* wb)
{
	unsigned char retval[2];
	int ret;

	/* What's that here is a real diffenrence between USB and RS232 */
	int toggle= (camera->port->type == GP_PORT_USB);

	ret = mdc800_io_sendCommand(camera->port,COMMAND_GET_WB_AND_EXPOSURE,0,0,0,retval,2);
	if (ret == GP_OK)
	{
		(*exp)= retval[toggle]-2;
		(*wb)= retval[1-toggle];
		return 1;
	}
	printCoreError ("(mdc800_getWBandExposure) fails.\n");
	return 0;
}


/*
 * Sets the Exposure Value
 */
int mdc800_setExposure (Camera *camera,int v)
{
	return mdc800_io_sendCommand(camera->port,COMMAND_SET_EXPOSURE,v+2,0,0,0,0);
}

/*
 * Sets the Exposure Mode
 * 0: MTRX 1:CNTR
 */
int mdc800_setExposureMode (Camera *camera,int m)
{
	return mdc800_io_sendCommand (camera->port,COMMAND_SET_EXPOSURE_MODE,m,0,0,0,0);
}


/*
 * return the Exposure Mode or -1
 */
int mdc800_getExposureMode (Camera *camera,int *retval)
{
	unsigned char cretval;
	int ret;
	ret = mdc800_io_sendCommand (camera->port,COMMAND_GET_EXPOSURE_MODE,0,0,0,&cretval,1);
	if (ret == GP_OK)
	    *retval = cretval;
	return ret;
}

/*
 * Enable, Disable the Menu
 */
int mdc800_enableMenu (Camera *camera,int enable)
{
	char command=enable?COMMAND_SET_MENU_ON:COMMAND_SET_MENU_OFF;

	if (enable == mdc800_isMenuOn (camera))
		return GP_OK;
	camera->pl->system_flags_valid=0;
	return mdc800_io_sendCommand (camera->port,command,0,0,0,0,0);
}

int mdc800_number_of_pictures (Camera *camera, int *nrofpics)
{
	unsigned char answer [2];
	int ret;

	printFnkCall ("(mdc800_number_of_pictures) called.\n");

	ret= mdc800_setTarget (camera, 1);
	if (ret != GP_OK)
	{
		printAPIError ("(mdc800_number_of_pictures) can't set Target\n");
		return ret;
	}

/*
	if (!mdc800_setMode (1))
	{
		printError ("(mdc800_number_of_pictures) can't set Mode\n");
		mdc800_close ();
		return 0;
	}
*/

	ret = mdc800_io_sendCommand(camera->port,COMMAND_GET_NUM_IMAGES,0,0,0,answer,2);
	if (ret != GP_OK)
	{
		printAPIError ("(mdc800_getNumberOfImages) request Number of Pictures fails.\n");
		return ret;
	}
	*nrofpics=answer[0]*256+answer [1];
	return GP_OK;
}