From 84b1ccd7d0c5d149d74925c81ce13616a4fd711b Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Fri, 11 Apr 2025 08:28:37 +0200 Subject: [PATCH] gpio move configuring to separate function instead of in constructor --- server/gpio/gpio.cpp | 19 ++++++++++++------- server/gpio/gpio.hpp | 3 ++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/server/gpio/gpio.cpp b/server/gpio/gpio.cpp index 91a41f8..6a88721 100644 --- a/server/gpio/gpio.cpp +++ b/server/gpio/gpio.cpp @@ -61,8 +61,19 @@ void gpiod_chip_close(struct gpiod_chip *chip) } #endif -GPIO::GPIO(Direction dir, uint8_t gpio, bool state, QObject *parent) : QObject(parent), m_offset(gpio) +GPIO::GPIO(QObject *parent) : QObject(parent), m_offset(0) { + +} + +GPIO::~GPIO() +{ + gpiod_line_request_release(m_request); +} + +void GPIO::configure_pin(Direction dir, uint8_t gpio, bool state = false) +{ + m_offset = gpio; if (dir == Direction::Output) { m_request = request_output_line("/dev/gpiochip0", gpio, (enum gpiod_line_value)state, "unisim_cpp"); @@ -81,12 +92,6 @@ GPIO::GPIO(Direction dir, uint8_t gpio, bool state, QObject *parent) : QObject(p } } } - -GPIO::~GPIO() -{ - gpiod_line_request_release(m_request); -} - void GPIO::set_value(bool value) { #if __aarch64__ diff --git a/server/gpio/gpio.hpp b/server/gpio/gpio.hpp index c5a0f49..fe5fb45 100644 --- a/server/gpio/gpio.hpp +++ b/server/gpio/gpio.hpp @@ -50,8 +50,9 @@ class GPIO : public QObject Input, Output }; - explicit GPIO(Direction dir, uint8_t gpio, bool state = false, QObject *parent = nullptr); + explicit GPIO(QObject *parent = nullptr); ~GPIO(); + void configure_pin(Direction dir, uint8_t gpio, bool state = false); void set_value(bool val); bool value();