Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/jetson_gpio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <sensor_trigger/jetson_gpio.hpp>

#include <cstdio>
#include <sys/stat.h>

namespace jetson_gpio
{
Expand Down Expand Up @@ -65,6 +66,15 @@ bool JetsonGpio::export_gpio()
int file_descriptor, buffer_length;
char buffer[BUFFER_SIZE];

// Check target GPIO is available (not opened) first.
// If it is unavailable, close the port and try to open it.
std::string target_gpio = std::string(SYSFS_GPIO_DIR) + std::string("/gpio")
+ std::to_string(gpio_);
struct stat return_status;
if (stat(target_gpio.c_str(), &return_status) == 0) {
unexport_gpio();
}

file_descriptor = open(SYSFS_GPIO_DIR "/export", O_WRONLY);
if (file_descriptor < 0) {
return false;
Expand Down