-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathqin.cpp
More file actions
31 lines (27 loc) · 687 Bytes
/
qin.cpp
File metadata and controls
31 lines (27 loc) · 687 Bytes
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
#include "qin.h"
#include <QtDebug>
#include <iostream.h>
QIn::QIn(QPID *pidPointer, QObject *parent) :
QObject(parent)
{
if(pidPointer)
pid = pidPointer;
else
qDebug() << "PID pointer is null";
timer = new QTimer(this);
timer->setInterval(20); //50Hz
connect(timer, SIGNAL(timeout()), this, SLOT(checkForData()));
timer->start();
}
void QIn::checkForData()
{
//check CIN
QFile in;
in.open(stdin, QIODevice::ReadOnly);
QString inputData = in.readLine(); //BLOCKING
in.close();
if(!inputData.isEmpty()) //if there is new data
{
std::cout << pid->calculate(inputData.toDouble()) << std::endl;
}
}