Skip to content

Commit

Permalink
[gpio] Add possibility to tweak pull-up / pull-down
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Jan 17, 2024
1 parent 27ef1ba commit e63403f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ struct simpleio_protocol : public ossia::net::protocol_base

GPIO_impl impl{};
int32_t error;
int32_t flags
= ptr->direction ? GPIOHANDLE_REQUEST_OUTPUT : GPIOHANDLE_REQUEST_INPUT;
int32_t flags = ptr->flags;
int32_t events{};
int32_t state{};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <ossia/detail/math.hpp>
#include <ossia/detail/string_algorithms.hpp>

#include <QCheckBox>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QDirIterator>
Expand Down Expand Up @@ -337,6 +338,8 @@ class AddPortDialog : public QDialog
, m_buttons{QDialogButtonBox::StandardButton::Ok | QDialogButtonBox::StandardButton::Cancel, this}
, m_gpioIn{"In"}
, m_gpioOut{"Out"}
, m_gpioPullUp{"Pull-up"}
, m_gpioPullDown{"Pull-down"}
{
this->setLayout(&m_layout);
m_layout.addWidget(&m_availablePorts);
Expand Down Expand Up @@ -370,6 +373,10 @@ class AddPortDialog : public QDialog
m_gpioInOutLayout.addWidget(&m_gpioOut);
m_gpioLayout.addRow(&m_gpioInOutLayout);

m_gpioPullLayout.addWidget(&m_gpioPullUp);
m_gpioPullLayout.addWidget(&m_gpioPullDown);
m_gpioLayout.addRow(&m_gpioPullLayout);

m_custom.setCurrentIndex(0);

connect(&m_buttons, &QDialogButtonBox::accepted, this, &AddPortDialog::accept);
Expand Down Expand Up @@ -411,6 +418,7 @@ class AddPortDialog : public QDialog
case 0: // GPIO
m_custom.setCurrentIndex(1);
m_gpioIn.setChecked(true);
m_gpioPullUp.setChecked(true);
break;
default:
m_custom.setCurrentIndex(0);
Expand All @@ -434,9 +442,24 @@ class AddPortDialog : public QDialog
void operator()(SimpleIO::GPIO& gpio) const noexcept
{
if(self.m_gpioIn.isChecked())
{
gpio.direction = 0;
gpio.flags |= GPIOHANDLE_REQUEST_INPUT;
}
else if(self.m_gpioOut.isChecked())
{
gpio.direction = 1;
gpio.flags |= GPIOHANDLE_REQUEST_OUTPUT;
}

if(self.m_gpioPullUp.isChecked())
{
gpio.flags |= GPIOHANDLE_REQUEST_BIAS_PULL_UP;
}
if(self.m_gpioPullDown.isChecked())
{
gpio.flags |= GPIOHANDLE_REQUEST_BIAS_PULL_DOWN;
}
}

void operator()(SimpleIO::PWM& gpio) const noexcept { }
Expand Down Expand Up @@ -467,7 +490,9 @@ class AddPortDialog : public QDialog
QWidget m_gpioWidget;
QFormLayout m_gpioLayout;
QHBoxLayout m_gpioInOutLayout;
QHBoxLayout m_gpioPullLayout;
QRadioButton m_gpioIn, m_gpioOut;
QCheckBox m_gpioPullUp, m_gpioPullDown;

const SimpleIOData* m_currentNode{};
};
Expand Down

0 comments on commit e63403f

Please sign in to comment.