forked from AllskyTeam/allsky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapture_RPiHQ.cpp
1333 lines (1149 loc) · 38.4 KB
/
capture_RPiHQ.cpp
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
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <sys/time.h>
//#include <time.h>
#include <unistd.h>
#include <string.h>
//#include <sys/types.h>
#include <errno.h>
#include <string>
#include <iomanip>
#include <cstring>
#include <sstream>
//include <iostream>
//#include <cstdio>
#include <tr1/memory>
//#include <ctime>
#include <stdlib.h>
#include <signal.h>
#include <fstream>
using namespace std;
#define KNRM "\x1B[0m"
#define KRED "\x1B[31m"
#define KGRN "\x1B[32m"
#define KYEL "\x1B[33m"
#define KBLU "\x1B[34m"
#define KMAG "\x1B[35m"
#define KCYN "\x1B[36m"
#define KWHT "\x1B[37m"
#define US_IN_MS 1000 // microseconds in a millisecond
#define MS_IN_SEC 1000 // milliseconds in a second
#define US_IN_SEC (US_IN_MS * MS_IN_SEC) // microseconds in a second
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
//char nameCnt[128];
char const *fileName = "image.jpg";
bool bMain = true;
//ol bDisplay = false;
std::string dayOrNight;
int numExposures = 0; // how many valid pictures have we taken so far?
// Some command-line and other option definitions needed outside of main():
int tty = 0; // 1 if we're on a tty (i.e., called from the shell prompt).
#define NOT_SET -1 // signifies something isn't set yet
#define DEFAULT_NOTIFICATIONIMAGES 1
int notificationImages = DEFAULT_NOTIFICATIONIMAGES;
//bool bSavingImg = false;
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
char debugText[500]; // buffer to hold debug messages displayed by displayDebugText()
int debugLevel = 0;
/**
* Helper function to display debug info
**/
void displayDebugText(const char * text, int requiredLevel) {
if (debugLevel >= requiredLevel) {
printf("%s", text);
}
}
// Return the numeric time.
timeval getTimeval()
{
timeval curTime;
gettimeofday(&curTime, NULL);
return(curTime);
}
// Format a numeric time as a string.
char *formatTime(timeval t, char const *tf)
{
static char TimeString[128];
strftime(TimeString, 80, tf, localtime(&t.tv_sec));
return(TimeString);
}
// Return the current time as a string. Uses both functions above.
char *getTime(char const *tf)
{
return(formatTime(getTimeval(), tf));
}
std::string ReplaceAll(std::string str, const std::string& from, const std::string& to) {
size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
}
return str;
}
std::string exec(const char *cmd)
{
std::tr1::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
if (!pipe)
return "ERROR";
char buffer[128];
std::string result = "";
while (!feof(pipe.get()))
{
if (fgets(buffer, 128, pipe.get()) != NULL)
{
result += buffer;
}
}
return result;
}
/*
void *Display(void *params)
{
cv::Mat *pImg = (cv::Mat *)params;
cvNamedWindow("video", 1);
while (bDisplay)
{
cvShowImage("video", pImg);
cvWaitKey(100);
}
cvDestroyWindow("video");
printf("Display thread over\n");
return (void *)0;
}
*/
// Exit the program gracefully.
void closeUp(int e)
{
static int closingUp = 0; // indicates if we're in the process of exiting.
// For whatever reason, we're sometimes called twice, but we should only execute once.
if (closingUp) return;
closingUp = 1;
// If we're not on a tty assume we were started by the service.
// Unfortunately we don't know if the service is stopping us, or restarting us.
// If it was restarting there'd be no reason to copy a notification image since it
// will soon be overwritten. Since we don't know, always copy it.
if (notificationImages) {
system("scripts/copy_notification_image.sh NotRunning &");
// Sleep to give it a chance to print any messages so they (hopefully) get printed
// before the one below. This is only so it looks nicer in the log file.
sleep(3);
}
printf(" ***** Stopping AllSky *****\n");
exit(e);
}
void IntHandle(int i)
{
bMain = false;
closeUp(0);
}
// A user error was found. Wait for the user to fix it.
void waitToFix(char const *msg)
{
printf("**********\n");
printf(msg);
printf("\n");
printf("*** After fixing, ");
if (tty)
printf("restart allsky.sh.\n");
else
printf("restart the allsky service.\n");
if (notificationImages)
system("scripts/copy_notification_image.sh Error &");
sleep(5); // give time for image to be copied
printf("*** Sleeping until you fix the problem.\n");
printf("**********\n");
sleep(100000); // basically, sleep forever until the user fixes this.
}
// Calculate if it is day or night
void calculateDayOrNight(const char *latitude, const char *longitude, const char *angle)
{
char sunwaitCommand[128];
// Log data. Don't need "exit" or "set".
sprintf(sunwaitCommand, "sunwait poll angle %s %s %s", angle, latitude, longitude);
// Inform user
sprintf(debugText, "Determine if it is day or night using variables: desired sun declination angle: %s degrees, latitude: %s, longitude: %s\n", angle, latitude, longitude);
displayDebugText(debugText, 1);
// Determine if it is day or night
dayOrNight = exec(sunwaitCommand);
// RMu, I have no clue what this does...
dayOrNight.erase(std::remove(dayOrNight.begin(), dayOrNight.end(), '\n'), dayOrNight.end());
if (dayOrNight != "DAY" && dayOrNight != "NIGHT")
{
sprintf(debugText, "*** ERROR: dayOrNight isn't DAY or NIGHT, it's '%s'\n", dayOrNight.c_str());
waitToFix(debugText);
closeUp(2);
}
}
// Calculate how long until nighttime.
int calculateTimeToNightTime(const char *latitude, const char *longitude, const char *angle)
{
std::string t;
char sunwaitCommand[128]; // returns "hh:mm, hh:mm" (sunrise, sunset)
sprintf(sunwaitCommand, "sunwait list angle %s %s %s | awk '{print $2}'", angle, latitude, longitude);
t = exec(sunwaitCommand);
t.erase(std::remove(t.begin(), t.end(), '\n'), t.end());
int h=0, m=0, secs;
sscanf(t.c_str(), "%d:%d", &h, &m);
secs = (h*60*60) + (m*60);
char *now = getTime("%H:%M");
int hNow=0, mNow=0, secsNow;
sscanf(now, "%d:%d", &hNow, &mNow);
secsNow = (hNow*60*60) + (mNow*60);
// Handle the (probably rare) case where nighttime is tomorrow
if (secsNow > secs)
{
return(secs + (60*60*24) - secsNow);
}
else
{
return(secs - secsNow);
}
}
// write value to log file
void writeToLog(int val)
{
std::ofstream outfile;
// Append value to the logfile
outfile.open("log.txt", std::ios_base::app);
outfile << val;
outfile << "\n";
}
// Build capture command to capture the image from the HQ camera
void RPiHQcapture(int asiAutoFocus, int asiAutoExposure, int asiExposure, int asiAutoGain, int asiAutoAWB, double asiGain, int bin, double asiWBR, double asiWBB, int asiRotation, int asiFlip, int asiGamma, int asiBrightness, int quality, const char* fileName, int time, int showDetails, const char* ImgText, int fontsize, int fontcolor, int background, int darkframe)
{
sprintf(debugText, "capturing image in file %s\n", fileName);
displayDebugText(debugText, 3);
// Ensure no rraspistill process is still running
string kill = "ps -ef|grep raspistill| grep -v color|awk '{print $2}'|xargs kill -9 1> /dev/null 2>&1";
// Define char variable
char kcmd[kill.length() + 1];
// Convert command to character variable
strcpy(kcmd, kill.c_str());
sprintf(debugText, "Command: %s\n", kcmd);
displayDebugText(debugText, 3);
// Execute raspistill command
system(kcmd);
stringstream ss;
/*
static char time_buffer[40];
const struct std::tm *tm_ptr;
std::time_t now;
now = std::
time ( NULL );
tm_ptr = std::localtime ( &now );
std::strftime ( time_buffer, 40, "%d %B %Y %I:%M:%S %p", tm_ptr );
*/
ss << fileName;
// Define strings for raspistill command string and
string command = "nice raspistill --nopreview --thumb none --output " + ss.str() + " --burst -st ";
// Define strings for roi (used for binning) string
string roi;
if (bin > 3)
{
bin = 3;
}
if (bin < 1)
{
bin = 1;
}
// Check for binning 1x1 is selected
if (bin==1)
{
// Select binning 1x1 (4060 x 3056 pixels)
roi = "--mode 3 ";
}
// Check if binning 2x2 is selected
else if (bin==2)
{
// Select binning 2x2 (2028 x 1520 pixels)
roi = "--mode 2 --width 2028 --height 1520 ";
}
// Check if binning 3x3 is selected
else
{
// Select binning 4x4 (1012 x 760 pixels)
roi = "--mode 4 --width 1012 --height 760 ";
}
// Append binning window
command += roi;
if (asiExposure < 1)
{
asiExposure = 1;
}
if (asiExposure > 240000000)
{
asiExposure = 240000000;
}
// Exposure time
string shutter;
// Check if automatic determined exposure time is selected
if (asiAutoExposure)
{
shutter = "--exposure auto ";
}
// Set exposure time
else if (asiExposure)
{
ss.str("");
ss << asiExposure;
shutter = "--exposure off --shutter " + ss.str() + " ";
}
// Add exposure time setting to raspistill command string
command += shutter;
if (asiAutoFocus)
{
command += "--focus ";
}
// Anolog Gain
string gain;
// Check if auto gain is selected
if (asiAutoGain)
{
// Set analog gain to 1
gain = "--analoggain 1 ";
}
// Set manual analog gain setting
else if (asiGain) {
if (asiGain < 1)
{
asiGain = 1;
}
if (asiGain > 16)
{
asiGain = 16;
}
ss.str("");
ss << asiGain;
gain = "--analoggain " + ss.str() + " ";
}
// Add gain setting to raspistill command string
command += gain;
// White balance
string awb;
// Check if R and B component are given
if (!asiAutoAWB) {
if (asiWBR < 0.1)
{
asiWBR = 0.1;
}
if (asiWBR > 10)
{
asiWBR = 10;
}
if (asiWBB < 0.1)
{
asiWBB = 0.1;
}
if (asiWBB > 10)
{
asiWBB = 10;
}
ss.str("");
ss << asiWBR;
awb = "--awb off --awbgains " + ss.str();
ss.str("");
ss << asiWBB;
awb += "," + ss.str() + " ";
}
// Use automatic white balance
else
{
awb = "--awb auto ";
}
// Add white balance setting to raspistill command string
command += awb;
// Check if rotation is at least 0 degrees
if (asiRotation != 0 && asiRotation != 90 && asiRotation != 180 && asiRotation != 270)
{
// Set rotation to 0 degrees
asiRotation = 0;
}
// check if rotation is needed
if (asiRotation!=0) {
ss.str("");
ss << asiRotation;
// Add white balance setting to raspistill command string
command += "--rotation " + ss.str() + " ";
}
// Flip image
string flip = "";
// Check if flip is selected
if (asiFlip == 1 || asiFlip == 3)
{
// Set horizontal flip
flip += "--hflip ";
}
if (asiFlip == 2 || asiFlip == 3)
{
// Set vertical flip
flip += "--vflip ";
}
// Add flip info to raspistill command string
command += flip;
//Gamma correction (saturation)
string saturation;
// Check if gamma correction is set
if (asiGamma < -100)
{
asiGamma = -100;
}
if (asiGamma > 100)
{
asiGamma = 100;
}
if (asiGamma)
{
ss.str("");
ss << asiGamma;
saturation = "--saturation "+ ss.str() + " ";
}
// Add gamma correction info to raspistill command string
command += saturation;
// Brightness
string brightness;
if (asiBrightness < 0)
{
asiBrightness = 0;
}
if (asiBrightness > 100)
{
asiBrightness = 100;
}
// check if brightness setting is set
if (asiBrightness!=50)
{
ss.str("");
ss << asiBrightness;
brightness = "--brightness " + ss.str() + " ";
}
// Add brightness info to raspistill command string
command += brightness;
// Quality
string squality;
if (quality < 0)
{
quality = 0;
}
if (quality > 100)
{
quality = 100;
}
ss.str("");
ss << quality;
squality = "--quality " + ss.str() + " ";
// Add image quality info to raspistill command string
command += squality;
if (!darkframe) {
if (showDetails)
command += "-a 1104 ";
if (time==1)
command += "-a 1036 ";
if (strcmp(ImgText, "") != 0) {
ss.str("");
// ss << ReplaceAll(ImgText, std::string(" "), std::string("_"));
ss << ImgText;
command += "-a \"" + ss.str() + "\" ";
}
if (fontsize < 6)
fontsize = 6;
if (fontsize > 160)
fontsize = 160;
ss.str("");
ss << fontsize;
if (fontcolor < 0)
fontcolor = 0;
if (fontcolor > 255)
fontcolor = 255;
std::stringstream C;
C << std::setfill ('0') << std::setw(2) << std::hex << fontcolor;
if (background < 0)
background = 0;
if (background > 255)
background = 255;
std::stringstream B;
B << std::setfill ('0') << std::setw(2) << std::hex << background;
command += "-ae " + ss.str() + ",0x" + C.str() + ",0x8080" + B.str() + " ";
}
// Define char variable
char cmd[command.length() + 1];
// Convert command to character variable
strcpy(cmd, command.c_str());
sprintf(debugText, "Capture command: %s\n", cmd);
displayDebugText(debugText, 1);
// Execute raspistill command
if (system(cmd) == 0) numExposures++;
}
// Simple function to make flags easier to read for humans.
char const *yes = "1 (yes)";
char const *no = "0 (no)";
char const *yesNo(int flag)
{
if (flag)
return(yes);
else
return(no);
}
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
int main(int argc, char *argv[])
{
signal(SIGINT, IntHandle);
signal(SIGTERM, IntHandle); // The service sends SIGTERM to end this program.
/*
int fontname[] = { CV_FONT_HERSHEY_SIMPLEX, CV_FONT_HERSHEY_PLAIN, CV_FONT_HERSHEY_DUPLEX,
CV_FONT_HERSHEY_COMPLEX, CV_FONT_HERSHEY_TRIPLEX, CV_FONT_HERSHEY_COMPLEX_SMALL,
CV_FONT_HERSHEY_SCRIPT_SIMPLEX, CV_FONT_HERSHEY_SCRIPT_COMPLEX };
int fontnumber = 0;
int iStrLen;
int iTextX = 15, iTextY = 25;
*/
char const *ImgText = "";
char const *param = "";
double fontsize = 32;
/*
int linewidth = 1;
int outlinefont = 0;
*/
int fontcolor = 255;
int background = 0;
/*
int smallFontcolor[3] = { 0, 0, 255 };
int linetype[3] = { CV_AA, 8, 4 };
int linenumber = 0;
char buf[1024] = { 0 };
char bufTime[128] = { 0 };
char bufTemp[128] = { 0 };
*/
int width = 0;
int height = 0;
int dayBin = 1;
int nightBin = 2;
int currentBin = NOT_SET;
int asiDayExposure = 32; // milliseconds
int asiNightExposure = 60000000;
int currentExposure = NOT_SET;
int asiNightAutoExposure = 0;
int asiDayAutoExposure= 1;
int currentAutoExposure = 0;
int asiAutoFocus = 0;
double asiNightGain = 4;
double asiDayGain = 1;
double currentGain = NOT_SET;
int asiNightAutoGain = 0;
int asiDayAutoGain = 0;
int currentAutoGain = NOT_SET;
int asiAutoAWB = 0;
int nightDelay = 10; // Delay in milliseconds. Default is 10ms
int dayDelay = 15000; // Delay in milliseconds. Default is 15 seconds
int currentDelay = NOT_SET;
double asiWBR = 2.5;
double asiWBB = 2;
int asiGamma = 50;
int asiDayBrightness = 50;
int asiNightBrightness= 50;
int currentBrightness = NOT_SET;
int asiFlip = 0;
int asiRotation = 0;
char const *latitude = "52.57N"; //GPS Coordinates of Limmen, Netherlands where this code was altered
char const *longitude = "4.70E";
char const *angle = "0"; // angle of the sun with the horizon (0=sunset, -6=civil twilight, -12=nautical twilight, -18=astronomical twilight)
//int preview = 0;
int time = 0;
int showDetails = 0;
int darkframe = 0;
int daytimeCapture = 0;
int help = 0;
int quality = 90;
int i;
//id *retval;
bool endOfNight = false;
//hread_t hthdSave = 0;
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
setlinebuf(stdout); // Line buffer output so entries appear in the log immediately.
printf("\n");
printf("%s ******************************************\n", KGRN);
printf("%s *** Allsky Camera Software v0.8 | 2021 ***\n", KGRN);
printf("%s ******************************************\n\n", KGRN);
printf("\%sCapture images of the sky with a Raspberry Pi and an ZWO ASI or RPi HQ camera\n", KGRN);
printf("\n");
printf("%sAdd -h or -help for available options\n", KYEL);
printf("\n");
printf("\%sAuthor: ", KNRM);
printf("Thomas Jacquin - <jacquin.thomas@gmail.com>\n\n");
printf("\%sContributors:\n", KNRM);
printf("-Knut Olav Klo\n");
printf("-Daniel Johnsen\n");
printf("-Yang and Sam from ZWO\n");
printf("-Robert Wagner\n");
printf("-Michael J. Kidd - <linuxkidd@gmail.com>\n");
printf("-Rob Musquetier\n\n");
// The newer "allsky.sh" puts quotes around arguments so we can have spaces in them.
// If you are running the old allsky.sh, set this to false:
bool argumentsQuoted = true;
if (argc > 0)
{
sprintf(debugText, "Found %d parameters...\n", argc - 1);
displayDebugText(debugText, 3);
// -h[elp] doesn't take an argument, but the "for" loop assumes every option does,
// so check separately, assuming the option is the first one.
// If it's not the first option, we'll find it in the "for" loop.
if (strcmp(argv[0], "-h") == 0 || strcmp(argv[0], "-help") == 0)
{
help = 1;
i = 1;
}
else
{
i = 0;
}
for (i = 0; i < argc - 1; i++)
{
sprintf(debugText, "Processing argument: %s\n\n", argv[i]);
displayDebugText(debugText, 3);
// Check again in case "-h" isn't the first option.
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0)
{
help = 1;
}
else if (strcmp(argv[i], "-width") == 0)
{
width = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-height") == 0)
{
height = atoi(argv[++i]);
}
/*
else if (strcmp(argv[i], "-type") == 0)
{
Image_type = atoi(argv[++i]);
}
*/
else if (strcmp(argv[i], "-quality") == 0)
{
quality = atoi(argv[++i]);
}
// check for old names as well - the "||" part is the old name
else if (strcmp(argv[i], "-nightexposure") == 0 || strcmp(argv[i], "-exposure") == 0)
{
asiNightExposure = atoi(argv[++i]) * US_IN_MS;
}
else if (strcmp(argv[i], "-nightautoexposure") == 0 || strcmp(argv[i], "-autoexposure") == 0)
{
asiNightAutoExposure = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-autofocus") == 0)
{
asiAutoFocus = atoi(argv[++i]);
}
// xxxx Day gain isn't settable by the user. Should it be?
else if (strcmp(argv[i], "-nightgain") == 0 || strcmp(argv[i], "-gain") == 0)
{
asiNightGain = atof(argv[++i]);
}
else if (strcmp(argv[i], "-nightautogain") == 0 || strcmp(argv[i], "-autogain") == 0)
{
asiNightAutoGain = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-gamma") == 0)
{
asiGamma = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-brightness") == 0)// old "-brightness" applied to day and night
{
asiDayBrightness = atoi(argv[++i]);
asiNightBrightness = asiDayBrightness;
}
else if (strcmp(argv[i], "-daybrightness") == 0)
{
asiDayBrightness = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-nightbrightness") == 0)
{
asiNightBrightness = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-daybin") == 0)
{
dayBin = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-nightbin") == 0 || strcmp(argv[i], "-bin") == 0)
{
nightBin = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-nightdelay") == 0 || strcmp(argv[i], "-delay") == 0)
{
nightDelay = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-daydelay") == 0 || strcmp(argv[i], "-daytimeDelay") == 0)
{
dayDelay = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-awb") == 0)
{
asiAutoAWB = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-wbr") == 0)
{
asiWBR = atof(argv[++i]);
}
else if (strcmp(argv[i], "-wbb") == 0)
{
asiWBB = atof(argv[++i]);
}
// Check for text parameter
else if (strcmp(argv[i], "-text") == 0)
{
if (argumentsQuoted)
{
ImgText = argv[++i];
}
else
{
// Get first param
param = argv[i + 1];
// Space character
const char *space = " ";
// Temporary text buffer
char buffer[1024]; // <- danger, only storage for 1024 characters.
// First word flag
int j = 0;
// Loop while next parameter doesn't start with a - character
while (strncmp(param, "-", 1) != 0)
{
// Copy Text into buffer
strncpy(buffer, ImgText, sizeof(buffer));
// Add a space after each word (skip for first word)
if (j)
strncat(buffer, space, sizeof(buffer));
// Add parameter
strncat(buffer, param, sizeof(buffer));
// Copy buffer into ImgText variable
ImgText = buffer;
// Flag first word is entered
j = 1;
// Get next parameter
param = argv[++i];
}
}
}
/*
else if (strcmp(argv[i], "-textx") == 0)
{
iTextX = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-texty") == 0)
{
iTextY = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-fontname") == 0)
{
fontnumber = atoi(argv[++i]);
}
*/
else if (strcmp(argv[i], "-background") == 0)
{
background = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-fontcolor") == 0)
{
fontcolor = atoi(argv[++i]);
}
/*
else if (strcmp(argv[i], "-smallfontcolor") == 0)
{
if (argumentsQuoted)
{
sscanf(argv[++i], "%d %d %d", &smallFontcolor[0], &smallFontcolor[1], &smallFontcolor[2]);
}
else
{
smallFontcolor[0] = atoi(argv[++i]);
smallFontcolor[1] = atoi(argv[++i]);
smallFontcolor[2] = atoi(argv[++i]);
}
}
else if (strcmp(argv[i], "-fonttype") == 0)
{
linenumber = atoi(argv[++i]);
}
*/
else if (strcmp(argv[i], "-fontsize") == 0)
{
fontsize = atof(argv[++i]);
}
/*
else if (strcmp(argv[i], "-fontline") == 0)
{
linewidth = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-outlinefont") == 0)
{
outlinefont = atoi(argv[++i]);
if (outlinefont != 0)
outlinefont = 1;
}
*/
else if (strcmp(argv[i], "-rotation") == 0)
{
asiRotation = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-flip") == 0)
{
asiFlip = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-filename") == 0)
{
fileName = (argv[++i]);
}
else if (strcmp(argv[i], "-latitude") == 0)
{
latitude = argv[++i];
}
else if (strcmp(argv[i], "-longitude") == 0)
{
longitude = argv[++i];
}
else if (strcmp(argv[i], "-angle") == 0)
{
angle = argv[++i];
}
/*
else if (strcmp(argv[i], "-preview") == 0)
{
preview = atoi(argv[++i]);
}
*/
else if (strcmp(argv[i], "-showTime") == 0 || strcmp(argv[i], "-time") == 0)
{
time = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-darkframe") == 0)
{
darkframe = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-showDetails") == 0)
{
showDetails = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-daytime") == 0)
{
daytimeCapture = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-notificationimages") == 0)
{
notificationImages = atoi(argv[++i]);
}
else if (strcmp(argv[i], "-tty") == 0)
{
tty = atoi(argv[++i]);
}
}
}
if (help == 1)
{
printf("%sAvailable Arguments:\n", KYEL);
printf(" -width - Default = Camera Max Width\n");
printf(" -height - Default = Camera Max Height\n");
printf(" -nightexposure - Default = 5000000 - Time in us (equals to 5 sec)\n");
printf(" -nightautoexposure - Default = 0 - Set to 1 to enable auto Exposure\n");
printf(" -autofocus - Default = 0 - Set to 1 to enable auto Focus\n");
printf(" -nightgain - Default = 1 (1 - 16)\n");
printf(" -nightautogain - Default = 0 - Set to 1 to enable auto Gain at night\n");
printf(" -gamma - Default = 50 (-100 till 100)\n");
printf(" -brightness - Default = 50 (0 till 100)\n");
printf(" -awb - Default = 0 - Auto White Balance (0 = off)\n");
printf(" -wbr - Default = 2 - White Balance Red (0 = off)\n");
printf(" -wbb - Default = 2 - White Balance Blue (0 = off)\n");
printf(" -daybin - Default = 1 - binning OFF (1x1), 2 = 2x2, 3 = 3x3 binning\n");
printf(" -nightbin - Default = 1 - same as -daybin but for nighttime\n");
printf(" -nightdelay - Default = 10 - Delay between images in milliseconds - %d = 1 sec.\n", MS_IN_SEC);