Merged in paulpatience/nuttx-apps/qencoder (pull request #28)
examples/qencoder: Add configuration options to Kconfig file
This commit is contained in:
commit
dd53e9ae57
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user