diff --git a/panther_lights/CMakeLists.txt b/panther_lights/CMakeLists.txt index aa0c99031..b7cddbb74 100644 --- a/panther_lights/CMakeLists.txt +++ b/panther_lights/CMakeLists.txt @@ -4,23 +4,6 @@ project(panther_lights) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -find_library(LIBGPIOD libgpiod) - -if(NOT LIBGPIOD) - message(WARNING "libgpiod not found. Building from source") - include(ExternalProject) - - ExternalProject_Add(libgpiod - GIT_REPOSITORY git://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git - GIT_TAG v2.0.1 - PREFIX ${CATKIN_DEVEL_PREFIX} - CONFIGURE_COMMAND /autogen.sh --prefix= --enable-tools=no --enable-bindings-cxx - BUILD_COMMAND make -j ${N} - INSTALL_COMMAND make install INSTALL_PREFIX=${CATKIN_DEVEL_PREFIX}/lib/libgpiod - BUILD_IN_SOURCE 1 - ) -endif() - find_package(catkin REQUIRED COMPONENTS image_transport panther_msgs @@ -33,7 +16,6 @@ find_package(catkin REQUIRED COMPONENTS catkin_package( INCLUDE_DIRS include - LIBRARIES libgpiod CATKIN_DEPENDS panther_msgs roscpp ) @@ -48,9 +30,9 @@ add_executable(driver_node src/apa102.cpp ) -add_dependencies(driver_node libgpiod ${catkin_EXPORTED_TARGETS}) +add_dependencies(driver_node ${catkin_EXPORTED_TARGETS}) target_link_libraries(driver_node - ${CATKIN_DEVEL_PREFIX}/lib/libgpiodcxx.so + gpiodcxx ${catkin_LIBRARIES} ) diff --git a/panther_lights/include/panther_lights/driver_node.hpp b/panther_lights/include/panther_lights/driver_node.hpp index 19793387b..bc9544324 100644 --- a/panther_lights/include/panther_lights/driver_node.hpp +++ b/panther_lights/include/panther_lights/driver_node.hpp @@ -29,6 +29,7 @@ class DriverNode int num_led_; double frame_timeout_; bool panels_initialised_ = false; + gpiod::line power_pin_; std::string node_name_; APA102 front_panel_; @@ -46,7 +47,6 @@ class DriverNode void frame_cb( const sensor_msgs::Image::ConstPtr & msg, const APA102 & panel, const ros::Time & last_time, const std::string & panel_name); - void set_pin_value(const gpiod::line::value value) const; bool set_brightness_cb( panther_msgs::SetLEDBrightness::Request & req, panther_msgs::SetLEDBrightness::Response & res); }; diff --git a/panther_lights/package.xml b/panther_lights/package.xml index 7de02cac6..d783945e1 100644 --- a/panther_lights/package.xml +++ b/panther_lights/package.xml @@ -16,13 +16,8 @@ catkin - autoconf - autoconf-archive - libtool - m4 - pkg-config - image_transport + libgpiod-dev panther_msgs roscpp rospy diff --git a/panther_lights/src/driver_node.cpp b/panther_lights/src/driver_node.cpp index 2639305d3..f89b8c7b8 100644 --- a/panther_lights/src/driver_node.cpp +++ b/panther_lights/src/driver_node.cpp @@ -31,7 +31,12 @@ DriverNode::DriverNode( frame_timeout_ = ph_->param("frame_timeout", 0.1); num_led_ = ph_->param("num_led", 46); - set_pin_value(gpiod::line::value::INACTIVE); + const gpiod::chip chip("gpiochip0"); + power_pin_ = chip.find_line("LED_SBC_SEL"); + + const gpiod::line_request lr = { + node_name_, gpiod::line_request::DIRECTION_OUTPUT, gpiod::line_request::FLAG_ACTIVE_LOW}; + power_pin_.request(lr, 0); front_panel_ts_ = ros::Time::now(); rear_panel_ts_ = ros::Time::now(); @@ -71,7 +76,8 @@ DriverNode::~DriverNode() rear_panel_.set_panel(std::vector(num_led_ * 4, 0)); // give back control over LEDs - set_pin_value(gpiod::line::value::INACTIVE); + power_pin_.set_value(0); + power_pin_.release(); } bool DriverNode::set_brightness_cb( @@ -124,26 +130,10 @@ void DriverNode::frame_cb( panels_initialised_ = true; // take control over LEDs - set_pin_value(gpiod::line::value::ACTIVE); + power_pin_.set_value(1); } panel.set_panel(msg->data); } } -void DriverNode::set_pin_value(const gpiod::line::value value) const -{ - auto chip = gpiod::chip(std::filesystem::path{"/dev/gpiochip0"}); - auto power_pin_offset = gpiod::line::offset(chip.get_line_offset_from_name("LED_SBC_SEL")); - - auto settings = gpiod::line_settings(); - settings.set_direction(gpiod::line::direction::OUTPUT); - settings.set_active_low(true); - settings.set_output_value(value); - - auto rb = chip.prepare_request(); - rb.set_consumer(node_name_); - rb.add_line_settings(power_pin_offset, settings); - rb.do_request(); -} - } // namespace panther_lights \ No newline at end of file