We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 5fbaae9 + 4cb91a0 commit ebc4a8dCopy full SHA for ebc4a8d
1 file changed
src/jetson_gpio.cpp
@@ -15,6 +15,7 @@
15
#include <sensor_trigger/jetson_gpio.hpp>
16
17
#include <cstdio>
18
+#include <sys/stat.h>
19
20
namespace jetson_gpio
21
{
@@ -65,6 +66,15 @@ bool JetsonGpio::export_gpio()
65
66
int file_descriptor, buffer_length;
67
char buffer[BUFFER_SIZE];
68
69
+ // Check target GPIO is available (not opened) first.
70
+ // If it is unavailable, close the port and try to open it.
71
+ std::string target_gpio = std::string(SYSFS_GPIO_DIR) + std::string("/gpio")
72
+ + std::to_string(gpio_);
73
+ struct stat return_status;
74
+ if (stat(target_gpio.c_str(), &return_status) == 0) {
75
+ unexport_gpio();
76
+ }
77
+
78
file_descriptor = open(SYSFS_GPIO_DIR "/export", O_WRONLY);
79
if (file_descriptor < 0) {
80
return false;
0 commit comments