Merged in paulpatience/nuttx-apps/qencoder (pull request #28)

examples/qencoder: Add configuration options to Kconfig file
This commit is contained in:
Gregory Nutt 2016-01-19 12:55:53 -06:00
commit dd53e9ae57
3 changed files with 39 additions and 38 deletions

View File

@ -6,8 +6,34 @@
config EXAMPLES_QENCODER config EXAMPLES_QENCODER
bool "Quadrature encoder example" bool "Quadrature encoder example"
default n default n
depends on QENCODER
---help--- ---help---
Enable the quadrature encoder example Enable the quadrature encoder example
if EXAMPLES_QENCODER 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 endif

View File

@ -45,56 +45,27 @@
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * 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 * Public Types
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NSH_BUILTIN_APPS
struct qe_example_s struct qe_example_s
{ {
bool initialized; /* True: QE devices have been initialized */ 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 */ 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 nloops; /* Collect this number of samples */
unsigned int delay; /* Delay this number of seconds between samples */ unsigned int delay; /* Delay this number of seconds between samples */
};
#endif #endif
};
/**************************************************************************** /****************************************************************************
* Public Variables * Public Variables
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NSH_BUILTIN_APPS
extern struct qe_example_s g_qeexample; extern struct qe_example_s g_qeexample;
#endif
/**************************************************************************** /****************************************************************************
* Public Function Prototypes * Public Function Prototypes

View File

@ -75,9 +75,7 @@
* Public Data * Public Data
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NSH_BUILTIN_APPS
struct qe_example_s g_qeexample; struct qe_example_s g_qeexample;
#endif
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
@ -243,14 +241,14 @@ static void parse_args(int argc, FAR char **argv)
#ifdef CONFIG_BUILD_KERNEL #ifdef CONFIG_BUILD_KERNEL
int main(int argc, FAR char *argv[]) int main(int argc, FAR char *argv[])
#else #else
int qe_main(int argc, char *argv[]) int qe_main(int argc, FAR char *argv[])
#endif #endif
{ {
int32_t position; int32_t position;
int fd; int fd;
int exitval = EXIT_SUCCESS; int exitval = EXIT_SUCCESS;
int ret; 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; int nloops;
#endif #endif
@ -286,7 +284,7 @@ int qe_main(int argc, char *argv[])
/* Open the encoder device for reading */ /* Open the encoder device for reading */
printf("qe_main: Hardware initialized. Opening the encoder device: %s\n", printf("qe_main: Hardware initialized. Opening the encoder device: %s\n",
g_qeexample.devpath); g_qeexample.devpath);
fd = open(g_qeexample.devpath, O_RDONLY); fd = open(g_qeexample.devpath, O_RDONLY);
if (fd < 0) if (fd < 0)
@ -298,6 +296,7 @@ int qe_main(int argc, char *argv[])
/* Reset the count if so requested */ /* Reset the count if so requested */
#ifdef CONFIG_NSH_BUILTIN_APPS
if (g_qeexample.reset) if (g_qeexample.reset)
{ {
printf("qe_main: Resetting the count...\n"); printf("qe_main: Resetting the count...\n");
@ -309,6 +308,7 @@ int qe_main(int argc, char *argv[])
goto errout_with_dev; goto errout_with_dev;
} }
} }
#endif
/* Now loop the appropriate number of times, displaying the collected /* Now loop the appropriate number of times, displaying the collected
* encoder samples. * encoder samples.
@ -317,7 +317,7 @@ int qe_main(int argc, char *argv[])
#if defined(CONFIG_NSH_BUILTIN_APPS) #if defined(CONFIG_NSH_BUILTIN_APPS)
printf("qe_main: Number of samples: %u\n", g_qeexample.nloops); printf("qe_main: Number of samples: %u\n", g_qeexample.nloops);
for (nloops = 0; nloops < g_qeexample.nloops; 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); printf("qe_main: Number of samples: %d\n", CONFIG_EXAMPLES_QENCODER_NSAMPLES);
for (nloops = 0; nloops < CONFIG_EXAMPLES_QENCODER_NSAMPLES; nloops++) for (nloops = 0; nloops < CONFIG_EXAMPLES_QENCODER_NSAMPLES; nloops++)
#else #else
@ -344,7 +344,11 @@ int qe_main(int argc, char *argv[])
else else
{ {
#if defined(CONFIG_NSH_BUILTIN_APPS) || CONFIG_EXAMPLES_QENCODER_NSAMPLES > 0
printf("qe_main: %3d. %d\n", nloops+1, position); printf("qe_main: %3d. %d\n", nloops+1, position);
#else
printf("qe_main: %d\n", position);
#endif
} }
/* Delay a little bit */ /* Delay a little bit */