nbhw16: shield: fix output in case of error

This commit is contained in:
Stefan Eichenberger 2017-09-04 17:07:39 +02:00
parent e229e0cb3a
commit d7677ffa84
1 changed files with 12 additions and 10 deletions

View File

@ -58,7 +58,7 @@ static int configure_shieldmode(int mode)
int ret; int ret;
if (mode < 0 || mode > 3) { if (mode < 0 || mode > 3) {
printf("Invalid shield mode %d\n", mode); debug ("Invalid shield mode %d\n", mode);
return -1; return -1;
} }
@ -138,7 +138,6 @@ static int configure_shieldmode(int mode)
} }
return 0; return 0;
} }
static int get_rs232(const char *mode) static int get_rs232(const char *mode)
@ -160,8 +159,8 @@ static int get_termination(const char* termination)
return 0; return 0;
} }
printf ("Invalid termination mode %s (falling back to off)", termination); debug ("Invalid termination mode %s (falling back to off)", termination);
return 0; return -1;
} }
static int get_mode_from_args(char * const argv[], int argc) static int get_mode_from_args(char * const argv[], int argc)
@ -172,7 +171,7 @@ static int get_mode_from_args(char * const argv[], int argc)
assert(argc >= 2); assert(argc >= 2);
if (strcmp ("mode", argv[0])) { if (strcmp ("mode", argv[0])) {
puts("Invalid arguments (see help)\n"); debug("Invalid arguments (see help)\n");
return -1; return -1;
} }
@ -180,10 +179,14 @@ static int get_mode_from_args(char * const argv[], int argc)
if (argc > 2) { if (argc > 2) {
if (rs232 || strcmp("termination", argv[2])) { if (rs232 || strcmp("termination", argv[2])) {
puts("Invalid arguments, do not configure termination\n"); debug("Invalid arguments, do not configure termination\n");
return -1;
} }
else { else {
termination = get_termination(argv[3]); termination = get_termination(argv[3]);
if (termination < 0) {
return -1;
}
} }
} }
@ -194,13 +197,12 @@ static int get_mode_from_args(char * const argv[], int argc)
int set_shieldmode(char * const argv[], int argc) int set_shieldmode(char * const argv[], int argc)
{ {
if (argc < 2) { if (argc < 2) {
puts("Too few arguments for comio\n"); debug("Too few arguments for comio\n");
return -1; return -1;
} }
configure_shieldmode(get_mode_from_args(argv, argc)); /* -1 will make configure_shieldmode to faile and is okay therefore */
return configure_shieldmode(get_mode_from_args(argv, argc));
return 0;
} }
struct shield_t comio_shield = { struct shield_t comio_shield = {