examples/adc/adc_main.c: Appease nxstyle
This commit is contained in:
parent
7fa6f69756
commit
5576c127fd
@ -106,12 +106,14 @@ static void adc_devpath(FAR struct adc_state_s *adc, FAR const char *devpath)
|
|||||||
static void adc_help(FAR struct adc_state_s *adc)
|
static void adc_help(FAR struct adc_state_s *adc)
|
||||||
{
|
{
|
||||||
printf("Usage: adc [OPTIONS]\n");
|
printf("Usage: adc [OPTIONS]\n");
|
||||||
printf("\nArguments are \"sticky\". For example, once the ADC device is\n");
|
printf("\nArguments are \"sticky\". "
|
||||||
|
"For example, once the ADC device is\n");
|
||||||
printf("specified, that device will be re-used until it is changed.\n");
|
printf("specified, that device will be re-used until it is changed.\n");
|
||||||
printf("\n\"sticky\" OPTIONS include:\n");
|
printf("\n\"sticky\" OPTIONS include:\n");
|
||||||
printf(" [-p devpath] selects the ADC device. "
|
printf(" [-p devpath] selects the ADC device. "
|
||||||
"Default: %s Current: %s\n",
|
"Default: %s Current: %s\n",
|
||||||
CONFIG_EXAMPLES_ADC_DEVPATH, g_adcstate.devpath ? g_adcstate.devpath : "NONE");
|
CONFIG_EXAMPLES_ADC_DEVPATH,
|
||||||
|
g_adcstate.devpath ? g_adcstate.devpath : "NONE");
|
||||||
printf(" [-n count] selects the samples to collect. "
|
printf(" [-n count] selects the samples to collect. "
|
||||||
"Default: 1 Current: %d\n", adc->count);
|
"Default: 1 Current: %d\n", adc->count);
|
||||||
printf(" [-h] shows this message and exits\n");
|
printf(" [-h] shows this message and exits\n");
|
||||||
@ -155,7 +157,8 @@ static int arg_decimal(FAR char **arg, FAR long *value)
|
|||||||
* Name: parse_args
|
* Name: parse_args
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static void parse_args(FAR struct adc_state_s *adc, int argc, FAR char **argv)
|
static void parse_args(FAR struct adc_state_s *adc, int argc,
|
||||||
|
FAR char **argv)
|
||||||
{
|
{
|
||||||
FAR char *ptr;
|
FAR char *ptr;
|
||||||
FAR char *str;
|
FAR char *str;
|
||||||
@ -228,8 +231,8 @@ int main(int argc, FAR char *argv[])
|
|||||||
|
|
||||||
if (!g_adcstate.initialized)
|
if (!g_adcstate.initialized)
|
||||||
{
|
{
|
||||||
/* Initialization of the ADC hardware must be performed by board-specific
|
/* Initialization of the ADC hardware must be performed by
|
||||||
* logic prior to running this test.
|
* board-specific logic prior to running this test.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Set the default values */
|
/* Set the default values */
|
||||||
@ -268,76 +271,77 @@ int main(int argc, FAR char *argv[])
|
|||||||
* ADC samples.
|
* ADC samples.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (;;)
|
for (; ; )
|
||||||
{
|
{
|
||||||
/* Flush any output before the loop entered or from the previous pass
|
/* Flush any output before the loop entered or from the previous pass
|
||||||
* through the loop.
|
* through the loop.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_ADC_SWTRIG
|
#ifdef CONFIG_EXAMPLES_ADC_SWTRIG
|
||||||
/* Issue the software trigger to start ADC conversion */
|
/* Issue the software trigger to start ADC conversion */
|
||||||
|
|
||||||
ret = ioctl(fd, ANIOC_TRIGGER, 0);
|
ret = ioctl(fd, ANIOC_TRIGGER, 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
int errcode = errno;
|
int errcode = errno;
|
||||||
printf("adc_main: ANIOC_TRIGGER ioctl failed: %d\n", errcode);
|
printf("adc_main: ANIOC_TRIGGER ioctl failed: %d\n", errcode);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Read up to CONFIG_EXAMPLES_ADC_GROUPSIZE samples */
|
/* Read up to CONFIG_EXAMPLES_ADC_GROUPSIZE samples */
|
||||||
|
|
||||||
readsize = CONFIG_EXAMPLES_ADC_GROUPSIZE * sizeof(struct adc_msg_s);
|
readsize = CONFIG_EXAMPLES_ADC_GROUPSIZE * sizeof(struct adc_msg_s);
|
||||||
nbytes = read(fd, sample, readsize);
|
nbytes = read(fd, sample, readsize);
|
||||||
|
|
||||||
/* Handle unexpected return values */
|
/* Handle unexpected return values */
|
||||||
|
|
||||||
if (nbytes < 0)
|
if (nbytes < 0)
|
||||||
{
|
{
|
||||||
errval = errno;
|
errval = errno;
|
||||||
if (errval != EINTR)
|
if (errval != EINTR)
|
||||||
{
|
{
|
||||||
printf("adc_main: read %s failed: %d\n",
|
printf("adc_main: read %s failed: %d\n",
|
||||||
g_adcstate.devpath, errval);
|
g_adcstate.devpath, errval);
|
||||||
errval = 3;
|
errval = 3;
|
||||||
goto errout_with_dev;
|
goto errout_with_dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("adc_main: Interrupted read...\n");
|
printf("adc_main: Interrupted read...\n");
|
||||||
}
|
}
|
||||||
else if (nbytes == 0)
|
else if (nbytes == 0)
|
||||||
{
|
{
|
||||||
printf("adc_main: No data read, Ignoring\n");
|
printf("adc_main: No data read, Ignoring\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print the sample data on successful return */
|
/* Print the sample data on successful return */
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int nsamples = nbytes / sizeof(struct adc_msg_s);
|
int nsamples = nbytes / sizeof(struct adc_msg_s);
|
||||||
if (nsamples * sizeof(struct adc_msg_s) != nbytes)
|
if (nsamples * sizeof(struct adc_msg_s) != nbytes)
|
||||||
{
|
{
|
||||||
printf("adc_main: read size=%ld is not a multiple of sample size=%d, Ignoring\n",
|
printf("adc_main: read size=%ld is not a multiple of "
|
||||||
(long)nbytes, sizeof(struct adc_msg_s));
|
"sample size=%d, Ignoring\n",
|
||||||
}
|
(long)nbytes, sizeof(struct adc_msg_s));
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
printf("Sample:\n");
|
{
|
||||||
for (i = 0; i < nsamples; i++)
|
printf("Sample:\n");
|
||||||
{
|
for (i = 0; i < nsamples; i++)
|
||||||
printf("%d: channel: %d value: %d\n",
|
{
|
||||||
i+1, sample[i].am_channel, sample[i].am_data);
|
printf("%d: channel: %d value: %d\n",
|
||||||
}
|
i + 1, sample[i].am_channel, sample[i].am_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (g_adcstate.count && --g_adcstate.count <= 0)
|
if (g_adcstate.count && --g_adcstate.count <= 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return OK;
|
return OK;
|
||||||
|
Loading…
Reference in New Issue
Block a user