GPIO pins can be accessed and manipulated using the /sys/class/gpio/ pseudo-directory. So the command lines:
Code: Select all
echo 5 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio5/direction
echo true > /sys/class/gpio/gpio5/value
cat /sys/class/gpio/gpio5/value
I thought I could use the class QFileSytemWatcher to monitor input pins by using the kernel's notify system to tell a program that a switch has changed rather than continually monitoring it. To this end I created a program using Qt Creator by selecting New Project->Qt Widgets Application and putting a QLabel widget on the GUI.
I then modified mainwindow.h and mainwindow.cpp as follows
Code: Select all
ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QFileSystemWatcher>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
QFileSystemWatcher watcher;
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void switchChanged(QString);
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
Code: Select all
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileSystemWatcher>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
watcher.addPath ("/sys/class/gpio/gpio5/value");
QObject::connect(&watcher, SIGNAL (fileChanged(QString)),\
this, SLOT (switchChanged(QString)));
ui->setupUi(this);
}
void MainWindow::switchChanged(QString str)
{
ui->label->setText(str);
}
MainWindow::~MainWindow()
{
delete ui;
}
Code: Select all
echo in > /sys/class/gpio/gpio5/direction
However when I executed the command line:
Code: Select all
echo both > /sys/class/gpio/gpio5/edge