From 436c9faed55cac5f224d31dec2bf608efe580674 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 13 Apr 2011 09:31:57 -0300 Subject: [PATCH] atrf-path: the GUI is now activated with -g; also changed arguments in GUI mode - atrf-path.c (usage, main): new option -g to invoke the GUI - atrf-path.c (usage, main): in GUI mode, the number of sweeps is optional (default: infinite) - atrf-path.c (main), gui.h (gui), gui.c (gui): exit after the specified number of sweeps --- tools/atrf-path/atrf-path.c | 37 +++++++++++++++++++++++++++++++------ tools/atrf-path/gui.c | 4 ++-- tools/atrf-path/gui.h | 4 ++-- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/tools/atrf-path/atrf-path.c b/tools/atrf-path/atrf-path.c index 5886e79..062b84d 100644 --- a/tools/atrf-path/atrf-path.c +++ b/tools/atrf-path/atrf-path.c @@ -139,10 +139,26 @@ static void usage(const char *name) { fprintf(stderr, "usage: %s [-p power] [-t trim_tx [-t trim_rx]] driver_tx[:arg]\n" -"%16s driver_rx[:arg] [sweeps [samples]]\n\n" +"%16s driver_rx[:arg] [sweeps [samples]]\n" + +#ifdef HAVE_GFX +"%6s %s -g [-p power] [-t trim_tx [-t trim_rx]] driver_tx[:arg]\n" +"%16s driver_rx[:arg] [[sweeps] samples]\n" +#endif + "\n" + +#ifdef HAVE_GFX +" -g display results graphically\n" +#endif " -p power transmit power, 0 to 15 (default %d)\n" " -t trim trim capacitor, 0 to 15 (default %d)\n" - , name, "", DEFAULT_POWER, DEFAULT_TRIM); + + , name, "", +#ifdef HAVE_GFX + "", name, "", +#endif + DEFAULT_POWER, DEFAULT_TRIM); + exit(1); } @@ -155,14 +171,19 @@ int main(int argc, char **argv) .trim_rx = DEFAULT_TRIM, .samples = 1, }; + int graphical = 0; int power = DEFAULT_POWER; int sweeps = 1; unsigned long tmp; char *end; int c; - while ((c = getopt(argc, argv, "p:t:")) != EOF) + while ((c = getopt(argc, argv, "gp:t:")) != EOF) switch (c) { + case'g': + graphical = 1; + sweeps = 0; + break; case 'p': tmp = strtoul(optarg, &end, 0); if (*end || tmp > 15) @@ -195,6 +216,10 @@ int main(int argc, char **argv) sweeps = strtoul(argv[optind+2], &end, 0); if (*end) usage(*argv); + if (graphical && argc-optind == 3) { + sweep.samples = sweeps; + sweeps = 0; + } /* fall through */ case 2: tx_drv = argv[optind]; @@ -212,10 +237,10 @@ int main(int argc, char **argv) return 1; sweep.power = 15-power; - if (sweeps) /* @@@ hack */ - do_sweeps(&sweep, sweeps); + if (graphical) + gui(&sweep, sweeps); else - gui(&sweep); + do_sweeps(&sweep, sweeps); atrf_reg_write(sweep.tx, REG_TRX_STATE, TRX_CMD_TRX_OFF); atrf_reg_write(sweep.rx, REG_TRX_STATE, TRX_CMD_TRX_OFF); diff --git a/tools/atrf-path/gui.c b/tools/atrf-path/gui.c index 18377db..4bd47bf 100644 --- a/tools/atrf-path/gui.c +++ b/tools/atrf-path/gui.c @@ -109,7 +109,7 @@ static void tstop(void) } -void gui(const struct sweep *sweep) +void gui(const struct sweep *sweep, int sweeps) { SDL_Surface *surf; SDL_Event event; @@ -127,7 +127,7 @@ void gui(const struct sweep *sweep) exit(1); } - while (1) { + while (cycle != sweeps || !sweeps) { struct sample res[N_CHAN*2]; while (SDL_PollEvent(&event)) diff --git a/tools/atrf-path/gui.h b/tools/atrf-path/gui.h index 2dc2288..b9b96fd 100644 --- a/tools/atrf-path/gui.h +++ b/tools/atrf-path/gui.h @@ -19,9 +19,9 @@ #ifdef HAVE_GFX -void gui(const struct sweep *sweep); +void gui(const struct sweep *sweep, int sweeps); #else -#define gui(sweep) abort() +#define gui(sweep, sweeps) abort() #endif #endif /* !GUI_H */