Skip to content

Commit

Permalink
mraa-gpio: return proper error codes
Browse files Browse the repository at this point in the history
because the permissions might be missing, and then we want to fallback
to sudo mraa-gpio.

Signed-off-by: Reini Urban <reini@spexai.com>
  • Loading branch information
Reini Urban authored and rurban committed Oct 15, 2024
1 parent 301089e commit 0a4b7a5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tools/mraa-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ gpio_isr_stop(struct gpio_source* gpio_info)
int
main(int argc, char** argv)
{
int retval = 0;
if (argc == 1) {
print_command_error();
}
Expand All @@ -177,10 +178,13 @@ main(int argc, char** argv)
if (argc == 4) {
int pin = atoi(argv[2]);
mraa_boolean_t rawmode = strcmp(argv[1], "setraw") == 0;
if (gpio_set(pin, atoi(argv[3]), rawmode) != MRAA_SUCCESS)
if (gpio_set(pin, atoi(argv[3]), rawmode) != MRAA_SUCCESS) {
fprintf(stdout, "Could not initialize gpio %d\n", pin);
retval = 1;
}
} else {
print_command_error();
retval = 2;
}
} else if ((strcmp(argv[1], "get") == 0) || (strcmp(argv[1], "getraw") == 0)) {
if (argc == 3) {
Expand All @@ -191,9 +195,11 @@ main(int argc, char** argv)
fprintf(stdout, "Pin %d = %d\n", pin, level);
} else {
fprintf(stdout, "Could not initialize gpio %d\n", pin);
retval = 1;
}
} else {
print_command_error();
retval = 2;
}
} else if (strcmp(argv[1], "monitor") == 0) {
if (argc == 3) {
Expand All @@ -211,13 +217,16 @@ main(int argc, char** argv)
gpio_isr_stop(&gpio_info);
} else {
fprintf(stdout, "Failed to register ISR for pin %d\n", pin);
retval = 3;
}
} else {
print_command_error();
retval = 2;
}
} else {
print_command_error();
retval = 2;
}
}
return 0;
return retval;
}

0 comments on commit 0a4b7a5

Please sign in to comment.