18 std::string file =
"/sys/class/gpio/gpio" + std::to_string(gpioData.
pin) +
"/direction";
20 fd = open(file.data(), O_WRONLY);
23 ROS_ERROR(
"[gpio]Unable to open %s", file.data());
29 if (write(fd,
"out", 3) != 3)
31 ROS_ERROR(
"[gpio]Failed to set direction of gpio%d", gpioData.
pin);
36 if (write(fd,
"in", 2) != 2)
38 ROS_ERROR(
"[gpio]Failed to set direction of gpio%d", gpioData.
pin);
51 std::string file =
"/sys/class/gpio/gpio" + std::to_string(iter->pin) +
"/value";
52 FILE* fp = fopen(file.c_str(),
"r");
55 ROS_ERROR(
"[gpio]Unable to read /sys/class/gpio/gpio%d/value", iter->pin);
59 char state = fgetc(fp);
60 bool value = (state == 0x31);
70 char buffer[1] = {
'1' };
73 std::string file =
"/sys/class/gpio/gpio" + std::to_string(iter.pin) +
"/value";
74 int fd = open(file.c_str(), O_WRONLY);
77 ROS_ERROR(
"[gpio]Unable to write /sys/class/gpio/gpio%i/value", iter.pin);
81 lseek(fd, 0, SEEK_SET);
85 int ref = write(fd, buffer, 1);
87 ROS_ERROR(
"[GPIO]Failed to write to gpio%d.", iter.pin);
92 int ref = write(fd, buffer, 1);
94 ROS_ERROR(
"[GPIO]Failed to write to gpio%d.", iter.pin);