forked from asalamon74/pktriggercord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pslr.c
1809 lines (1601 loc) · 62.8 KB
/
pslr.c
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
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
pkTriggerCord
Copyright (C) 2011-2019 Andras Salamon <andras.salamon@melda.info>
Remote control of Pentax DSLR cameras.
Support for K200D added by Jens Dreyer <jens.dreyer@udo.edu> 04/2011
Support for K-r added by Vincenc Podobnik <vincenc.podobnik@gmail.com> 06/2011
Support for K-30 added by Camilo Polymeris <cpolymeris@gmail.com> 09/2012
Support for K-01 added by Ethan Queen <ethanqueen@gmail.com> 01/2013
Support for K-3 added by Tao Wang <twang2218@gmail.com> 01/2016
based on:
PK-Remote
Remote control of Pentax DSLR cameras.
Copyright (C) 2008 Pontus Lidman <pontus@lysator.liu.se>
PK-Remote for Windows
Copyright (C) 2010 Tomasz Kos
This program 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 3 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 Lesser General Public License for more details.
You should have received a copy of the GNU General Public License
and GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <signal.h>
#ifdef RAD10
#include <windows.h>
#include <utime.h>
#include "tdbtime.h"
#else
#include <unistd.h>
#endif
#include <stdbool.h>
#include <stdarg.h>
#include <dirent.h>
#include "pslr.h"
#include "pslr_log.h"
#include "pslr_scsi.h"
#include "pslr_lens.h"
#include "pslr_utils.h"
#define POLL_INTERVAL 50000 /* Number of us to wait when polling */
#define BLKSZ 65536 /* Block size for downloads; if too big, we get
* memory allocation error from sg driver */
#define BLOCK_RETRY 3 /* Number of retries, since we can occasionally
* get SCSI errors when downloading data */
ipslr_handle_t pslr;
static int ipslr_set_mode(ipslr_handle_t *p, uint32_t mode);
static int ipslr_cmd_00_09(ipslr_handle_t *p, uint32_t mode);
static int ipslr_cmd_10_0a(ipslr_handle_t *p, uint32_t mode);
static int ipslr_cmd_00_05(ipslr_handle_t *p);
static int ipslr_status(ipslr_handle_t *p, uint8_t *buf);
static int ipslr_status_full(ipslr_handle_t *p, pslr_status *status);
static int ipslr_press_shutter(ipslr_handle_t *p, bool fullpress);
static int ipslr_select_buffer(ipslr_handle_t *p, int bufno, pslr_buffer_type buftype, int bufres);
static int ipslr_buffer_segment_info(ipslr_handle_t *p, pslr_buffer_segment_info *pInfo);
static int ipslr_next_segment(ipslr_handle_t *p);
static int ipslr_download(ipslr_handle_t *p, uint32_t addr, uint32_t length, uint8_t *buf);
static int ipslr_identify(ipslr_handle_t *p);
static int _ipslr_write_args(uint8_t cmd_2, ipslr_handle_t *p, int n, ...);
#define ipslr_write_args(p,n,...) _ipslr_write_args(0,(p),(n),__VA_ARGS__)
#define ipslr_write_args_special(p,n,...) _ipslr_write_args(4,(p),(n),__VA_ARGS__)
static int command(FDTYPE fd, int a, int b, int c);
static int get_status(FDTYPE fd);
static int get_result(FDTYPE fd);
static int read_result(FDTYPE fd, uint8_t *buf, uint32_t n);
void hexdump(uint8_t *buf, uint32_t bufLen);
static pslr_progress_callback_t progress_callback = NULL;
user_file_format_t pslr_user_file_formats[3] = {
{ USER_FILE_FORMAT_PEF, "PEF", "pef"},
{ USER_FILE_FORMAT_DNG, "DNG", "dng"},
{ USER_FILE_FORMAT_JPEG, "JPEG", "jpg"},
};
const char* valid_vendors[3] = {"PENTAX", "SAMSUNG", "RICOHIMG"};
const char* valid_models[3] = {"DIGITAL_CAMERA", "DSC", "Digital Camera"};
// x18 subcommands to change camera properties
// X18_n: unknown effect
typedef enum {
X18_00,
X18_EXPOSURE_MODE,
X18_02,
X18_AE_METERING_MODE,
X18_FLASH_MODE,
X18_AF_MODE,
X18_AF_POINT_SEL,
X18_AF_POINT,
X18_08,
X18_09,
X18_0A,
X18_0B,
X18_0C,
X18_0D,
X18_0E,
X18_0F,
X18_WHITE_BALANCE,
X18_WHITE_BALANCE_ADJ,
X18_IMAGE_FORMAT,
X18_JPEG_STARS,
X18_JPEG_RESOLUTION,
X18_ISO,
X18_SHUTTER,
X18_APERTURE,
X18_EC,
X18_19,
X18_FLASH_EXPOSURE_COMPENSATION,
X18_JPEG_IMAGE_TONE,
X18_DRIVE_MODE,
X18_1D,
X18_1E,
X18_RAW_FORMAT,
X18_JPEG_SATURATION,
X18_JPEG_SHARPNESS,
X18_JPEG_CONTRAST,
X18_COLOR_SPACE,
X18_24,
X18_JPEG_HUE
} x18_subcommands_t;
// x10 subcommands for buttons
// X10_n: unknown effect
typedef enum {
X10_00,
X10_01,
X10_02,
X10_03,
X10_04,
X10_SHUTTER,
X10_AE_LOCK,
X10_GREEN,
X10_AE_UNLOCK,
X10_09,
X10_CONNECT,
X10_0B,
X10_CONTINUOUS,
X10_BULB,
X10_0E,
X10_0F,
X10_10,
X10_DUST
} x10_subcommands_t;
/* ************** Enabling/disabling debug mode *************/
/* Done by reverse engineering the USB communication between PK Tether and */
/* Pentax K-10D camera. The debug on/off should work without breaking the */
/* camera, but you are invoking this subroutines without any warranties */
/* Written by: Samo Penic, 2014 */
#define DEBUG_OFF 0
#define DEBUG_ON 1
/* a different write_args function needs to be done with slightly changed */
/* command sequence. Original function was ipslr_write_args(). */
static
int pslr_get_buffer_status(ipslr_handle_t *p, uint32_t *x, uint32_t *y) {
//ipslr_handle_t *p = (ipslr_handle_t *) h;
DPRINT("[C]\t\tipslr_get_buffer_status()\n");
uint8_t buf[8];
int n;
CHECK(command(p->fd, 0x02, 0x00, 0));
n = get_result(p->fd);
DPRINT("[C]\t\tipslr_get_buffer_status() bytes: %d\n",n);
if (n!= 8) {
return PSLR_READ_ERROR;
}
CHECK(read_result(p->fd, buf, n));
int i;
for (i=0; i<n; ++i) {
DPRINT("[C]\t\tbuf[%d]=%02x\n",i,buf[i]);
}
get_uint32_func get_uint32_func_ptr;
if (p->model->is_little_endian) {
get_uint32_func_ptr = get_uint32_le;
} else {
get_uint32_func_ptr = get_uint32_be;
}
*x = (*get_uint32_func_ptr)(buf);
*y = (*get_uint32_func_ptr)(buf+4);
return PSLR_OK;
}
/* Commands in form 23 XX YY. I know it is stupid, but ipslr_cmd functions */
/* are sooooo handy. */
static int ipslr_cmd_23_XX(ipslr_handle_t *p, char XX, char YY, uint32_t mode) {
DPRINT("[C]\t\tipslr_cmd_23_XX(%x, %x, mode=%x)\n", XX, YY, mode);
CHECK(ipslr_write_args(p, 1, mode));
CHECK(command(p->fd, 0x23, XX, YY));
CHECK(get_status(p->fd));
return PSLR_OK;
}
/* First of two exceptions. Command 0x23 0x06 0x14 behaves differently than */
/* generic 23 XX YY commands */
static int ipslr_cmd_23_06(ipslr_handle_t *p, char debug_on_off) {
DPRINT("[C]\t\tipslr_cmd_23_06(debug=%d)\n", debug_on_off);
CHECK(ipslr_write_args(p, 1, 3));
if (debug_on_off==0) {
CHECK(ipslr_write_args_special(p, 4,0,0,0,0));
} else {
CHECK(ipslr_write_args_special(p, 4,1,1,0,0));
}
CHECK(command(p->fd, 0x23, 0x06, 0x14));
CHECK(get_status(p->fd));
return PSLR_OK;
}
/* Second exception. Command 0x23 0x04 0x08 behaves differently than generic */
/* 23 XX YY commands */
static int ipslr_cmd_23_04(ipslr_handle_t *p) {
DPRINT("[C]\t\tipslr_cmd_23_04()\n");
CHECK(ipslr_write_args(p, 1, 3)); // posebni ARGS-i
CHECK(ipslr_write_args_special(p, 1, 1)); // posebni ARGS-i
CHECK(command(p->fd, 0x23, 0x04, 0x08));
CHECK(get_status(p->fd));
return PSLR_OK;
}
/* Function called to enable/disable debug mode. If debug_mode argument is 0 */
/* function disables debug mode, else debug mode is enabled */
int pslr_set_debugmode(ipslr_handle_t *p, char debug_mode) {
DPRINT("[C]\tpslr_set_debugmode(%d)\n", debug_mode);
uint8_t buf[16]; /* buffer for storing statuses and read_results */
ipslr_cmd_00_09(p,1);
ipslr_cmd_23_XX(p,0x07,0x04,3);
read_result(p->fd,buf,0x10);
ipslr_cmd_23_XX(p,0x05,0x04,3);
read_result(p->fd,buf,0x04);
ipslr_status(p,buf);
if (debug_mode==0) {
ipslr_cmd_23_06(p,DEBUG_OFF);
} else {
ipslr_cmd_23_06(p,DEBUG_ON);
}
ipslr_status(p,buf);
ipslr_cmd_23_04(p);
ipslr_cmd_23_XX(p,0x00,0x04, 0);
ipslr_cmd_00_09(p,2);
ipslr_status(p,buf);
return PSLR_OK;
}
/* ************* End enabling/disabling debug mode ************ */
user_file_format_t *pslr_get_user_file_format_t( user_file_format uff ) {
unsigned int i;
for (i = 0; i<sizeof(pslr_user_file_formats) / sizeof(pslr_user_file_formats[0]); i++) {
if (pslr_user_file_formats[i].uff == uff) {
return &pslr_user_file_formats[i];
}
}
return NULL;
}
int pslr_set_user_file_format(pslr_handle_t h, user_file_format uff) {
switch ( uff ) {
case USER_FILE_FORMAT_PEF:
pslr_set_image_format(h, PSLR_IMAGE_FORMAT_RAW);
pslr_set_raw_format(h, PSLR_RAW_FORMAT_PEF);
break;
case USER_FILE_FORMAT_DNG:
pslr_set_image_format(h, PSLR_IMAGE_FORMAT_RAW);
pslr_set_raw_format(h, PSLR_RAW_FORMAT_DNG);
break;
case USER_FILE_FORMAT_JPEG:
pslr_set_image_format(h, PSLR_IMAGE_FORMAT_JPEG);
break;
case USER_FILE_FORMAT_MAX:
return PSLR_PARAM;
}
return PSLR_OK;
}
user_file_format pslr_get_user_file_format( pslr_status *st ) {
int rawfmt = st->raw_format;
int imgfmt = st->image_format;
if (imgfmt == PSLR_IMAGE_FORMAT_JPEG) {
return USER_FILE_FORMAT_JPEG;
} else {
if (rawfmt == PSLR_RAW_FORMAT_PEF) {
return USER_FILE_FORMAT_PEF;
} else {
return USER_FILE_FORMAT_DNG;
}
}
}
// most of the cameras require this exposure mode conversion step
pslr_gui_exposure_mode_t exposure_mode_conversion( pslr_exposure_mode_t exp ) {
switch ( exp ) {
case PSLR_EXPOSURE_MODE_GREEN:
return PSLR_GUI_EXPOSURE_MODE_GREEN;
case PSLR_EXPOSURE_MODE_P:
return PSLR_GUI_EXPOSURE_MODE_P;
case PSLR_EXPOSURE_MODE_SV:
return PSLR_GUI_EXPOSURE_MODE_SV;
case PSLR_EXPOSURE_MODE_TV:
return PSLR_GUI_EXPOSURE_MODE_TV;
case PSLR_EXPOSURE_MODE_AV:
case PSLR_EXPOSURE_MODE_AV_OFFAUTO:
return PSLR_GUI_EXPOSURE_MODE_AV;
case PSLR_EXPOSURE_MODE_TAV:
return PSLR_GUI_EXPOSURE_MODE_TAV;
case PSLR_EXPOSURE_MODE_M:
case PSLR_EXPOSURE_MODE_M_OFFAUTO:
return PSLR_GUI_EXPOSURE_MODE_M;
case PSLR_EXPOSURE_MODE_B:
case PSLR_EXPOSURE_MODE_B_OFFAUTO:
return PSLR_GUI_EXPOSURE_MODE_B;
case PSLR_EXPOSURE_MODE_X:
return PSLR_GUI_EXPOSURE_MODE_X;
case PSLR_EXPOSURE_MODE_MAX:
return PSLR_GUI_EXPOSURE_MODE_MAX;
}
return 0;
}
pslr_handle_t pslr_init( char *model, char *device ) {
FDTYPE fd;
char vendorId[20];
char productId[20];
int driveNum;
char **drives;
const char *camera_name;
DPRINT("[C]\tpslr_init()\n");
if ( device == NULL ) {
drives = get_drives(&driveNum);
} else {
driveNum = 1;
drives = malloc( driveNum * sizeof(char*) );
drives[0] = strdup( device );
}
DPRINT("driveNum:%d\n",driveNum);
int i;
for ( i=0; i<driveNum; ++i ) {
pslr_result result = get_drive_info( drives[i], &fd, vendorId, sizeof(vendorId), productId, sizeof(productId));
DPRINT("\tChecking drive: %s %s %s\n", drives[i], vendorId, productId);
if ( find_in_array( valid_vendors, sizeof(valid_vendors)/sizeof(valid_vendors[0]),vendorId) != -1
&& find_in_array( valid_models, sizeof(valid_models)/sizeof(valid_models[0]), productId) != -1 ) {
if ( result == PSLR_OK ) {
DPRINT("\tFound camera %s %s\n", vendorId, productId);
pslr.fd = fd;
if ( model != NULL ) {
// user specified the camera model
camera_name = pslr_get_camera_name( &pslr );
DPRINT("\tName of the camera: %s\n", camera_name);
if ( str_comparison_i( camera_name, model, strlen( camera_name) ) == 0 ) {
return &pslr;
} else {
DPRINT("\tIgnoring camera %s %s\n", vendorId, productId);
pslr_shutdown ( &pslr );
pslr.id = 0;
pslr.model = NULL;
}
} else {
return &pslr;
}
} else {
DPRINT("\tCannot get drive info of Pentax camera. Please do not forget to install the program using 'make install'\n");
// found the camera but communication is not possible
close_drive( &fd );
continue;
}
} else {
close_drive( &fd );
continue;
}
}
DPRINT("\tcamera not found\n");
return NULL;
}
int pslr_connect(pslr_handle_t h) {
DPRINT("[C]\tpslr_connect()\n");
ipslr_handle_t *p = (ipslr_handle_t *) h;
uint8_t statusbuf[28];
CHECK(ipslr_status(p, statusbuf));
CHECK(ipslr_set_mode(p, 1));
CHECK(ipslr_status(p, statusbuf));
CHECK(ipslr_identify(p));
if ( !p->model ) {
DPRINT("\nUnknown Pentax camera.\n");
return -1;
}
CHECK(ipslr_status_full(p, &p->status));
DPRINT("\tinit bufmask=0x%x\n", p->status.bufmask);
if ( !p->model->old_scsi_command ) {
CHECK(ipslr_cmd_00_09(p, 2));
}
CHECK(ipslr_status_full(p, &p->status));
CHECK(ipslr_cmd_10_0a(p, 1));
if ( p->model->old_scsi_command ) {
CHECK(ipslr_cmd_00_05(p));
}
CHECK(ipslr_status_full(p, &p->status));
return 0;
}
int pslr_disconnect(pslr_handle_t h) {
DPRINT("[C]\tpslr_disconnect()\n");
ipslr_handle_t *p = (ipslr_handle_t *) h;
uint8_t statusbuf[28];
CHECK(ipslr_cmd_10_0a(p, 0));
CHECK(ipslr_set_mode(p, 0));
CHECK(ipslr_status(p, statusbuf));
return PSLR_OK;
}
int pslr_shutdown(pslr_handle_t h) {
DPRINT("[C]\tpslr_shutdown()\n");
ipslr_handle_t *p = (ipslr_handle_t *) h;
close_drive(&p->fd);
return PSLR_OK;
}
int pslr_shutter(pslr_handle_t h) {
DPRINT("[C]\tpslr_shutter()\n");
ipslr_handle_t *p = (ipslr_handle_t *) h;
return ipslr_press_shutter(p, true);
}
int pslr_focus(pslr_handle_t h) {
DPRINT("[C]\tpslr_focus()\n");
ipslr_handle_t *p = (ipslr_handle_t *) h;
return ipslr_press_shutter(p, false);
}
int pslr_get_status(pslr_handle_t h, pslr_status *ps) {
DPRINT("[C]\tpslr_get_status()\n");
ipslr_handle_t *p = (ipslr_handle_t *) h;
memset( ps, 0, sizeof( pslr_status ));
CHECK(ipslr_status_full(p, &p->status));
memcpy(ps, &p->status, sizeof (pslr_status));
return PSLR_OK;
}
char *pslr_format_rational( pslr_rational_t rational, char * fmt ) {
char *ret = malloc(32);
if ( rational.denom == 0 ) {
snprintf( ret, 32, "unknown" );
} else {
snprintf( ret, 32, fmt, 1.0 * rational.nom / rational.denom );
}
return ret;
}
static
char *get_white_balance_single_adjust_str( uint32_t adjust, char negativeChar, char positiveChar ) {
char *ret = malloc(4);
if ( adjust < 7 ) {
snprintf( ret, 4, "%c%d", negativeChar, 7-adjust);
} else if ( adjust > 7 ) {
snprintf( ret, 4, "%c%d", positiveChar, adjust-7);
} else {
strcpy(ret,"");
}
return ret;
}
static
char *get_white_balance_adjust_str( uint32_t adjust_mg, uint32_t adjust_ba ) {
char *ret = malloc(8);
if ( adjust_mg != 7 || adjust_ba != 7 ) {
snprintf(ret, 8, "%s%s", get_white_balance_single_adjust_str(adjust_mg, 'M', 'G'),get_white_balance_single_adjust_str(adjust_ba, 'B', 'A'));
} else {
strcpy(ret,"0");
}
return ret;
}
char *pslr_get_af_name(pslr_handle_t h, uint32_t af_point) {
ipslr_handle_t *p = (ipslr_handle_t *) h;
if (p->model->af_point_num==11) {
return pslr_get_af11_point_str(af_point);
} else {
char *raw = malloc(11);
sprintf(raw, "%d", af_point);
return raw;
}
}
char *pslr_get_status_info( pslr_handle_t h, pslr_status status ) {
char *strbuffer = malloc(8192);
sprintf(strbuffer,"%-32s: %d\n", "current iso", status.current_iso);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %d/%d\n", "current shutter speed", status.current_shutter_speed.nom, status.current_shutter_speed.denom);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %d/%d\n", "camera max shutter speed", status.max_shutter_speed.nom, status.max_shutter_speed.denom);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "current aperture", pslr_format_rational( status.current_aperture, "%.1f"));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "lens max aperture", pslr_format_rational( status.lens_max_aperture, "%.1f"));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "lens min aperture", pslr_format_rational( status.lens_min_aperture, "%.1f"));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %d/%d\n", "set shutter speed", status.set_shutter_speed.nom, status.set_shutter_speed.denom);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "set aperture", pslr_format_rational( status.set_aperture, "%.1f"));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "fixed iso", status.fixed_iso);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %d-%d\n", "auto iso", status.auto_iso_min,status.auto_iso_max);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "jpeg quality", status.jpeg_quality);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %dM\n", "jpeg resolution", pslr_get_jpeg_resolution( h, status.jpeg_resolution));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "jpeg image tone", pslr_get_jpeg_image_tone_str(status.jpeg_image_tone));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "jpeg saturation", status.jpeg_saturation);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "jpeg contrast", status.jpeg_contrast);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "jpeg sharpness", status.jpeg_sharpness);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "jpeg hue", status.jpeg_hue);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s mm\n", "zoom", pslr_format_rational(status.zoom, "%.2f"));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "focus", status.focus);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "color space", pslr_get_color_space_str(status.color_space));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "image format", pslr_get_image_format_str(status.image_format));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "raw format", pslr_get_raw_format_str(status.raw_format));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "light meter flags", status.light_meter_flags);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "ec", pslr_format_rational( status.ec, "%.2f" ) );
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s EV steps\n", "custom ev steps", pslr_get_custom_ev_steps_str(status.custom_ev_steps));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s EV steps\n", "custom sensitivity steps", pslr_get_custom_sensitivity_steps_str(status.custom_sensitivity_steps));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "exposure mode", status.exposure_mode);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "scene mode", pslr_get_scene_mode_str(status.scene_mode));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "user mode flag", status.user_mode_flag);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "ae metering mode", pslr_get_ae_metering_str(status.ae_metering_mode));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "af mode", pslr_get_af_mode_str(status.af_mode));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "af point select", pslr_get_af_point_sel_str(status.af_point_select));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "selected af point", pslr_get_af_name( h, status.selected_af_point));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "focused af point", pslr_get_af_name( h, status.focused_af_point));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "drive mode", pslr_get_drive_mode_str(status.drive_mode));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "auto bracket mode", status.auto_bracket_mode > 0 ? "on" : "off");
sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "auto bracket picture count", status.auto_bracket_picture_count);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "auto bracket picture counter", status.auto_bracket_picture_counter);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "auto bracket ev", pslr_format_rational(status.auto_bracket_ev, "%.2f"));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "shake reduction", status.shake_reduction > 0 ? "on" : "off");
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "white balance mode", pslr_get_white_balance_mode_str(status.white_balance_mode));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "white balance adjust", get_white_balance_adjust_str(status.white_balance_adjust_mg, status.white_balance_adjust_ba));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "flash mode", pslr_get_flash_mode_str(status.flash_mode));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %.2f\n", "flash exposure compensation", (1.0 * status.flash_exposure_compensation/256));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %.2f\n", "manual mode ev", (1.0 * status.manual_mode_ev / 10));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "lens", pslr_get_lens_name(status.lens_id1, status.lens_id2));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %.2fV %.2fV %.2fV %.2fV\n", "battery", 0.01 * status.battery_1, 0.01 * status.battery_2, 0.01 * status.battery_3, 0.01 * status.battery_4);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "buffer mask", int_to_binary(status.bufmask));
return strbuffer;
}
static
char *get_hardwired_setting_bool_info( pslr_bool_setting setting) {
char *strbuffer = malloc(32+1);
sprintf(strbuffer,"%-32s", setting.pslr_setting_status == PSLR_SETTING_STATUS_HARDWIRED ? "\t[hardwired]" : "");
return strbuffer;
}
static
char *get_special_setting_info( pslr_setting_status_t setting_status) {
char *strbuffer = malloc(32);
switch ( setting_status ) {
case PSLR_SETTING_STATUS_NA:
sprintf(strbuffer,"N/A");
break;
case PSLR_SETTING_STATUS_UNKNOWN:
sprintf(strbuffer,"Unknown");
break;
default:
free(strbuffer);
return NULL;
}
return strbuffer;
}
static
char *get_hardwired_setting_uint16_info( pslr_uint16_setting setting) {
char *strbuffer = malloc(32+1);
sprintf(strbuffer,"%-32s", setting.pslr_setting_status == PSLR_SETTING_STATUS_HARDWIRED ? "\t[hardwired]" : "");
return strbuffer;
}
char *pslr_get_settings_info( pslr_handle_t h, pslr_settings settings ) {
char *strbuffer = malloc(8192);
sprintf(strbuffer,"%-32s: %-8s%s\n", "one push bracketing", get_special_setting_info(settings.one_push_bracketing.pslr_setting_status) ?: settings.one_push_bracketing.value ? "on" : "off", get_hardwired_setting_bool_info(settings.one_push_bracketing));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %-8s%s\n", "bulb mode", get_special_setting_info(settings.bulb_mode_press_press.pslr_setting_status) ?: settings.bulb_mode_press_press.value ? "press-press" : "press-hold", get_hardwired_setting_bool_info(settings.bulb_mode_press_press));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %-8s%s\n", "bulb timer", get_special_setting_info(settings.bulb_timer.pslr_setting_status) ?: settings.bulb_timer.value ? "on" : "off", get_hardwired_setting_bool_info(settings.bulb_timer));
char *bulb_timer_sec = malloc(32);
sprintf(bulb_timer_sec, "%d s", settings.bulb_timer_sec.value);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %-8s%s\n", "bulb timer sec", get_special_setting_info(settings.bulb_timer_sec.pslr_setting_status) ?: bulb_timer_sec, get_hardwired_setting_uint16_info(settings.bulb_timer_sec));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %-8s%s\n", "remote bulb mode", get_special_setting_info(settings.remote_bulb_mode_press_press.pslr_setting_status) ?: settings.remote_bulb_mode_press_press.value ? "press-press" : "press-hold", get_hardwired_setting_bool_info(settings.remote_bulb_mode_press_press));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %-8s%s\n", "using aperture ring", get_special_setting_info(settings.using_aperture_ring.pslr_setting_status) ?: settings.using_aperture_ring.value ? "on" : "off", get_hardwired_setting_bool_info(settings.using_aperture_ring));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %-8s%s\n", "shake reduction", get_special_setting_info(settings.shake_reduction.pslr_setting_status) ?: settings.shake_reduction.value ? "on" : "off", get_hardwired_setting_bool_info(settings.shake_reduction));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %-8s%s\n", "astrotracer", get_special_setting_info(settings.astrotracer.pslr_setting_status) ?: settings.astrotracer.value ? "on" : "off", get_hardwired_setting_bool_info(settings.astrotracer));
char *astrotracer_timer_sec = malloc(32);
sprintf(astrotracer_timer_sec, "%d s", settings.astrotracer_timer_sec.value);
sprintf(strbuffer+strlen(strbuffer),"%-32s: %-8s%s\n", "astrotracer timer sec", get_special_setting_info(settings.astrotracer_timer_sec.pslr_setting_status) ?: astrotracer_timer_sec, get_hardwired_setting_uint16_info(settings.astrotracer_timer_sec));
sprintf(strbuffer+strlen(strbuffer),"%-32s: %-8s%s\n", "horizon correction", get_special_setting_info(settings.horizon_correction.pslr_setting_status) ?: settings.horizon_correction.value ? "on" : "off", get_hardwired_setting_bool_info(settings.horizon_correction));
return strbuffer;
}
int pslr_get_status_buffer(pslr_handle_t h, uint8_t *st_buf) {
DPRINT("[C]\tpslr_get_status_buffer()\n");
ipslr_handle_t *p = (ipslr_handle_t *) h;
memset( st_buf, 0, MAX_STATUS_BUF_SIZE);
// CHECK(ipslr_status_full(p, &p->status));
// ipslr_status_full(p, &p->status);
memcpy(st_buf, p->status_buffer, MAX_STATUS_BUF_SIZE);
return PSLR_OK;
}
int pslr_get_settings_buffer(pslr_handle_t h, uint8_t *st_buf) {
DPRINT("[C]\tpslr_get_settings_buffer()\n");
ipslr_handle_t *p = (ipslr_handle_t *) h;
memset( st_buf, 0, SETTINGS_BUFFER_SIZE);
memcpy(st_buf, p->settings_buffer, SETTINGS_BUFFER_SIZE);
return PSLR_OK;
}
int pslr_get_buffer(pslr_handle_t h, int bufno, pslr_buffer_type type, int resolution,
uint8_t **ppData, uint32_t *pLen) {
DPRINT("[C]\tpslr_get_buffer()\n");
uint8_t *buf = 0;
int ret;
ret = pslr_buffer_open(h, bufno, type, resolution);
if ( ret != PSLR_OK ) {
return ret;
}
uint32_t size = pslr_buffer_get_size(h);
buf = malloc(size);
if (!buf) {
return PSLR_NO_MEMORY;
}
uint32_t bufpos = 0;
while (true) {
uint32_t nextread = size - bufpos > 65536 ? 65536 : size - bufpos;
if (nextread == 0) {
break;
}
uint32_t bytes = pslr_buffer_read(h, buf+bufpos, nextread);
if (bytes == 0) {
break;
}
bufpos += bytes;
}
if ( bufpos != size ) {
free(buf);
return PSLR_READ_ERROR;
}
pslr_buffer_close(h);
if (ppData) {
*ppData = buf;
}
if (pLen) {
*pLen = size;
}
return PSLR_OK;
}
int pslr_set_progress_callback(pslr_handle_t h, pslr_progress_callback_t cb, uintptr_t user_data) {
progress_callback = cb;
return PSLR_OK;
}
static
int ipslr_handle_command_x18( ipslr_handle_t *p, bool cmd9_wrap, int subcommand, int argnum, ...) {
DPRINT("[C]\t\tipslr_handle_command_x18(0x%x, %d)\n", subcommand, argnum);
if ( cmd9_wrap ) {
CHECK(ipslr_cmd_00_09(p, 1));
}
// max 4 args
va_list ap;
int args[4];
int i;
for ( i = 0; i < 4; ++i ) {
args[i] = 0;
}
va_start(ap, argnum);
for (i = 0; i < argnum; i++) {
args[i] = va_arg(ap, int);
}
va_end(ap);
CHECK(ipslr_write_args(p, argnum, args[0], args[1], args[2], args[3]));
CHECK(command(p->fd, 0x18, subcommand, 4 * argnum));
CHECK(get_status(p->fd));
if ( cmd9_wrap ) {
CHECK(ipslr_cmd_00_09(p, 2));
}
return PSLR_OK;
}
int pslr_test( pslr_handle_t h, bool cmd9_wrap, int subcommand, int argnum, int arg1, int arg2, int arg3, int arg4) {
DPRINT("[C]\tpslr_test(wrap=%d, subcommand=0x%x, %x, %x, %x, %x)\n", cmd9_wrap, subcommand, arg1, arg2, arg3, arg4);
ipslr_handle_t *p = (ipslr_handle_t *) h;
return ipslr_handle_command_x18( p, cmd9_wrap, subcommand, argnum, arg1, arg2, arg3, arg4);
}
int pslr_set_shutter(pslr_handle_t h, pslr_rational_t value) {
DPRINT("[C]\tpslr_set_shutter(%x %x)\n", value.nom, value.denom);
ipslr_handle_t *p = (ipslr_handle_t *) h;
return ipslr_handle_command_x18( p, true, X18_SHUTTER, 2, value.nom, value.denom, 0);
}
int pslr_set_aperture(pslr_handle_t h, pslr_rational_t value) {
DPRINT("[C]\tpslr_set_aperture(%x %x)\n", value.nom, value.denom);
ipslr_handle_t *p = (ipslr_handle_t *) h;
return ipslr_handle_command_x18( p, false, X18_APERTURE, 3, value.nom, value.denom, 0);
}
int pslr_set_iso(pslr_handle_t h, uint32_t value, uint32_t auto_min_value, uint32_t auto_max_value) {
DPRINT("[C]\tpslr_set_iso(0x%X, auto_min=%X, auto_max=%X)\n", value, auto_min_value, auto_max_value);
ipslr_handle_t *p = (ipslr_handle_t *) h;
return ipslr_handle_command_x18( p, true, X18_ISO, 3, value, auto_min_value, auto_max_value);
}
int pslr_set_expose_compensation(pslr_handle_t h, pslr_rational_t value) {
DPRINT("[C]\tpslr_set_expose_compensation(0x%X 0x%X)\n", value.nom, value.denom);
ipslr_handle_t *p = (ipslr_handle_t *) h;
return ipslr_handle_command_x18( p, true, X18_EC, 2, value.nom, value.denom, 0);
}
int pslr_set_white_balance(pslr_handle_t h, pslr_white_balance_mode_t wb_mode) {
DPRINT("[C]\tpslr_set_white_balance(0x%X)\n", wb_mode);
ipslr_handle_t *p = (ipslr_handle_t *) h;
return ipslr_handle_command_x18( p, true, X18_WHITE_BALANCE, 1, wb_mode);
}
int pslr_set_white_balance_adjustment(pslr_handle_t h, pslr_white_balance_mode_t wb_mode, uint32_t wbadj_mg, uint32_t wbadj_ba) {
DPRINT("[C]\tpslr_set_white_balance_adjustment(mode=0x%X, tint=0x%X, temp=0x%X)\n", wb_mode, wbadj_mg, wbadj_ba);
ipslr_handle_t *p = (ipslr_handle_t *) h;
return ipslr_handle_command_x18( p, true, X18_WHITE_BALANCE_ADJ, 3, wb_mode, wbadj_mg, wbadj_ba);
}
int pslr_set_flash_mode(pslr_handle_t h, pslr_flash_mode_t value) {
DPRINT("[C]\tpslr_set_flash_mode(%X)\n", value);
ipslr_handle_t *p = (ipslr_handle_t *) h;
return ipslr_handle_command_x18( p, true, X18_FLASH_MODE, 1, value, 0, 0);
}
int pslr_set_flash_exposure_compensation(pslr_handle_t h, pslr_rational_t value) {
DPRINT("[C]\tpslr_set_flash_exposure_compensation(%X %X)\n", value.nom, value.denom);
ipslr_handle_t *p = (ipslr_handle_t *) h;
return ipslr_handle_command_x18( p, true, X18_FLASH_EXPOSURE_COMPENSATION, 2, value.nom, value.denom, 0);
}
int pslr_set_drive_mode(pslr_handle_t h, pslr_drive_mode_t drive_mode) {
DPRINT("[C]\tpslr_set_drive_mode(%X)\n", drive_mode);
ipslr_handle_t *p = (ipslr_handle_t *) h;
return ipslr_handle_command_x18( p, true, X18_DRIVE_MODE, 1, drive_mode, 0, 0);
}
int pslr_set_ae_metering_mode(pslr_handle_t h, pslr_ae_metering_t ae_metering_mode) {
DPRINT("[C]\tpslr_set_ae_metering_mode(%X)\n", ae_metering_mode);
ipslr_handle_t *p = (ipslr_handle_t *) h;
return ipslr_handle_command_x18( p, true, X18_AE_METERING_MODE, 1, ae_metering_mode, 0, 0);
}
int pslr_set_af_mode(pslr_handle_t h, pslr_af_mode_t af_mode) {
DPRINT("[C]\tpslr_set_af_mode(%X)\n", af_mode);
ipslr_handle_t *p = (ipslr_handle_t *) h;
return ipslr_handle_command_x18( p, true, X18_AF_MODE, 1, af_mode, 0, 0);
}
int pslr_set_af_point_sel(pslr_handle_t h, pslr_af_point_sel_t af_point_sel) {
DPRINT("[C]\tpslr_set_af_point_sel(%X)\n", af_point_sel);
ipslr_handle_t *p = (ipslr_handle_t *) h;
return ipslr_handle_command_x18( p, true, X18_AF_POINT_SEL, 1, af_point_sel, 0, 0);
}
int pslr_set_jpeg_stars(pslr_handle_t h, int jpeg_stars ) {
DPRINT("[C]\tpslr_set_jpeg_stars(%X)\n", jpeg_stars);
int hwqual;
ipslr_handle_t *p = (ipslr_handle_t *) h;
if ( jpeg_stars > p->model->max_jpeg_stars ) {
return PSLR_PARAM;
}
hwqual = pslr_get_hw_jpeg_quality( p->model, jpeg_stars );
return ipslr_handle_command_x18( p, true, X18_JPEG_STARS, 2, 1, hwqual, 0);
}
static
int _get_user_jpeg_resolution( ipslr_model_info_t *model, int hwres ) {
return model->jpeg_resolutions[hwres];
}
int pslr_get_jpeg_resolution(pslr_handle_t h, int hwres) {
ipslr_handle_t *p = (ipslr_handle_t *) h;
return _get_user_jpeg_resolution( p->model, hwres );
}
static
int _get_hw_jpeg_resolution( ipslr_model_info_t *model, int megapixel) {
int resindex = 0;
while ( resindex < MAX_RESOLUTION_SIZE && model->jpeg_resolutions[resindex] > megapixel ) {
++resindex;
}
return resindex < MAX_RESOLUTION_SIZE ? resindex : MAX_RESOLUTION_SIZE-1;
}
int pslr_set_jpeg_resolution(pslr_handle_t h, int megapixel) {
DPRINT("[C]\tpslr_set_jpeg_resolution(%X)\n", megapixel);
ipslr_handle_t *p = (ipslr_handle_t *) h;
int hwres = _get_hw_jpeg_resolution( p->model, megapixel );
return ipslr_handle_command_x18( p, true, X18_JPEG_RESOLUTION, 2, 1, hwres, 0);
}
int pslr_set_jpeg_image_tone(pslr_handle_t h, pslr_jpeg_image_tone_t image_tone) {
DPRINT("[C]\tpslr_set_jpeg_image_tone(%X)\n", image_tone);
ipslr_handle_t *p = (ipslr_handle_t *) h;
if (image_tone < 0 || image_tone > PSLR_JPEG_IMAGE_TONE_MAX) {
return PSLR_PARAM;
}
return ipslr_handle_command_x18( p, true, X18_JPEG_IMAGE_TONE, 1, image_tone, 0, 0);
}
int pslr_set_jpeg_sharpness(pslr_handle_t h, int32_t sharpness) {
DPRINT("[C]\tpslr_set_jpeg_sharpness(%X)\n", sharpness);
ipslr_handle_t *p = (ipslr_handle_t *) h;
int hw_sharpness = sharpness + (pslr_get_model_jpeg_property_levels( h )-1) / 2;
if (hw_sharpness < 0 || hw_sharpness >= p->model->jpeg_property_levels) {
return PSLR_PARAM;
}
return ipslr_handle_command_x18( p, false, X18_JPEG_SHARPNESS, 2, 0, hw_sharpness, 0);
}
int pslr_set_jpeg_contrast(pslr_handle_t h, int32_t contrast) {
DPRINT("[C]\tpslr_set_jpeg_contrast(%X)\n", contrast);
ipslr_handle_t *p = (ipslr_handle_t *) h;
int hw_contrast = contrast + (pslr_get_model_jpeg_property_levels( h )-1) / 2;
if (hw_contrast < 0 || hw_contrast >= p->model->jpeg_property_levels) {
return PSLR_PARAM;
}
return ipslr_handle_command_x18( p, false, X18_JPEG_CONTRAST, 2, 0, hw_contrast, 0);
}
int pslr_set_jpeg_hue(pslr_handle_t h, int32_t hue) {
DPRINT("[C]\tpslr_set_jpeg_hue(%X)\n", hue);
ipslr_handle_t *p = (ipslr_handle_t *) h;
int hw_hue = hue + (pslr_get_model_jpeg_property_levels( h )-1) / 2;
DPRINT("hw_hue: %d\n", hw_hue);
if (hw_hue < 0 || hw_hue >= p->model->jpeg_property_levels) {
return PSLR_PARAM;
}
DPRINT("before return\n");
return ipslr_handle_command_x18( p, false, X18_JPEG_HUE, 2, 0, hw_hue, 0);
}
int pslr_set_jpeg_saturation(pslr_handle_t h, int32_t saturation) {
DPRINT("[C]\tpslr_set_jpeg_saturation(%X)\n", saturation);
ipslr_handle_t *p = (ipslr_handle_t *) h;
int hw_saturation = saturation + (pslr_get_model_jpeg_property_levels( h )-1) / 2;
if (hw_saturation < 0 || hw_saturation >= p->model->jpeg_property_levels) {
return PSLR_PARAM;
}
return ipslr_handle_command_x18( p, false, X18_JPEG_SATURATION, 2, 0, hw_saturation, 0);
}
int pslr_set_image_format(pslr_handle_t h, pslr_image_format_t format) {
DPRINT("[C]\tpslr_set_image_format(%X)\n", format);
ipslr_handle_t *p = (ipslr_handle_t *) h;
if (format >= PSLR_IMAGE_FORMAT_MAX) {
return PSLR_PARAM;
}
return ipslr_handle_command_x18( p, true, X18_IMAGE_FORMAT, 2, 1, format, 0);
}
int pslr_set_raw_format(pslr_handle_t h, pslr_raw_format_t format) {
DPRINT("[C]\tpslr_set_raw_format(%X)\n", format);
ipslr_handle_t *p = (ipslr_handle_t *) h;
if (format >= PSLR_RAW_FORMAT_MAX) {
return PSLR_PARAM;
}
return ipslr_handle_command_x18( p, true, X18_RAW_FORMAT, 2, 1, format, 0);
}
int pslr_set_color_space(pslr_handle_t h, pslr_color_space_t color_space) {
DPRINT("[C]\tpslr_set_raw_format(%X)\n", color_space);
ipslr_handle_t *p = (ipslr_handle_t *) h;
if (color_space >= PSLR_COLOR_SPACE_MAX) {
return PSLR_PARAM;
}
return ipslr_handle_command_x18( p, true, X18_COLOR_SPACE, 1, color_space, 0, 0);
}
int pslr_delete_buffer(pslr_handle_t h, int bufno) {
DPRINT("[C]\tpslr_delete_buffer(%X)\n", bufno);
ipslr_handle_t *p = (ipslr_handle_t *) h;
if (bufno < 0 || bufno > 9) {
return PSLR_PARAM;
}
CHECK(ipslr_write_args(p, 1, bufno));
CHECK(command(p->fd, 0x02, 0x03, 0x04));
CHECK(get_status(p->fd));
return PSLR_OK;
}
int pslr_green_button(pslr_handle_t h) {
DPRINT("[C]\tpslr_green_button()\n");
ipslr_handle_t *p = (ipslr_handle_t *) h;
CHECK(command(p->fd, 0x10, X10_GREEN, 0x00));
CHECK(get_status(p->fd));
return PSLR_OK;
}
int pslr_dust_removal(pslr_handle_t h) {
DPRINT("[C]\tpslr_dust_removal()\n");
ipslr_handle_t *p = (ipslr_handle_t *) h;
CHECK(command(p->fd, 0x10, X10_DUST, 0x00));
CHECK(get_status(p->fd));
return PSLR_OK;
}
int pslr_bulb(pslr_handle_t h, bool on ) {
DPRINT("[C]\tpslr_bulb(%d)\n", on);
ipslr_handle_t *p = (ipslr_handle_t *) h;
CHECK(ipslr_write_args(p, 1, on ? 1 : 0));
CHECK(command(p->fd, 0x10, X10_BULB, 0x04));
CHECK(get_status(p->fd));
return PSLR_OK;
}
int pslr_button_test(pslr_handle_t h, int bno, int arg) {
DPRINT("[C]\tpslr_button_test(%X, %X)\n", bno, arg);
int r;
ipslr_handle_t *p = (ipslr_handle_t *) h;
CHECK(ipslr_write_args(p, 1, arg));
CHECK(command(p->fd, 0x10, bno, 4));
r = get_status(p->fd);
DPRINT("\tbutton result code: 0x%x\n", r);
return PSLR_OK;
}
int pslr_ae_lock(pslr_handle_t h, bool lock) {
DPRINT("[C]\tpslr_ae_lock(%X)\n", lock);
ipslr_handle_t *p = (ipslr_handle_t *) h;
if (lock) {
CHECK(command(p->fd, 0x10, X10_AE_LOCK, 0x00));
} else {
CHECK(command(p->fd, 0x10, X10_AE_UNLOCK, 0x00));
}
CHECK(get_status(p->fd));
return PSLR_OK;
}
int pslr_set_exposure_mode(pslr_handle_t h, pslr_exposure_mode_t mode) {
DPRINT("[C]\tpslr_set_exposure_mode(%X)\n", mode);
ipslr_handle_t *p = (ipslr_handle_t *) h;
if (mode >= PSLR_EXPOSURE_MODE_MAX) {
return PSLR_PARAM;
}
if ( p->model->need_exposure_mode_conversion ) {
mode = exposure_mode_conversion( mode );
}
return ipslr_handle_command_x18( p, true, X18_EXPOSURE_MODE, 2, 1, mode, 0);
}
int pslr_buffer_open(pslr_handle_t h, int bufno, pslr_buffer_type buftype, int bufres) {
DPRINT("[C]\tpslr_buffer_open(#%X, type=%X, res=%X)\n", bufno, buftype, bufres);
pslr_buffer_segment_info info;
uint16_t bufs;
uint32_t buf_total = 0;
int i, j;
int ret;
int retry = 0;
int retry2 = 0;