examples/qencoder: add an option to configure the encoder maximum position

Signed-off-by: raiden00pl <raiden00@railab.me>
This commit is contained in:
raiden00pl 2021-08-10 10:21:49 +02:00 committed by Xiang Xiao
parent b8fd862965
commit 4fa7248036
2 changed files with 28 additions and 0 deletions

View File

@ -33,4 +33,13 @@ config EXAMPLES_QENCODER_DELAY
If CONFIG_NSH_BUILTIN_APPS is defined, then this value is the default If CONFIG_NSH_BUILTIN_APPS is defined, then this value is the default
delay if no other delay is provided on the command line. delay if no other delay is provided on the command line.
config EXAMPLES_QENCODER_HAVE_MAXPOS
bool "Enable the maximum encoder position"
default n
config EXAMPLES_QENCODER_MAXPOS
int "Maximum encoder position"
default 0
depends on EXAMPLES_QENCODER_HAVE_MAXPOS
endif endif

View File

@ -45,6 +45,12 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_EXAMPLES_QENCODER_HAVE_MAXPOS
# if CONFIG_EXAMPLES_QENCODER_MAXPOS == 0
# error CONFIG_EXAMPLES_QENCODER_MAXPOS not specified
# endif
#endif
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
****************************************************************************/ ****************************************************************************/
@ -245,6 +251,19 @@ int main(int argc, FAR char *argv[])
goto errout; goto errout;
} }
#ifdef CONFIG_EXAMPLES_QENCODER_HAVE_MAXPOS
/* Set the maximum encoder positions */
ret = ioctl(fd, QEIOC_SETPOSMAX,
(unsigned long)CONFIG_EXAMPLES_QENCODER_MAXPOS);
if (ret < 0)
{
printf("qe_main: ioctl(QEIOC_SETMAXPOS) failed: %d\n", errno);
exitval = EXIT_FAILURE;
goto errout_with_dev;
}
#endif
/* Reset the count if so requested */ /* Reset the count if so requested */
if (g_qeexample.reset) if (g_qeexample.reset)