-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcammonitor.cpp
More file actions
3270 lines (2988 loc) · 92.7 KB
/
cammonitor.cpp
File metadata and controls
3270 lines (2988 loc) · 92.7 KB
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
/***********************************************************************
Copyright (c) Industrial Research Limited $Date: 2011/04/12 22:13:21 $
This file is part of Camwire, a generic camera interface.
Camwire 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.1 of the
License, or (at your option) any later version.
Camwire 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 Camwire; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
Title: Camera monitor
Description:
Provides basic access to digital camera functions via a simple
terminal and display interface. Uses the Camwire API.
To do:
Re-design the whole thing. It grew organically as Camwire was
developed and is a real mess.
***********************************************************************/
#include "cammonitor.h"
using namespace std;
/*
----------------------------------------------------------------------
Initializes the camera bus, gets the user to select a camera if there
is more than one, initializes it, and sets up the display interface.
Then enters an endless loop which displays images and reponds to user
commands.
*/
/* Almost every camera function call returns a success/failure flag
which should be checked, resulting in quite messy-looking code. To
keep things clean and simple, almost all errors therefore result in a
call to errorexit() which prints a message, cleans up allocated
memory, and exits with an error status. */
/*
----------------------------------------------------------------------
Returns the camera to work with, which is the camera number with
matching chip identifier string. Displays the camera's identifier
data and creates it as well.
*/
int camera::get_named_cam(const Camwire_handle *handle_array,
const int num_cameras,
const char *chip_id_string)
{
int c, current_cam;
Camwire_id camid;
current_cam = -1;;
for (c = 0; c < num_cameras; ++c)
{
if (camwire_get_identifier(handle_array[c], &camid) !=
CAMWIRE_SUCCESS)
{
errorexit(NULL, c, "Could not get the identifier.");
}
if (strncmp(camid.chip, chip_id_string, CAMWIRE_ID_MAX_CHARS) ==
0)
{
current_cam = c;
break;
}
}
if (current_cam < 0)
{
printf("Could not find camera with ID %s.\n", chip_id_string);
fflush(stdout);
errorexit(NULL, current_cam,
"Try running without specifying an ID.");
}
printf("Vendor name: %s\n", camid.vendor);
printf("Model name: %s\n", camid.model);
printf("Vendor & chip ID: %s\n", camid.chip);
fflush(stdout);
return(current_cam);
}
/*
----------------------------------------------------------------------
Reads the camera's parameters and default values into the settings
structure.
*/
void camera::get_camera_settings(const Camwire_handle c_handle,
Settings_t *set)
{
int settingsval;
camwire_get_stateshadow(c_handle, &set->shadowlevel);
camwire_get_run_stop(c_handle, &settingsval);
if (settingsval) set->activity = set->running;
else set->activity = set->stopped;
camwire_get_single_shot(c_handle, &settingsval);
if (settingsval) set->acqtype = set->single;
else set->acqtype = set->continuous;
camwire_get_colour_coefficients(c_handle, set->colour_coef);
camwire_get_colour_correction(c_handle, (int *)&set->colour_corr);
camwire_get_gamma(c_handle, &settingsval);
if (settingsval) set->gamma = set->gamma_on;
else set->gamma = set->gamma_off;
camwire_get_white_balance(c_handle, set->white_bal);
camwire_get_brightness(c_handle, &set->brightness);
camwire_get_gain(c_handle, &set->gain);
camwire_get_trigger_source(c_handle, &settingsval);
if (settingsval) set->trigger = set->external;
else set->trigger = set->internal;
camwire_get_trigger_polarity(c_handle, &settingsval);
if (settingsval) set->polarity = set->rising;
else set->polarity = set->falling;
camwire_get_shutter(c_handle, &set->shutter);
camwire_get_framerate(c_handle, &set->framerate);
camwire_get_frame_size(c_handle, &set->width, &set->height);
camwire_get_pixel_coding(c_handle, &set->coding);
camwire_get_pixel_tiling(c_handle, &set->tiling);
camwire_get_frame_offset(c_handle, &set->left, &set->top);
camwire_get_num_framebuffers(c_handle, &set->num_buffers);
camwire_get_framenumber(c_handle, &set->framenumber);
}
/*
----------------------------------------------------------------------
Sets default values to the non-camera paramenters in the settings
structure.
*/
void camera::default_noncamera_settings(Settings_t *set)
{
set->maxval = 0; /* 0 means uninitialized.*/
change_response_curve(set, set->unchanged);
set->save_delay = DEFAULT_SAVE_DELAY;
set->save_num_images = DEFAULT_SAVE_NUM_IMAGES;
strncpy(set->imagefilename, DEFAULT_IMAGE_FILENAME, MAX_FILENAME);
set->imagefilename[MAX_FILENAME] = '\0';
}
/*
----------------------------------------------------------------------
Set the response_curve member of the given settings to newvalue, while
maintaining the allocated linbuffer for linearized images. Assumes
currently valid values in set->coding, set->width and set->height.
*/
void camera::change_response_curve(Settings_t *set, int newvalue)
{
int depth;
if (linbuffer == NULL && newvalue == set->linearized)
{
camwire_pixel_depth(set->coding, &depth);
if (depth != 8 && depth != 24)
{
fprintf(stderr, "Only 8-bit pixel components can be linearized.\n"
"Did not change the response curve.\n");
return;
}
linbuffer = malloc((size_t)set->width*set->height*depth/4);
/* Divide by 4, not 8, for a buffer twice the size.*/
if (linbuffer == NULL)
{
fprintf(stderr, "Could not allocate linear image buffer.\n"
"Did not change the response curve.\n");
return;
}
}
if (linbuffer != NULL && newvalue != set->linearized)
{
free(linbuffer);
linbuffer = NULL;
}
if (newvalue==0){
set->response_curve = set->unchanged;//newvalue;
}else if(newvalue==1)
{
set->response_curve = set->linearized;//newvalue;
}
}
/*
----------------------------------------------------------------------
Prints the menu of available commands as well as the current
settings.
*/
void camera::show_menu(const Settings_t *set)
{
char *c1, *c2, *c3, *c4;
char leftcurr[] = "[", rightcurr[] = "]", nothing[] = "";
unsigned long maxval;
char namebuffer[MAX_FILENAME+1];
printf("\nCommands: "
"[H]otkey "
"%spossible_settings%s %scurrent_setting%s\n",
nothing, nothing, leftcurr, rightcurr);
/* Activity:*/
if (set->activity == set->stopped)
{
c1 = leftcurr; c2 = rightcurr;
c3 = nothing; c4 = nothing;
}
else
{
c1 = nothing; c2 = nothing;
c3 = leftcurr; c4 = rightcurr;
}
printf("[R]un/stop camera %sstopped%s %srunning%s\n",
c1, c2, c3, c4);
/* Acquisition type:*/
if (set->acqtype == set->continuous)
{
c1 = leftcurr; c2 = rightcurr; c3 = nothing; c4 = nothing;
}
else
{
c1 = nothing; c2 = nothing; c3 = leftcurr; c4 = rightcurr;
}
printf("[A]quisition "
"%scontinuous%s %ssingle-shot%s\n",
c1, c2, c3, c4);
/* Trigger:*/
if (set->trigger == set->internal)
{
c1 = leftcurr; c2 = rightcurr; c3 = nothing; c4 = nothing;
}
else
{
c1 = nothing; c2 = nothing; c3 = leftcurr; c4 = rightcurr;
}
printf("[T]rigger source %sinternal%s %sexternal%s\n",
c1, c2, c3, c4);
/* Polarity:*/
if (set->polarity == set->falling)
{
c1 = leftcurr; c2 = rightcurr; c3 = nothing; c4 = nothing;
}
else
{
c1 = nothing; c2 = nothing; c3 = leftcurr; c4 = rightcurr;
}
printf("trigger [P]olarity %sfalling%s %srising%s\n",
c1, c2, c3, c4);
/* Integration time:*/
printf("[I]ntegration time %s%g s%s\n",
leftcurr, set->shutter, rightcurr);
/* Frame rate:*/
printf("[F]rame rate %s%g fps%s\n",
leftcurr, set->framerate, rightcurr);
/* Image size:*/
printf("frame si[Z]e "
" %sw %d pixels%s %sh %d pixels%s\n",
leftcurr, set->width, rightcurr,
leftcurr, set->height, rightcurr);
/* Pixel Coding:*/
printf("pixel [C]oding "
" %s%s%s\n",
leftcurr, pixelcoding2string(set->coding), rightcurr);
/* Pixel Maxval:*/
maxval = set->maxval;
if (set->maxval == 0)
{
maxval = (1 << component_depth(set->coding)) - 1;
}
printf("[9] pixel maxval "
" %s%lu%s\n",
leftcurr, maxval, rightcurr);
/* Pixel Tiling:*/
printf("pixel tilin[G] "
" %s%s%s\n",
leftcurr, pixeltiling2string(set->tiling), rightcurr);
/* Image offset:*/
printf("frame [O]ffset "
" %sleft %d pixels%s %stop %d pixels%s\n",
leftcurr, set->left, rightcurr,
leftcurr, set->top, rightcurr);
/* Gain:*/
printf("[U] gain [0, 1] %s%g%s\n",
leftcurr, set->gain, rightcurr);
/* Brightness:*/
printf("[V] brightness [-1, +1] %s%g%s\n",
leftcurr, set->brightness, rightcurr);
/* White balance:*/
printf("[W]hite balance [0, 1] %sblue %g%s %sred %g%s\n",
leftcurr, set->white_bal[0], rightcurr,
leftcurr, set->white_bal[1], rightcurr);
/* Gamma:*/
if (set->gamma == set->gamma_off)
{
c1 = leftcurr; c2 = rightcurr; c3 = nothing; c4 = nothing;
}
else
{
c1 = nothing; c2 = nothing; c3 = leftcurr; c4 = rightcurr;
}
printf("[Y] gamma "
"%soff%s %son%s\n",
c1, c2, c3, c4);
/* Response curve:*/
if (set->response_curve == set->unchanged)
{
c1 = leftcurr; c2 = rightcurr; c3 = nothing; c4 = nothing;
}
else
{
c1 = nothing; c2 = nothing; c3 = leftcurr; c4 = rightcurr;
}
printf("[X] response curve "
"%sunchanged%s %slinearized%s\n",
c1, c2, c3, c4);
/* Colour correction:*/
if (set->colour_corr == set->colour_corr_off)
{
c1 = leftcurr; c2 = rightcurr; c3 = nothing; c4 = nothing;
}
else
{
c1 = nothing; c2 = nothing; c3 = leftcurr; c4 = rightcurr;
}
printf("[J] colour correction %soff%s %son%s\n", c1, c2, c3, c4);
/* Colour coefficients:*/
printf("[K] colour coefficients [%g %g %g]\n",
set->colour_coef[0], set->colour_coef[1], set->colour_coef[2]);
printf(" [%g %g %g]\n",
set->colour_coef[3], set->colour_coef[4], set->colour_coef[5]);
printf(" [%g %g %g]\n",
set->colour_coef[6], set->colour_coef[7], set->colour_coef[8]);
/* Frame Buffers:*/
printf("frame [B]uffers %s%d%s\n",
leftcurr, set->num_buffers, rightcurr);
/* Shadow camera:*/
if (!set->shadowlevel)
{
c1 = leftcurr; c2 = rightcurr; c3 = nothing; c4 = nothing;
}
else
{
c1 = nothing; c2 = nothing; c3 = leftcurr; c4 = rightcurr;
}
printf("sha[D]ow camera %soff%s %son%s\n",
c1, c2, c3, c4);
/* Image filename:*/
filename_framenumber(namebuffer, set->imagefilename, 0,
set->framenumber + 1);
printf("file[N]ame for save %s%s%s\n",
leftcurr, namebuffer, rightcurr);
/* Delay before saving:*/
printf("de[L]ay before saving %s%g s%s\n",
leftcurr, set->save_delay, rightcurr);
/* Number of images to save:*/
printf("[M]ultiple images to save %s%d%s\n",
leftcurr, set->save_num_images, rightcurr);
/* Save image:*/
if (set->save_num_images == 1)
{
printf("[S]ave image to file\n");
}
else if (set->save_num_images > 1)
{
printf("[S]ave images to files\n");
}
/* else do not print save item.*/
/* Settings save or load:*/
printf("s[E]ttings save or load\n");
/* Show Camwire data:*/
printf("s[H]ow camwire data\n");
/* Quit:*/
printf("[Q]uit camera monitor\n");
fflush(stdout);
}
/*
----------------------------------------------------------------------
Prints the command line prompt.
*/
void camera::show_prompt(void)
{
printf(COMMAND_PROMPT);
fflush(stdout);
}
/*
----------------------------------------------------------------------
Does something in response to the user input.
*/
int camera::user_input(const Camwire_handle c_handle, const int key,
Settings_t *set)
{
int continue_flag;
int oldwidth, oldheight;
Camwire_pixel oldcoding;
unsigned long oldmaxval;
continue_flag = 1;
switch(tolower(key))
{
case 'r': /* Run-stop toggle:*/
if(set_run_stop(c_handle))
set->activity = set->running;
else
set->activity = set->stopped;
break;
case 'a': /* Acquisition type toggle:*/
if(set_acq_type(c_handle))
set->acqtype = set->single;
else
set->acqtype = set->continuous;
break;
case 't': /* Trigger source toggle:*/
if(set_external_trigger(c_handle))
set->trigger = set->external;
else
set->trigger = set->internal;
break;
case 'p': /* Trigger polarity toggle:*/
if(set_trigger_polarity(c_handle))
set->polarity = set->rising;
else
set->polarity = set->falling;
break;
case 'i': /* Integration time:*/
set->shutter = set_shutter(c_handle);
break;
case 'f': /* Frame rate:*/
set->framerate = set_framerate(c_handle);
break;
case 'z': /* Frame siZe:*/
oldwidth = set->width;
oldheight = set->height;
set_framesize(c_handle, &set->width, &set->height);
if (display_initialized)
{
if (display_resize(d_handle, set->width, set->height) !=
DISPLAY_SUCCESS)
{ /* Can't display it for some reason.*/
set->width = oldwidth;
set->height = oldheight;
camwire_set_frame_size(c_handle, set->width,
set->height);
}
}
break;
case 'c': /* Pixel Coding:*/
oldcoding = set->coding;
set_pixel_coding(c_handle, &set->coding);
if (display_initialized)
{
if (display_coding(d_handle, set->coding) !=
DISPLAY_SUCCESS)
{ /* Can't display it.*/
fprintf(stderr, "Cannot display this pixel coding.\n");
set->coding = oldcoding;
camwire_set_pixel_coding(c_handle, set->coding);
}
}
break;
case '9': /* Pixel maxval:*/
oldmaxval = set->maxval;
set_pixel_maxval(&set->maxval);
if (display_initialized)
{
if (display_maxval(d_handle, set->maxval) != DISPLAY_SUCCESS)
{
fprintf(stderr, "Could not set pixel maxval %lu in display.\n",
set->maxval);
set->maxval = oldmaxval;
}
}
break;
case 'g': /* Pixel Tiling:*/
set_pixel_tiling(c_handle, &set->tiling);
break;
case 'o': /* Frame Offset:*/
set_offset(c_handle, &set->left, &set->top);
break;
case 'u': /* Gain:*/
set_gain(c_handle, &set->gain);
break;
case 'v': /* Brightness:*/
set_brightness(c_handle, &set->brightness);
break;
case 'w': /* White balance:*/
set_white_bal(c_handle, set->white_bal);
break;
case 'y': /* Gamma:*/
if (set_gamma(c_handle))
set->gamma = set->gamma_on;
else
set->gamma = set->gamma_off;
break;
case 'x': /* Response curve:*/
change_response_curve(set, set_response_curve(c_handle));
break;
case 'j': /* Colour correction:*/
if(set_colour_corr(c_handle))
set->colour_corr = set->colour_corr_on;
else
set->colour_corr = set->colour_corr_off;
break;
case 'k': /* Colour coefficients:*/
set_colour_coef(c_handle, set->colour_coef);
break;
case 'b': /* Frame Buffers:*/
set_buffers(c_handle, &set->num_buffers);
break;
case 'd': /* ShaDow camera:*/
set->shadowlevel = set_shadow(c_handle);
break;
case 'n': /* Change image filename:*/
set_image_filename(set);
break;
case 'l': /* Delay before saving:*/
set_save_delay(set);
break;
case 'm': /* Number of images to save:*/
set_save_num_images(set);
break;
case 's': /* Save images to file:*/
continue_flag = save_images(c_handle, set);
break;
case 'e':
settings_save_load(c_handle, set);
break;
case 'h':
show_camwire_data(c_handle);
break;
case 'q': /* Quit:*/
continue_flag = 0;
break;
default:
break;
} /*switch*/
return(continue_flag);
}
/*
----------------------------------------------------------------------
Returns the camera shadow flag obtained from the user, after setting
the camera accordingly.
*/
int camera::set_shadow(const Camwire_handle c_handle)
{
int shadowlevel;
shadowlevel =
get_user_char_setting(c_handle, camwire_get_stateshadow, "oFf/oN", 'n', 'f');
if (shadowlevel)
{
if (camwire_set_stateshadow(c_handle, 1) != CAMWIRE_SUCCESS)
{
fprintf(stderr,
"Could not set camera state shadow flag.\n");
}
}
else
{
if (camwire_set_stateshadow(c_handle, 0) != CAMWIRE_SUCCESS)
{
fprintf(stderr,
"Could not unset camera state shadow flag.\n");
}
}
if (camwire_get_stateshadow(c_handle, &shadowlevel) != CAMWIRE_SUCCESS)
fprintf(stderr, "Could not get camera shadow status.\n");
return(shadowlevel);
}
/*
----------------------------------------------------------------------
Returns the activity status obtained from the user, after setting the
camera accordingly.
*/
int camera::set_run_stop(const Camwire_handle c_handle)
{
int run;
int num_buffers;
// run = get_user_char_setting(c_handle, camwire_get_run_stop,
// "Run/Stop camera", 'r', 's');
run =1;
if (run)
{
if (camwire_set_run_stop(c_handle, 1) != CAMWIRE_SUCCESS)
{
fprintf(stderr, "Could not set camera to running.\n");
}
}
else
{
if (camwire_set_run_stop(c_handle, 0) != CAMWIRE_SUCCESS)
{
fprintf(stderr, "Could not set camera to stopped.\n");
}
//wait_frametime(c_handle, SAFE_FRAME_PERIOD);
camwire_get_num_framebuffers(c_handle, &num_buffers);
camwire_flush_framebuffers(c_handle, num_buffers, NULL, NULL);
}
/* Note that we do not bother to check the camera run/stop status
again here because it auto-clears when single-shot is set:*/
if (run) return(1);
else return(0);
}
/*
----------------------------------------------------------------------
Returns true if the camera was set to stop, based on set_run_stop function.
*/
int camera::set_stop(const Camwire_handle c_handle)
{
int run;
int num_buffers;
// run = get_user_char_setting(c_handle, camwire_get_run_stop,
// "Run/Stop camera", 'r', 's');
run =0;
if (run)
{
if (camwire_set_run_stop(c_handle, 1) != CAMWIRE_SUCCESS)
{
fprintf(stderr, "Could not set camera to running.\n");
}
}
else
{
if (camwire_set_run_stop(c_handle, 0) != CAMWIRE_SUCCESS)
{
fprintf(stderr, "Could not set camera to stopped.\n");
}
//wait_frametime(c_handle, SAFE_FRAME_PERIOD);
camwire_get_num_framebuffers(c_handle, &num_buffers);
camwire_flush_framebuffers(c_handle, num_buffers, NULL, NULL);
camwire_destroy(c_handle);
}
/* Note that we do not bother to check the camera run/stop status
again here because it auto-clears when single-shot is set:*/
if (!run) return(1);
else return(0);
}
/*
----------------------------------------------------------------------
Returns the acquisition type obtained from the user, after setting
the camera accordingly.
*/
int camera::set_acq_type(const Camwire_handle c_handle)
{
int singleshot;
int num_buffers;
singleshot =
get_user_char_setting(c_handle, camwire_get_single_shot,
"Continuous/Single-shot acquisition",
's', 'c');
if (singleshot)
{
camwire_get_num_framebuffers(c_handle, &num_buffers);
camwire_flush_framebuffers(c_handle, num_buffers, NULL, NULL);
if (camwire_set_single_shot(c_handle, 1) != CAMWIRE_SUCCESS)
{
fprintf(stderr,
"Could not set camera to single-shot acquisition.\n");
}
}
else
{
if (camwire_set_single_shot(c_handle, 0) != CAMWIRE_SUCCESS)
{
fprintf(stderr,
"Could not set camera to continuous acquisition.\n");
}
}
if (camwire_get_single_shot(c_handle, &singleshot) !=
CAMWIRE_SUCCESS)
{
fprintf(stderr, "Could not get single-shot status.\n");
}
if (singleshot) return(1);//single
else return(0);//continuos
}
/*
----------------------------------------------------------------------
Returns the acquisition type obtained from the user, after setting
the camera accordingly.
*/
int camera::set_acq_type_jaymi(const Camwire_handle c_handle)
{
int singleshot;
int num_buffers;
singleshot =1;
if (singleshot)
{
camwire_get_num_framebuffers(c_handle, &num_buffers);
camwire_flush_framebuffers(c_handle, num_buffers, NULL, NULL);
if (camwire_set_single_shot(c_handle, 1) != CAMWIRE_SUCCESS)
{
fprintf(stderr,
"Could not set camera to single-shot acquisition.\n");
}
}
else
{
if (camwire_set_single_shot(c_handle, 0) != CAMWIRE_SUCCESS)
{
fprintf(stderr,
"Could not set camera to continuous acquisition.\n");
}
}
if (camwire_get_single_shot(c_handle, &singleshot) !=
CAMWIRE_SUCCESS)
{
fprintf(stderr, "Could not get single-shot status.\n");
}
if (singleshot) return(1);//single
else return(0);//continuos
}
/*
----------------------------------------------------------------------
Returns a shutter speed (exposure time) obtained from the user, after
setting the camera accordingly.
*/
double camera::set_shutter(const Camwire_handle c_handle)
{
int gotinput;
double shutter;
gotinput = 0;
putchar('\n');
while (!gotinput)
{
printf("Integration time (seconds): ");
fflush(stdout);
if (scanf("%lf", &shutter) == 1)
{
gotinput = 1;
}
else
{
fprintf(stderr, "Invalid floating point number.\n");
clear_stdin();
}
}
if (camwire_set_shutter(c_handle, shutter) != CAMWIRE_SUCCESS)
fprintf(stderr, "Could not set the camera shutter.\n");
if (camwire_get_shutter(c_handle, &shutter) != CAMWIRE_SUCCESS)
fprintf(stderr, "Could not confirm the camera shutter.\n");
return(shutter);
}
/*
----------------------------------------------------------------------
Returns the trigger source obtained from the user, after setting the
camera accordingly.
*/
int camera::set_external_trigger(const Camwire_handle c_handle)
{
int exttrig;
exttrig = get_user_char_setting(c_handle,
camwire_get_trigger_source,
"Internal/External trigger",
'e', 'i');
if (exttrig)
{
if (camwire_set_trigger_source(c_handle, 1) != CAMWIRE_SUCCESS)
{
fprintf(stderr,
"Could not set trigger source to external.\n");
}
}
else
{
if (camwire_set_trigger_source(c_handle, 0) != CAMWIRE_SUCCESS)
{
fprintf(stderr,
"Could not set trigger source to internal.\n");
}
}
if (camwire_get_trigger_source(c_handle, &exttrig) !=
CAMWIRE_SUCCESS)
{
fprintf(stderr, "Could not get trigger source.\n");
}
if (exttrig) return(1);//external
else return(0);//internal
}
/*
----------------------------------------------------------------------
Returns the trigger polarity obtained from the user, after setting
the camera accordingly.
*/
int camera::set_trigger_polarity(const Camwire_handle c_handle)
{
int risingpol;
risingpol =
get_user_char_setting(c_handle, camwire_get_trigger_polarity,
"Rising/Falling trigger polarity",
'r', 'f');
if (risingpol)
{
if (camwire_set_trigger_polarity(c_handle, 1) !=
CAMWIRE_SUCCESS)
{
fprintf(stderr,
"Could not set trigger polarity to rising edge.\n");
}
}
else
{
if (camwire_set_trigger_polarity(c_handle, 0) !=
CAMWIRE_SUCCESS)
{
fprintf(stderr,
"Could not set trigger polarity to falling edge.\n");
}
}
if (camwire_get_trigger_polarity(c_handle, &risingpol) !=
CAMWIRE_SUCCESS)
{
fprintf(stderr, "Could not get trigger polarity.\n");
}
if (risingpol) return(1);//rising
else return(0);//falling
}
/*
----------------------------------------------------------------------
Returns a frame rate (frames per second) obtained from the user,
after setting the camera accordingly.
*/
double camera::set_framerate(const Camwire_handle c_handle)
{
int gotinput;
double framerate;
gotinput = 0;
putchar('\n');
while (!gotinput)
{
printf("Frame rate (frames per second): ");
fflush(stdout);
if (scanf("%lf", &framerate) == 1)
{
gotinput = 1;
}
else
{
fprintf(stderr, "Invalid floating point number.\n");
clear_stdin();
}
}
if (camwire_set_framerate(c_handle, framerate) != CAMWIRE_SUCCESS)
fprintf(stderr, "Could not set the camera framerate.\n");
if (camwire_get_framerate(c_handle, &framerate) != CAMWIRE_SUCCESS)
fprintf(stderr, "Could not confirm the camera framerate.\n");
return(framerate);
}
double camera::set_framerate_jaymi(const Camwire_handle c_handle,double framerate)
{
if (camwire_set_framerate(c_handle, framerate) != CAMWIRE_SUCCESS)
fprintf(stderr, "Could not set the camera framerate.\n");
if (camwire_get_framerate(c_handle, &framerate) != CAMWIRE_SUCCESS)
fprintf(stderr, "Could not confirm the camera framerate.\n");
return(framerate);
}
/*
----------------------------------------------------------------------
Returns the frame size obtained from the user, after setting the
camera accordingly.
*/
void camera::set_framesize(const Camwire_handle c_handle, int *width,
int *height)
{
int gotinput;
gotinput = 0;
putchar('\n');
while (!gotinput)
{
printf("Frame size (width height): ");
fflush(stdout);
if (scanf("%d %d", width, height) == 2)
{
gotinput = 1;
}
else
{
fprintf(stderr, "Invalid number.\n");
clear_stdin();
}
}
if (camwire_set_frame_size(c_handle, *width, *height) !=
CAMWIRE_SUCCESS)
fprintf(stderr, "Could not set the camera frame size.\n");
if (camwire_get_frame_size(c_handle, width, height) !=
CAMWIRE_SUCCESS)
fprintf(stderr,
"Could not confirm the camera frame size.\n");
}
/*
----------------------------------------------------------------------
Returns the pixel coding obtained from the user, after setting
the camera accordingly.
*/
void camera::set_pixel_coding(const Camwire_handle c_handle,
Camwire_pixel *coding)
{
int gotinput;
char pix_coding[MAX_PIXEL_CODING_STRING+1];
char formatstring[20];