apix-pwm-example: apix-adc-example: improve arguments parsing
In previous implementation, if alias wanted to be used, it had to be passed twice. https://jira.digi.com/browse/DEL-6425 Signed-off-by: Hector Bujanda <hector.bujanda@digi.com>
This commit is contained in:
parent
870a6073c0
commit
dfa1e51519
|
|
@ -51,14 +51,25 @@ static void usage_and_exit(char *name, int exitval)
|
||||||
fprintf(stdout,
|
fprintf(stdout,
|
||||||
"Example application using libdigiapix ADC support\n"
|
"Example application using libdigiapix ADC support\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Usage: %s <adc_chip> <adc_channel> <interval> <number_of_samples> \n\n"
|
"Usage: %s\n"
|
||||||
"<adc_chip> ADC chip number or alias\n"
|
" %s is used as ADC alias\n"
|
||||||
"<adc_channel> ADC channel number or alias\n"
|
" %d seconds is used as Interval\n"
|
||||||
|
" %d is used as Samples\n"
|
||||||
|
"\n"
|
||||||
|
"Usage: %s <adc-alias> <interval> <number_of_samples>\n"
|
||||||
|
"<adc-alias> ADC alias\n"
|
||||||
|
"<interval> Time interval for sampling\n"
|
||||||
|
"<number_of_samples> Number of samples to get\n"
|
||||||
|
"\n"
|
||||||
|
"Usage: %s <adc-chip> <adc-channel> <interval> <number_of_samples>\n"
|
||||||
|
"<adc-chip-number> ADC chip number\n"
|
||||||
|
"<adc-channel-number> ADC channel number\n"
|
||||||
"<interval> Time interval for sampling\n"
|
"<interval> Time interval for sampling\n"
|
||||||
"<number_of_samples> Number of samples to get\n"
|
"<number_of_samples> Number of samples to get\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Alias for ADC can be configured in the library config file\n"
|
"Alias for ADC can be configured in the library config file\n"
|
||||||
"\n", name);
|
"\n", name, DEFAULT_ADC_ALIAS, DEFAULT_TIME_INTERVAl,
|
||||||
|
DEFAULT_NUMBER_OF_SAMPLES, name, name);
|
||||||
|
|
||||||
exit(exitval);
|
exit(exitval);
|
||||||
}
|
}
|
||||||
|
|
@ -166,6 +177,12 @@ int main(int argc, char *argv[])
|
||||||
channel = ldx_adc_get_channel(DEFAULT_ADC_ALIAS);
|
channel = ldx_adc_get_channel(DEFAULT_ADC_ALIAS);
|
||||||
interval = DEFAULT_TIME_INTERVAl;
|
interval = DEFAULT_TIME_INTERVAl;
|
||||||
number_of_samples = DEFAULT_NUMBER_OF_SAMPLES;
|
number_of_samples = DEFAULT_NUMBER_OF_SAMPLES;
|
||||||
|
} else if (argc == 4) {
|
||||||
|
/* Parse command line arguments */
|
||||||
|
chip = parse_argument(argv[1], ARG_ADC_CHIP);
|
||||||
|
channel = parse_argument(argv[1], ARG_ADC_CHANNEL);
|
||||||
|
interval = atoi(argv[2]);
|
||||||
|
number_of_samples = atoi(argv[3]);
|
||||||
} else if (argc == 5) {
|
} else if (argc == 5) {
|
||||||
/* Parse command line arguments */
|
/* Parse command line arguments */
|
||||||
chip = parse_argument(argv[1], ARG_ADC_CHIP);
|
chip = parse_argument(argv[1], ARG_ADC_CHIP);
|
||||||
|
|
|
||||||
|
|
@ -46,13 +46,19 @@ static void usage_and_exit(char *name, int exitval)
|
||||||
fprintf(stdout,
|
fprintf(stdout,
|
||||||
"Example application using libdigiapix PWM support\n"
|
"Example application using libdigiapix PWM support\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Usage: %s <pwm-chip> <pwm-freq>\n\n"
|
"Usage: %s\n"
|
||||||
"<pwm-chip> PWM chip number or alias\n"
|
" %s is used as PWM alias\n"
|
||||||
"<pwm-channel> PWM channel number or alias\n"
|
" %dHz is used as Frequency\n\n"
|
||||||
|
"Usage: %s <pwm-alias> <pwm-freq>\n"
|
||||||
|
"<pwm-alias> PWM alias\n"
|
||||||
|
"<pwm-freq> Frequency to use (Hz)\n\n"
|
||||||
|
"Usage: %s <pwm-chip> <pwm-channel> <pwm-freq>\n"
|
||||||
|
"<pwm-chip-number> PWM chip number\n"
|
||||||
|
"<pwm-channel-number> PWM channel number\n"
|
||||||
"<pwm-freq> Frequency to use (Hz)\n"
|
"<pwm-freq> Frequency to use (Hz)\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Aliases for PWM can be configured in the library config file\n"
|
"Aliases for PWM can be configured in the library config file\n"
|
||||||
"\n", name);
|
"\n", name, DEFAULT_PWM_ALIAS, DEFAULT_PWM_FREQUENCY, name, name);
|
||||||
|
|
||||||
exit(exitval);
|
exit(exitval);
|
||||||
}
|
}
|
||||||
|
|
@ -141,10 +147,15 @@ int main(int argc, char **argv)
|
||||||
pwm_chip = ldx_pwm_get_chip(DEFAULT_PWM_ALIAS);
|
pwm_chip = ldx_pwm_get_chip(DEFAULT_PWM_ALIAS);
|
||||||
pwm_channel = ldx_pwm_get_channel(DEFAULT_PWM_ALIAS);
|
pwm_channel = ldx_pwm_get_channel(DEFAULT_PWM_ALIAS);
|
||||||
pwm_freq = DEFAULT_PWM_FREQUENCY;
|
pwm_freq = DEFAULT_PWM_FREQUENCY;
|
||||||
|
} else if (argc == 3) {
|
||||||
|
pwm_chip = parse_argument(argv[1], ARG_PWM_CHIP);
|
||||||
|
pwm_channel = parse_argument(argv[1], ARG_PWM_CHANNEL);
|
||||||
|
pwm_freq = atoi(argv[2]);
|
||||||
} else if (argc == 4) {
|
} else if (argc == 4) {
|
||||||
pwm_chip = parse_argument(argv[1], ARG_PWM_CHIP);
|
pwm_chip = parse_argument(argv[1], ARG_PWM_CHIP);
|
||||||
pwm_channel = parse_argument(argv[2], ARG_PWM_CHANNEL);
|
pwm_channel = parse_argument(argv[2], ARG_PWM_CHANNEL);
|
||||||
pwm_freq = atoi(argv[3]);
|
pwm_freq = atoi(argv[3]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
usage_and_exit(name, EXIT_FAILURE);
|
usage_and_exit(name, EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue