Added frames per second read out. Fixed some crashes.

This commit is contained in:
Collin Kidder
2015-05-24 10:10:27 -04:00
parent f18411c567
commit 06ee0c9301
7 changed files with 66 additions and 13 deletions
+13 -4
View File
@@ -13,6 +13,8 @@ SerialWorker::SerialWorker(CANFrameModel *model, QObject *parent) : QObject(pare
canModel = model;
gotFrames = 0;
ticker = NULL;
elapsedTime = NULL;
framesPerSec = 0;
}
SerialWorker::~SerialWorker()
@@ -69,6 +71,11 @@ void SerialWorker::setSerialPort(QSerialPortInfo *port)
ticker = new QTimer;
connect(ticker, SIGNAL(timeout()), this, SLOT(handleTick()));
}
if (elapsedTime == NULL)
{
elapsedTime = new QTime;
elapsedTime->start();
}
ticker->setInterval(250); //tick four times per second
ticker->setSingleShot(false); //keep ticking
ticker->start();
@@ -341,12 +348,14 @@ void SerialWorker::procRXChar(unsigned char c)
void SerialWorker::handleTick()
{
//qDebug() << "Tick!";
if (gotFrames > 0)
{
emit receivedFrames(); //notify interested parties that there are new frames
framesPerSec += gotFrames * 1000 / elapsedTime->elapsed() - (framesPerSec / 4);
elapsedTime->restart();
//if (gotFrames > 0)
//{
emit receivedFrames(framesPerSec / 4); //misnamed now. Just notifies of FPS and that frames might exist
canModel->sendBulkRefresh(gotFrames);
gotFrames = 0;
}
//}
}
//totally shuts down the whole thing