summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-02-15 19:12:19 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-02-15 19:12:19 +0000
commita19935519175396ad04c034a97af3bbcde3dfc51 (patch)
treeb0c0e8da816add9497ffcdf42c3cb423fe238388
parent8b265a45d9b5d840b563321941c632bd3b2c3963 (diff)
downloadnuttx-a19935519175396ad04c034a97af3bbcde3dfc51.tar.gz
nuttx-a19935519175396ad04c034a97af3bbcde3dfc51.tar.bz2
nuttx-a19935519175396ad04c034a97af3bbcde3dfc51.zip
Extend the Quad Encoder test
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4396 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--apps/examples/README.txt4
-rw-r--r--apps/examples/qencoder/qe.h13
-rw-r--r--apps/examples/qencoder/qe_main.c30
3 files changed, 41 insertions, 6 deletions
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: