#include <cstring>
#include <filesystem>
#include <gpiod.hpp>
+#include <iomanip>
#include <iostream>
#include <poll.h>
for (const auto& event : buffer)
::std::cout << "offset: " << event.line_offset()
- << ", type: " << edge_event_type_str(event)
- << ", event #" << event.line_seqno()
+ << " type: " << ::std::setw(7)
+ << ::std::left << edge_event_type_str(event)
+ << " event #" << event.line_seqno()
<< ::std::endl;
}
-
- return EXIT_SUCCESS;
}
namespace {
-/* example configuration - customize to suit your situation */
+/* Example configuration - customize to suit your situation */
const ::std::filesystem::path chip_path("/dev/gpiochip0");
const ::gpiod::line::offset line_offset = 5;
int main(void)
{
- auto request =
- ::gpiod::chip(chip_path)
- .prepare_request()
- .set_consumer("get-line-value")
- .add_line_settings(
- line_offset,
- ::gpiod::line_settings().set_direction(
- ::gpiod::line::direction::INPUT))
- .do_request();
-
- ::std::cout << request.get_value(line_offset) << ::std::endl;
+ auto request = ::gpiod::chip(chip_path)
+ .prepare_request()
+ .set_consumer("get-line-value")
+ .add_line_settings(
+ line_offset,
+ ::gpiod::line_settings().set_direction(
+ ::gpiod::line::direction::INPUT))
+ .do_request();
+
+ ::std::cout << line_offset << "="
+ << (request.get_value(line_offset) ==
+ ::gpiod::line::value::ACTIVE ?
+ "Active" :
+ "Inactive")
+ << ::std::endl;
return EXIT_SUCCESS;
}
#include <cstdlib>
#include <chrono>
#include <filesystem>
-#include <iostream>
#include <gpiod.hpp>
+#include <iostream>
#include <thread>
namespace {
::gpiod::line::value toggle_value(::gpiod::line::value v)
{
return (v == ::gpiod::line::value::ACTIVE) ?
- ::gpiod::line::value::INACTIVE :
- ::gpiod::line::value::ACTIVE;
+ ::gpiod::line::value::INACTIVE :
+ ::gpiod::line::value::ACTIVE;
}
} /* namespace */
int main(void)
{
- ::gpiod::line::value val = ::gpiod::line::value::ACTIVE;
+ ::gpiod::line::value value = ::gpiod::line::value::ACTIVE;
auto request =
::gpiod::chip(chip_path)
.do_request();
for (;;) {
- ::std::cout << val << ::std::endl;
+ ::std::cout << line_offset << "=" << value << ::std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
- val = toggle_value(val);
- request.set_value(line_offset, val);
+ value = toggle_value(value);
+ request.set_value(line_offset, value);
}
-
- return EXIT_SUCCESS;
}
#include <cstdlib>
#include <filesystem>
#include <gpiod.hpp>
+#include <iomanip>
#include <iostream>
namespace {
{
switch (event.type()) {
case ::gpiod::edge_event::event_type::RISING_EDGE:
- return "Rising ";
+ return "Rising";
case ::gpiod::edge_event::event_type::FALLING_EDGE:
return "Falling";
default:
request.read_edge_events(buffer);
for (const auto &event : buffer)
- ::std::cout << "offset: " << event.line_offset()
- << ", type: " << edge_event_type_str(event)
- << ", event #" << event.line_seqno()
+ ::std::cout << "line: " << event.line_offset()
+ << " type: " << ::std::setw(7)
+ << ::std::left << edge_event_type_str(event)
+ << " event #" << event.line_seqno()
<< ::std::endl;
}
-
- return EXIT_SUCCESS;
}