7
mirror of https://github.com/EEVengers/ThunderScope.git synced 2025-04-22 17:43:44 +00:00

add --help to all example programs

This commit is contained in:
profezzorn 2022-02-17 20:25:33 -08:00
parent 0b7e068b1e
commit 2c2c5cb2a0
3 changed files with 48 additions and 5 deletions
Software/libthunderscopehw/examples
thunderscopehwbench
thunderscopehwcalibrate
thunderscopehwdump

View File

@ -35,6 +35,7 @@ struct Option options[] = {
{"device", true, 1 },
{"verbose", false, 2 },
{"repeat", true, 3 },
{"help", false, 4 },
};
#define TS_RUN(X) do { \
@ -45,6 +46,13 @@ struct Option options[] = {
} \
} while(0)
void usage() {
printf("thunderscopehwbench [options]\n"
" --device=<deviceid>\n"
" --verbose\n"
" --repeat=<repetitions>\n");
}
char* optarg;
int optind = 1;
int mygetopt(int argc, char** argv) {
@ -67,6 +75,7 @@ int mygetopt(int argc, char** argv) {
return options[i].return_value;
}
fprintf(stderr, "Unknown option: %s\n", argv[optind]);
usage();
exit(1);
}
@ -93,6 +102,9 @@ int main(int argc, char** argv) {
exit(1);
}
continue;
case 4:
usage();
exit(1);
default:
continue;
case -1:

View File

@ -20,7 +20,8 @@ struct Option {
struct Option options[] = {
{"device", true, 1 },
{"verbose", false, 2 },
{"retries", true, 3 },
{"repeat", true, 3 },
{"help", false, 4 },
};
#define TS_RUN(X) do { \
@ -31,6 +32,13 @@ struct Option options[] = {
} \
} while(0)
void usage() {
printf("thunderscopehwcalibrate [options]\n"
" --device=<deviceid>\n"
" --verbose\n"
" --repeat=<repetitions>\n");
}
char* optarg;
int optind = 1;
int mygetopt(int argc, char** argv) {
@ -53,12 +61,13 @@ int mygetopt(int argc, char** argv) {
return options[i].return_value;
}
fprintf(stderr, "Unknown option: %s\n", argv[optind]);
usage();
exit(1);
}
int main(int argc, char** argv) {
int verbose = 0;
int retries = 1;
int repeat = 1;
uint64_t scope_id = 0;
uint64_t samples = 0;
int samplerate = 0;
@ -74,11 +83,14 @@ int main(int argc, char** argv) {
verbose++;
continue;
case 3:
if (!sscanf(optarg, "%d", &retries)) {
fprintf(stderr, "--retries needs a number.\n");
if (!sscanf(optarg, "%d", &repeat)) {
fprintf(stderr, "--repeat needs a number.\n");
exit(1);
}
continue;
case 4:
usage();
exit(0);
default:
continue;
case -1:
@ -126,7 +138,7 @@ int main(int argc, char** argv) {
usleep(500000);
#endif
for (int i = 0; i < retries; i++) {
for (int i = 0; i < repeat; i++) {
double minoffset = -0.5;
double maxoffset = 0.5;
for (int j = 0; j < 20; j++) {

View File

@ -30,6 +30,7 @@ struct Option options[] = {
{"device", true, 1 },
{"samples", true, 2 },
{"output-samplerate", true, 3 },
{"usage", true, 4 },
{"bw-all", true, 0x10 },
{"bw1", true, 0x11 },
@ -68,6 +69,20 @@ struct Option options[] = {
{"enable4", false, 0x64 },
};
void usage()
{
printf("thunderscopehwdump [options] [filename.wav]\n"
" --device=<deviceid>\n"
" --samples=<number of samples> must be divisable by 4096\n"
" --output-samplerate=<rate> samplerate used in wav file\n"
" --bw[1/2/3/4/-all]=20/100/200/350 (Hz)\n"
" --vdiv[1/2/3/4/-all]=1/2/5/10/20/50/100/200/500/1000/2000/5000/10000 (mV)\n"
" --voffset[1/2/3/4/-all]=<voltage offset> (volts)\n"
" --ac[1/2/3/4/-all]\n"
" --dc[1/2/3/4/-all]\n"
" --enable[1/2/3/4/-all]\n");
}
char* optarg;
int optind = 1;
int mygetopt(int argc, char** argv) {
@ -90,6 +105,7 @@ int mygetopt(int argc, char** argv) {
return options[i].return_value;
}
fprintf(stderr, "Unknown option: %s\n", argv[optind]);
usage();
exit(1);
}
@ -115,6 +131,9 @@ int main(int argc, char** argv) {
fprintf(stderr, "Output samplerate must be a number.\n");
exit(1);
}
case 4:
usage();
exit(0);
default:
continue;
case -1: