Changeset - 8fd74552f317
[Not reviewed]
default
0 2 0
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-06-24 03:24:03
hy@ozderya.net
added sample per second counter
2 files changed with 25 insertions and 0 deletions:
0 comments (0 inline, 0 general)
mainwindow.cpp
Show inline comments
 
@@ -136,12 +136,20 @@ MainWindow::MainWindow(QWidget *parent) 
 
    }
 
    else
 
    {
 
        selectNumberFormat(NumberFormat_uint8);
 
    }
 

	
 
    // Init sps (sample per second) counter
 
    sampleCount = 0;
 
    spsLabel.setText("0sps");
 
    ui->statusBar->addPermanentWidget(&spsLabel);
 
    spsTimer.start(SPS_UPDATE_TIMEOUT * 1000);
 
    QObject::connect(&spsTimer, &QTimer::timeout,
 
                     this, &MainWindow::spsTimerTimeout);
 

	
 
    // Init demo mode
 
    demoCount = 0;
 
    demoTimer.setInterval(100);
 
    QObject::connect(&demoTimer, &QTimer::timeout,
 
                     this, &MainWindow::demoTimerTimeout);
 
    QObject::connect(ui->actionDemoMode, &QAction::toggled,
 
@@ -154,12 +162,13 @@ MainWindow::MainWindow(QWidget *parent) 
 
        demoText.setBorderRadius(4);
 
        demoText.setRenderFlags(Qt::AlignLeft | Qt::AlignTop);
 
        demoIndicator.setText(demoText);
 
        demoIndicator.hide();
 
        demoIndicator.attach(ui->plot);
 
    }
 

	
 
}
 

	
 
MainWindow::~MainWindow()
 
{
 
    for (auto curve : curves)
 
    {
 
@@ -374,12 +383,14 @@ void MainWindow::addChannelData(unsigned
 
        }
 
    }
 

	
 
    // update plot
 
    curves[channel]->setSamples(dataX, (*channelDataArray));
 
    ui->plot->replot(); // TODO: replot after all channel data updated
 

	
 
    sampleCount += data.size();
 
}
 

	
 
void MainWindow::clearPlot()
 
{
 
    for (unsigned int ci = 0; ci < numOfChannels; ci++)
 
    {
 
@@ -557,12 +568,18 @@ template<typename T> double MainWindow::
 

	
 
bool MainWindow::isDemoRunning()
 
{
 
    return ui->actionDemoMode->isChecked();
 
}
 

	
 
void MainWindow::spsTimerTimeout()
 
{
 
    spsLabel.setText(QString::number(sampleCount/SPS_UPDATE_TIMEOUT) + "sps");
 
    sampleCount = 0;
 
}
 

	
 
void MainWindow::demoTimerTimeout()
 
{
 
    demoCount++;
 
    if (demoCount > 100) demoCount = 0;
 

	
 
    if (!ui->actionPause->isChecked())
mainwindow.h
Show inline comments
 
@@ -19,12 +19,13 @@
 

	
 
#ifndef MAINWINDOW_H
 
#define MAINWINDOW_H
 

	
 
#include <QMainWindow>
 
#include <QButtonGroup>
 
#include <QLabel>
 
#include <QString>
 
#include <QVector>
 
#include <QList>
 
#include <QSerialPort>
 
#include <QSignalMapper>
 
#include <QTimer>
 
@@ -90,12 +91,17 @@ private:
 

	
 
    // note that serialPort should already have enough bytes present
 
    template<typename T> double readSampleAs();
 

	
 
    bool skipByteRequested;
 

	
 
    const int SPS_UPDATE_TIMEOUT = 1;  // second
 
    QLabel spsLabel;
 
    unsigned int sampleCount;
 
    QTimer spsTimer;
 

	
 
    // demo
 
    QTimer demoTimer;
 
    int demoCount;
 
    bool isDemoRunning();
 
    QwtPlotTextLabel demoIndicator;
 

	
 
@@ -116,12 +122,14 @@ private slots:
 
    void onNumOfChannelsChanged(int value);
 
    void onNumberFormatButtonToggled(int numberFormatId, bool checked);
 
    void selectNumberFormat(NumberFormat numberFormatId);
 

	
 
    void clearPlot();
 

	
 
    void spsTimerTimeout();
 

	
 
    void demoTimerTimeout();
 
    void enableDemo(bool enabled);
 

	
 
    void onExportCsv();
 
};
 

	
0 comments (0 inline, 0 general)