Extend the Quad Encoder test

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4396 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2012-02-15 19:12:19 +00:00
parent 3625222c6c
commit 46e984d523
3 changed files with 41 additions and 6 deletions

View File

@ -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
^^^^^^^^^^^^^

View File

@ -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

View File

@ -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: