# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2015-04-27 17:02:53 # Node ID abcdecae08b49b7bad0b6469d61910f8e991b17f # Parent 950cf3465cfebbb32402feea806455574dc51f96 added simple demo mode for testing diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -179,6 +179,14 @@ MainWindow::MainWindow(QWidget *parent) { selectNumberFormat(NumberFormat_uint8); } + + // Init demo mode + demoCount = 0; + demoTimer.setInterval(100); + QObject::connect(&demoTimer, &QTimer::timeout, + this, &MainWindow::demoTimerTimeout); + QObject::connect(ui->actionDemoMode, &QAction::toggled, + this, &MainWindow::enableDemo); } MainWindow::~MainWindow() @@ -348,6 +356,9 @@ void MainWindow::selectFlowControl(int f void MainWindow::onPortToggled(bool open) { ui->pbOpenPort->setChecked(open); + // make sure demo mode is disabled + if (open && isDemoRunning()) enableDemo(false); + ui->actionDemoMode->setEnabled(!open); } void MainWindow::onDataReady() @@ -605,3 +616,42 @@ template double MainWindow:: this->serialPort.read((char*) &data, sizeof(data)); return double(data); } + +bool MainWindow::isDemoRunning() +{ + return ui->actionDemoMode->isChecked(); +} + +void MainWindow::demoTimerTimeout() +{ + demoCount++; + if (demoCount > 100) demoCount = 0; + + for (int ci = 0; ci < numOfChannels; ci++) + { + DataArray data(1); + data.replace(0, (ci + 1)*demoCount); + addChannelData(ci, data); + } +} + +void MainWindow::enableDemo(bool enabled) +{ + if (enabled) + { + if (!serialPort.isOpen()) + { + demoTimer.start(); + ui->actionDemoMode->setChecked(true); + } + else + { + ui->actionDemoMode->setChecked(false); + } + } + else + { + demoTimer.stop(); + ui->actionDemoMode->setChecked(false); + } +} diff --git a/mainwindow.h b/mainwindow.h --- a/mainwindow.h +++ b/mainwindow.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "ui_about_dialog.h" @@ -86,6 +87,11 @@ private: bool skipByteRequested; + // demo + QTimer demoTimer; + int demoCount; + bool isDemoRunning(); + private slots: void loadPortList(); void loadBaudRateList(); @@ -113,6 +119,9 @@ private slots: void clearPlot(); + void demoTimerTimeout(); + void enableDemo(bool enabled); + signals: void portToggled(bool open); }; diff --git a/mainwindow.ui b/mainwindow.ui --- a/mainwindow.ui +++ b/mainwindow.ui @@ -601,6 +601,7 @@ Help + @@ -640,6 +641,17 @@ About + + + true + + + Demo Mode + + + Toggle Demo Mode + +