Files
UvosSmartHomeInterface/serialwatcher.cpp
2017-11-02 20:17:05 +01:00

37 lines
601 B
C++

#include "serialwatcher.h"
void SerialWatcher::run()
{
abort();
loop.reset(new QEventLoop);
QTimer timer;
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
timer.setInterval(500);
timer.start();
loop->exec();
}
void SerialWatcher::abort()
{
if (!loop.isNull()){
loop->quit();
}
}
void SerialWatcher::doTick()
{
char charBuf;
while(sRead(_serial, &charBuf, 1) == 1)
{
_buffer.push_back(charBuf);
if( _buffer.endsWith('\n') )
{
textRecived(_buffer);
_buffer.clear();
}
}
}