-
Notifications
You must be signed in to change notification settings - Fork 3
/
arguments.c
285 lines (248 loc) · 11.2 KB
/
arguments.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
#include "arguments.h"
#include "tasbot.h"
#include "led.h"
#include "palette.h"
#include "filesystem.h"
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>
bool running = true;
bool verbose = false;
bool consoleRenderer = false;
bool skipStartupAnimation = false;
bool useRealtimeControl = false;
char* specificAnimationToShow = NULL;
//Debug
bool activateLEDModule = true;
bool realTASBot = true;
/**
* Print a help dialog to the console
*/
void printHelp() {
printf("===[Debug options]===\n");
printf("-h Print this help screen\n");
printf("-v Enable verbose logging\n");
printf("-r Enable console renderer for frames\n");
printf("-d [GPIO] Change GPIO data pin. Possible options are between 2 to 27. Default is %d\n", GPIO_PIN);
printf("-g Use gamma correction. DON'T USE, IT'S BROKEN!\n");
printf("\n===[Tune animation playback]===\n");
printf("-c Use random color from palette for monochrome animations\n");
printf("-a Use random color from palette for monochrome animations as well as blinks and the base\n");
printf("-w Activate rainbow mode. ATTENTION: Will overwrite ALL white pixels!\n");
printf("-W [10-1000] Set fade speed of rainbow mode in milliseconds. Default is %d\n", DEFAULT_HUE_FADE_SPEED);
printf("-C [xxxxxx] Default color that should be used for not colored animations\n");
printf("-b [0-255] Set maximum possible brightness. Default is %d\n", BRIGHTNESS);
printf("-s [MULTIPLIER] Set playback speed. Needs to be bigger than 0\n");
printf("-D Let the playback speed affect blink delay\n");
printf("-u Skip the startup animation\n");
printf("-R Set how many times a animation should be repeated. Default is %d\n", repetitions);
printf("-U Use the WLED UDP realtime control for the centered \"nose\" LEDs\n");
printf("-B [PATTERN] Controls the blinks. Highest number that can be used within the pattern is 9\n");
printf(" -1st: Maximum number of blinks between animations\n");
printf(" -2nd: Minimum seconds between blinks\n");
printf(" -3rd: Maximum seconds between blinks\n");
printf(" Example: \"4-4-6\" (default)\n");
printf(" -Maximum of 4 blinks between animations\n");
printf(" -4 to 6 seconds between each blink\n");
printf("\n===[File arguments]===\n");
printf("-p [FOLDER PATH] Play animations from a specific folder.\n");
printf("-z [FOLDER PATH] Play blink animation from specific folder.\n");
printf("-i [FILE PATH] Play specific animation as endless loop. \"-p\" and \"-z\" become useless with this.\n");
printf("-P [FILE PATH] Use color palette from text file. For formatting of palette file use tool or see example.\n");
printf("\n===[Hints]===\n");
printf("- To bring TASBot in a state, where he is only blinking, execute with argument \"-p ./gifs/blinks/\". This will narrow all possible options for animations down to blinking ones, while keeping the support for blink patterns and the usual appearance. To further improve appearance, don't use with the -c argument.\n\n");
printf("- Use different working directories as \"profiles\". This way, you could feature different sets of animations with different base frames if needed.\n");
}
/**
* Parse the program arguments from the console line
*/
void parseArguments(int _argc, char** _argv) {
int c;
while ((c = getopt(_argc, _argv, "XhvgwruUacDd:b:s:B:i:p:z:P:C:R:W:")) != -1) {
switch (c) {
case 'h':
printHelp();
exit(EXIT_SUCCESS);
case 'v':
verbose = true;
printf("[INFO] Use verbose logging\n");
break;
case 'r':
consoleRenderer = true;
printf("[INFO] Use console renderer\n");
break;
case 'g':
useGammaCorrection = true;
printf("[INFO] Use gamma correction\n");
break;
case 'D':
playbackSpeedAffectBlinks = true;
printf("[INFO] Playback speed will affect blink delay\n");
break;
case 'X':
realTASBot = false;
printf("[INFO] SECRET **NOT** TASBot MODE. FOR DEBUGGING ONLY!\n");
break;
case 'u':
skipStartupAnimation = true;
printf("[INFO] Skip startup animation\n");
break;
case 'U':
useRealtimeControl = true;
printf("[INFO] Using realtime control for centered LEDs\n");
break;
case 'd': {
int pin = (int) strtol(optarg, NULL, 10);
if (pin > 27 || pin < 2) {
fprintf(stderr, "[ERROR] GPIO pin %d doesnt exist. Pin ID must be between 2 and 27\n", pin);
abort();
}
dataPin = pin;
printf("[INFO] Set data pin to GPIO pin %d\n", pin);
break;
}
case 'c':
useRandomColors = true;
printf("[INFO] Use random color\n");
break;
case 'a':
useRandomColorsForAll = true;
printf("[INFO] Use random color, also for blinks and the base\n");
break;
case 'w':
rainbowMode = true;
printf("[INFO] Rainbow mode activated\n");
break;
case 'C': {
defaultColor = strtocol(optarg);
printf("[INFO] Set color to #%06x\n", defaultColor);
break;
}
case 'b': {
int bright = (int) strtol(optarg, NULL, 10);
if (bright > 255) {
printf("[WARNING] Brightness given (%d) higher than 255. Gonna use 255\n", bright);
bright = 255;
} else if (bright < 0) {
printf("[WARNING] Brightness given (%d) smaller than 0. Gonna use 0\n", bright);
bright = 0;
}
brightness = bright;
printf("[INFO] Set brightness to %d\n", brightness);
break;
}
case 'W': {
long speed = (int) strtol(optarg, NULL, 10);
if (speed > 1000) {
printf("[WARNING] Milliseconds given (%d) higher than 1000. Gonna use 1000\n", speed);
speed = 1000;
} else if (speed < 10) {
printf("[WARNING] Milliseconds given (%d) smaller than 10. Gonna use 10\n", speed);
speed = 10;
}
fadeSpeed = speed;
printf("[INFO] Set fade speed to %d milliseconds\n", fadeSpeed);
break;
}
case 'R': {
int reps = (int) strtol(optarg, NULL, 10);
if (reps < 1) {
printf("[WARNING] Repetitions given (%d) smaller then 1. Gonna use 1\n", reps);
reps = 1;
}
repetitions = reps;
printf("[INFO] Set repetitions to %d\n", repetitions);
break;
}
case 's': {
float speed = strtof(optarg, NULL);
if (speed > 0) {
playbackSpeed = speed;
printf("[INFO] Set playback speed to %f\n", speed);
} else {
fprintf(stderr,
"[ERROR] Can't use %f as playback speed. Please use a playback speed bigger than 0\n",
speed);
abort();
}
break;
}
case 'B': {
int blinks = optarg[0] - '0';
int min = optarg[2] - '0';
int max = optarg[4] - '0';
if (blinks < 0 || blinks > 9 || min < 0 || min > 9 || max < 0 || max > 9) {
fprintf(stderr, "[ERROR] Invalid pattern (%s). Please check pattern\n", optarg);
abort();
} else if (min > max) {
printf("[WARNING] Faulty pattern (%s). The minimum seconds between blinks can't be bigger than then the maximum seconds. Going to flip them!\n",
optarg);
minTimeBetweenBlinks = max;
maxTimeBetweenBlinks = min;
} else {
minTimeBetweenBlinks = min;
maxTimeBetweenBlinks = max;
}
maxBlinks = blinks;
printf("[INFO] Set blink pattern to %d-%d-%d\n", maxBlinks, minTimeBetweenBlinks, maxTimeBetweenBlinks);
break;
}
case 'p': {
if (checkIfDirectoryExist(optarg)) {
pathForAnimations = optarg;
printf("[INFO] Use animations from \"%s\"\n", optarg);
} else {
fprintf(stderr, "[ERROR] Can't open directory \"%s\"\n", optarg);
abort();
}
break;
}
case 'z': {
if (checkIfDirectoryExist(optarg)) {
pathForBlinks = optarg;
printf("[INFO] Use blink animations from \"%s\"\n", optarg);
} else {
fprintf(stderr, "[ERROR] Can't open directory \"%s\"\n", optarg);
abort();
}
break;
}
case 'i': {
if (checkIfFileExist(optarg)) {
specificAnimationToShow = optarg;
printf("[INFO] Use specific animation \"%s\"\n", optarg);
} else {
fprintf(stderr, "[ERROR] Can't open file \"%s\"\n", optarg);
abort();
}
break;
}
case 'P': {
if (checkIfFileExist(optarg)) {
pathForPalette = optarg;
printf("[INFO] Set color palette to \"%s\"\n", optarg);
} else {
fprintf(stderr, "[ERROR] Can't open file \"%s\"\n", optarg);
abort();
}
break;
}
case '?':
if (optopt == 'b' || optopt == 's' || optopt == 'B' || optopt == 'i' || optopt == 'p' ||
optopt == 'z' || optopt == 'P') {
fprintf(stderr, "Argument -%c requires an parameter.\n", optopt);
} else if (isprint (optopt)) {
fprintf(stderr, "Unknown argument `-%c'. Use -h for more information\n", optopt);
} else {
fprintf(stderr, "Unknown argument character `\\x%x'.\n", optopt);
}
default:
abort();
}
}
for (int index = optind; index < _argc; index++) {
printf("Non-option argument %s\n", _argv[index]);
}
}