examples/qencoder: obtain samples using the QEIOC_GETINDEX ioctl call
Normally, the qencoder position is obtained using the QEIOC_POSITION ioctl call. Adding the -i argument uses the QEIOC_GETINDEX to obtain the qe_index_s struct containing the position alongisde other fields. Signed-off-by: Stepan Pressl <pressste@fel.cvut.cz>
This commit is contained in:
parent
366d8db436
commit
1a7da54a9b
@ -39,6 +39,7 @@ struct qe_example_s
|
|||||||
{
|
{
|
||||||
FAR char *devpath; /* Path to the QE device */
|
FAR char *devpath; /* Path to the QE device */
|
||||||
bool reset; /* True: set the count back to zero */
|
bool reset; /* True: set the count back to zero */
|
||||||
|
bool use_qeindex; /* True: use the QEIOC_GETINDEX call to get samples */
|
||||||
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 */
|
||||||
};
|
};
|
||||||
|
@ -103,6 +103,7 @@ static void qe_help(void)
|
|||||||
printf(" [-n samples] Number of samples\n");
|
printf(" [-n samples] Number of samples\n");
|
||||||
printf(" [-t msec] Delay between samples (msec)\n");
|
printf(" [-t msec] Delay between samples (msec)\n");
|
||||||
printf(" [-r] Reset the position to zero\n");
|
printf(" [-r] Reset the position to zero\n");
|
||||||
|
printf(" [-i] Use the QEIOC_GETINDEX call to obtain samples\n");
|
||||||
printf(" [-h] Shows this message and exits\n\n");
|
printf(" [-h] Shows this message and exits\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,6 +154,7 @@ static void parse_args(int argc, FAR char **argv)
|
|||||||
int nargs;
|
int nargs;
|
||||||
|
|
||||||
g_qeexample.reset = false;
|
g_qeexample.reset = false;
|
||||||
|
g_qeexample.use_qeindex = false;
|
||||||
g_qeexample.nloops = CONFIG_EXAMPLES_QENCODER_NSAMPLES;
|
g_qeexample.nloops = CONFIG_EXAMPLES_QENCODER_NSAMPLES;
|
||||||
g_qeexample.delay = CONFIG_EXAMPLES_QENCODER_DELAY;
|
g_qeexample.delay = CONFIG_EXAMPLES_QENCODER_DELAY;
|
||||||
|
|
||||||
@ -202,6 +204,11 @@ static void parse_args(int argc, FAR char **argv)
|
|||||||
index++;
|
index++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'i':
|
||||||
|
g_qeexample.use_qeindex = true;
|
||||||
|
index++;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
qe_help();
|
qe_help();
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
@ -229,6 +236,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
int exitval = EXIT_SUCCESS;
|
int exitval = EXIT_SUCCESS;
|
||||||
int ret;
|
int ret;
|
||||||
int nloops;
|
int nloops;
|
||||||
|
struct qe_index_s index;
|
||||||
|
|
||||||
/* Set the default values */
|
/* Set the default values */
|
||||||
|
|
||||||
@ -295,6 +303,28 @@ int main(int argc, FAR char *argv[])
|
|||||||
|
|
||||||
/* Get the positions data using the ioctl */
|
/* Get the positions data using the ioctl */
|
||||||
|
|
||||||
|
if (g_qeexample.use_qeindex)
|
||||||
|
{
|
||||||
|
ret = ioctl(fd, QEIOC_GETINDEX, (unsigned long)((uintptr_t)&index));
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
printf("qe_main: ioctl(QEIOC_GETINDEX) failed: %d\n", errno);
|
||||||
|
printf("Your MCU probably does not support this ioctl call.\n");
|
||||||
|
printf("Consider using this example without the -i option.\n");
|
||||||
|
exitval = EXIT_FAILURE;
|
||||||
|
goto errout_with_dev;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* GETINDEX succesful */
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("qe_main: %3d. pos: %" PRIi32 ", last index: %" PRIi32 ", hit indexes: %" \
|
||||||
|
PRIi16 "\n", nloops + 1, index.qenc_pos, index.indx_pos, index.indx_cnt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ret = ioctl(fd, QEIOC_POSITION, (unsigned long)((uintptr_t)&position));
|
ret = ioctl(fd, QEIOC_POSITION, (unsigned long)((uintptr_t)&position));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
@ -309,6 +339,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
{
|
{
|
||||||
printf("qe_main: %3d. %" PRIi32 "\n", nloops + 1, position);
|
printf("qe_main: %3d. %" PRIi32 "\n", nloops + 1, position);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Delay a little bit */
|
/* Delay a little bit */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user