From f5da6e23cf251f7751e1e15d55f45406ea2ead35 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Tue, 19 Jan 2016 13:33:22 -0500 Subject: [PATCH] examples/qencoder: Add configuration options to Kconfig file --- examples/qencoder/Kconfig | 26 ++++++++++++++++++++++++++ examples/qencoder/qe.h | 35 +++-------------------------------- examples/qencoder/qe_main.c | 16 ++++++++++------ 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/examples/qencoder/Kconfig b/examples/qencoder/Kconfig index 461fc8646..b5a0a6fdb 100644 --- a/examples/qencoder/Kconfig +++ b/examples/qencoder/Kconfig @@ -6,8 +6,34 @@ config EXAMPLES_QENCODER bool "Quadrature encoder example" default n + depends on QENCODER ---help--- Enable the quadrature encoder example if EXAMPLES_QENCODER + +config EXAMPLES_QENCODER_DEVPATH + string "QE device path" + default "/dev/qe0" + ---help--- + The default path to the QE device + +config EXAMPLES_QENCODER_NSAMPLES + int "Number of samples" + default 0 + depends on !NSH_BUILTIN_APPS + ---help--- + If CONFIG_NSH_BUILTIN_APPS is defined, then the number of + samples is provided on the command line and this value is ignored. + Otherwise, this number of samples is collected and the program + terminates. If the value is 0, samples are collected indefinitely. + +config EXAMPLES_QENCODER_DELAY + int "Delay between samples" + default 100 + ---help--- + This value provides the delay (in milliseconds) 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. + endif diff --git a/examples/qencoder/qe.h b/examples/qencoder/qe.h index b4802a886..fe1632b6f 100644 --- a/examples/qencoder/qe.h +++ b/examples/qencoder/qe.h @@ -45,56 +45,27 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -/* Configuration ************************************************************/ -/* CONFIG_NSH_BUILTIN_APPS - Build the QE test as an NSH built-in function. - * Default: Built as a standalone problem - * CONFIG_EXAMPLES_QENCODER_DEVPATH - The path to the QE device. Default: - * /dev/qe0 - * CONFIG_EXAMPLES_QENCODER_NSAMPLES - If CONFIG_NSH_BUILTIN_APPS - * is defined, then the number of samples is provided on the command line - * 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 -# error "QE device support is not enabled (CONFIG_QENCODER)" -#endif - -#ifndef CONFIG_EXAMPLES_QENCODER_DEVPATH -# define CONFIG_EXAMPLES_QENCODER_DEVPATH "/dev/qe0" -#endif - -#ifndef CONFIG_EXAMPLES_QENCODER_DELAY -# define CONFIG_EXAMPLES_QENCODER_DELAY 100 -#endif /**************************************************************************** * Public Types ****************************************************************************/ -#ifdef CONFIG_NSH_BUILTIN_APPS struct qe_example_s { bool initialized; /* True: QE devices have been initialized */ - bool reset; /* True: set the count back to zero */ FAR char *devpath; /* Path to the QE device */ +#ifdef CONFIG_NSH_BUILTIN_APPS + 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 +}; /**************************************************************************** * Public Variables ****************************************************************************/ -#ifdef CONFIG_NSH_BUILTIN_APPS extern struct qe_example_s g_qeexample; -#endif /**************************************************************************** * Public Function Prototypes diff --git a/examples/qencoder/qe_main.c b/examples/qencoder/qe_main.c index 2042eaf93..4be96380b 100644 --- a/examples/qencoder/qe_main.c +++ b/examples/qencoder/qe_main.c @@ -75,9 +75,7 @@ * Public Data ****************************************************************************/ -#ifdef CONFIG_NSH_BUILTIN_APPS struct qe_example_s g_qeexample; -#endif /**************************************************************************** * Private Functions @@ -243,14 +241,14 @@ static void parse_args(int argc, FAR char **argv) #ifdef CONFIG_BUILD_KERNEL int main(int argc, FAR char *argv[]) #else -int qe_main(int argc, char *argv[]) +int qe_main(int argc, FAR char *argv[]) #endif { int32_t position; int fd; int exitval = EXIT_SUCCESS; int ret; -#if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_QENCODER_NSAMPLES) +#if defined(CONFIG_NSH_BUILTIN_APPS) || CONFIG_EXAMPLES_QENCODER_NSAMPLES > 0 int nloops; #endif @@ -286,7 +284,7 @@ int qe_main(int argc, char *argv[]) /* Open the encoder device for reading */ printf("qe_main: Hardware initialized. Opening the encoder device: %s\n", - g_qeexample.devpath); + g_qeexample.devpath); fd = open(g_qeexample.devpath, O_RDONLY); if (fd < 0) @@ -298,6 +296,7 @@ int qe_main(int argc, char *argv[]) /* Reset the count if so requested */ +#ifdef CONFIG_NSH_BUILTIN_APPS if (g_qeexample.reset) { printf("qe_main: Resetting the count...\n"); @@ -309,6 +308,7 @@ int qe_main(int argc, char *argv[]) goto errout_with_dev; } } +#endif /* Now loop the appropriate number of times, displaying the collected * encoder samples. @@ -317,7 +317,7 @@ int qe_main(int argc, char *argv[]) #if defined(CONFIG_NSH_BUILTIN_APPS) printf("qe_main: Number of samples: %u\n", g_qeexample.nloops); for (nloops = 0; nloops < g_qeexample.nloops; nloops++) -#elif defined(CONFIG_EXAMPLES_QENCODER_NSAMPLES) +#elif CONFIG_EXAMPLES_QENCODER_NSAMPLES > 0 printf("qe_main: Number of samples: %d\n", CONFIG_EXAMPLES_QENCODER_NSAMPLES); for (nloops = 0; nloops < CONFIG_EXAMPLES_QENCODER_NSAMPLES; nloops++) #else @@ -344,7 +344,11 @@ int qe_main(int argc, char *argv[]) else { +#if defined(CONFIG_NSH_BUILTIN_APPS) || CONFIG_EXAMPLES_QENCODER_NSAMPLES > 0 printf("qe_main: %3d. %d\n", nloops+1, position); +#else + printf("qe_main: %d\n", position); +#endif } /* Delay a little bit */