31 Gpio(
const std::string& chip_name,
unsigned int line_num,
bool is_output,
32 int default_value = 1)
33 : chip_(gpiod_chip_open_by_name(chip_name.c_str())),
34 is_output_(is_output),
36 assert(!chip_name.empty());
39 std::perror(
"Failed to open GPIO chip");
42 line_ = gpiod_chip_get_line(chip_, line_num_);
44 gpiod_chip_close(chip_);
45 std::perror(
"Failed to get GPIO line");
49 ? gpiod_line_request_output(line_,
nullptr, default_value)
50 : gpiod_line_request_input(line_,
nullptr);
52 std::perror(
"Failed to configure GPIO line");
136 int ret = gpiod_line_event_wait(line_,
nullptr);
137 if (ret == 1 && callback_) {
138 struct gpiod_line_event event;
139 if (gpiod_line_event_read(line_, &event) == 0 &&
140 event.event_type == GPIOD_LINE_EVENT_RISING_EDGE) {