From a19935519175396ad04c034a97af3bbcde3dfc51 Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 15 Feb 2012 19:12:19 +0000 Subject: Extend the Quad Encoder test git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4396 42af7a65-404d-4744-a932-0658087f49c3 --- apps/examples/README.txt | 4 ++++ apps/examples/qencoder/qe.h | 13 +++++++++++-- apps/examples/qencoder/qe_main.c | 30 ++++++++++++++++++++++++++---- 3 files changed, 41 insertions(+), 6 deletions(-) (limited to 'apps/examples') diff --git a/apps/examples/README.txt b/apps/examples/README.txt index eeb05562d..ffc592167 100644 --- a/apps/examples/README.txt +++ b/apps/examples/README.txt @@ -932,6 +932,10 @@ examples/qencoder and this value is ignored. Otherwise, this number of samples is collected and the program terminates. Default: Samples are collected indefinitely. + CONFIG_EXAMPLES_QENCODER_DELAY - This value provides the delay (in + milliseonds) between each sample. If CONFIG_NSH_BUILTIN_APPS + is defined, then this value is the default delay if no other delay is + provided on the command line. Default: 100 milliseconds examples/rgmp ^^^^^^^^^^^^^ diff --git a/apps/examples/qencoder/qe.h b/apps/examples/qencoder/qe.h index 8b9035604..1571da7b2 100644 --- a/apps/examples/qencoder/qe.h +++ b/apps/examples/qencoder/qe.h @@ -55,6 +55,10 @@ * and this value is ignored. Otherwise, this number of samples is * collected and the program terminates. Default: Samples are collected * indefinitely. + * CONFIG_EXAMPLES_QENCODER_DELAY - This value provides the delay (in + * milliseonds) between each sample. If CONFIG_NSH_BUILTIN_APPS + * is defined, then this value is the default delay if no other delay is + * provided on the command line. Default: 100 milliseconds */ #ifndef CONFIG_QENCODER @@ -65,6 +69,10 @@ # define CONFIG_EXAMPLES_QENCODER_DEVPATH "/dev/qe0" #endif +#ifndef CONFIG_EXAMPLES_QENCODER_DELAY +# define CONFIG_EXAMPLES_QENCODER_DELAY 100 +#endif + /* Debug ********************************************************************/ #ifdef CONFIG_CPP_HAVE_VARARGS @@ -92,8 +100,9 @@ #ifdef CONFIG_NSH_BUILTIN_APPS struct qe_example_s { - bool reset; - int nloops; + bool reset; /* True: set the count back to zero */ + unsigned int nloops; /* Collect this number of samples */ + unsigned int delay; /* Delay this number of seconds between samples */ }; #endif diff --git a/apps/examples/qencoder/qe_main.c b/apps/examples/qencoder/qe_main.c index c9a4d30e6..5d402ce41 100644 --- a/apps/examples/qencoder/qe_main.c +++ b/apps/examples/qencoder/qe_main.c @@ -99,9 +99,10 @@ static void qe_help(void) { message("\nUsage: qe [OPTIONS]\n\n"); message("OPTIONS include:\n"); - message(" [-n samples] number of samples\n"); - message(" [-r] reset the count\n"); - message(" [-h] shows this message and exits\n\n"); + message(" [-n samples] Number of samples\n"); + message(" [-t msec] Delay between samples (msec)\n"); + message(" [-r] Reset the position to zero\n"); + message(" [-h] Shows this message and exits\n\n"); } #endif @@ -157,6 +158,7 @@ void parse_args(int argc, FAR char **argv) g_qeexample.reset = false; g_qeexample.nloops = 1; + g_qeexample.delay = CONFIG_EXAMPLES_QENCODER_DELAY; for (index = 1; index < argc; ) { @@ -177,7 +179,19 @@ void parse_args(int argc, FAR char **argv) exit(1); } - g_qeexample.nloops = (int)value; + g_qeexample.nloops = (unsigned int)value; + index += nargs; + break; + + case 't': + nargs = arg_decimal(&argv[index], &value); + if (value < 0 || value > INT_MAX) + { + message("Sample delay out of range: %ld\n", value); + exit(1); + } + + g_qeexample.delay = (unsigned int)value; index += nargs; break; @@ -298,6 +312,14 @@ int MAIN_NAME(int argc, char *argv[]) { message(MAIN_STRING " %d\n", position); } + + /* Delay a little bit */ + +#if defined(CONFIG_NSH_BUILTIN_APPS) + usleep(g_qeexample.delay * 1000); +#else + usleep(CONFIG_EXAMPLES_QENCODER_DELAY * 1000); +#endif } errout_with_dev: -- cgit v1.2.3