-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
41 lines (34 loc) · 961 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <QCoreApplication>
#include <QTextStream>
#include <QFile>
#include <QDebug>
QString readFromFile(const QString &filename);
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString currValue = "";
QString prevValue = "";
forever {
currValue = readFromFile("/sys/class/gpio/gpio128/value");
if (currValue != prevValue) {
qDebug() << "Monitored value is: " << currValue;
prevValue = currValue;
}
}
return a.exec();
}
QString readFromFile(const QString &filename)
{
QFile gpioFile(filename);
if (gpioFile.open(QIODevice::ReadOnly)) {
QTextStream gpioStream(&gpioFile);
QString fileContent = gpioStream.read(1);
gpioFile.close();
return fileContent;
} else {
// qDebug() << "Can't to open file " << filename;
// stopped = true;
// sendSignal("fatalAbort");
return "open error";
}
}