Changeset - d92b6daade5d
[Not reviewed]
stream
0 7 0
Hasan Yavuz Ă–ZDERYA - 7 years ago 2018-05-22 15:46:18
hy@ozderya.net
plotting works, only demo is tested

switching readers when demo is enabled breaks demo
7 files changed with 34 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/dataformatpanel.cpp
Show inline comments
 
@@ -47,8 +47,6 @@ DataFormatPanel::DataFormatPanel(QSerial
 
    ui->horizontalLayout->addWidget(bsReader.settingsWidget(), 1);
 
    connect(&bsReader, SIGNAL(numOfChannelsChanged(unsigned)),
 
            this, SIGNAL(numOfChannelsChanged(unsigned)));
 
    connect(&bsReader, SIGNAL(samplesPerSecondChanged(unsigned)),
 
            this, SIGNAL(samplesPerSecondChanged(unsigned)));
 

	
 
    // initalize reader selection buttons
 
    connect(ui->rbBinary, &QRadioButton::toggled, [this](bool checked)
 
@@ -98,8 +96,6 @@ void DataFormatPanel::enableDemo(bool en
 
    if (enabled)
 
    {
 
        demoReader.enable();
 
        connect(&demoReader, &DemoReader::samplesPerSecondChanged,
 
                this, &DataFormatPanel::samplesPerSecondChanged);
 
        emit sourceChanged(&demoReader);
 
    }
 
    else
 
@@ -120,8 +116,6 @@ void DataFormatPanel::selectReader(Abstr
 
    disconnect(currentReader, 0, this, 0);
 
    connect(reader, SIGNAL(numOfChannelsChanged(unsigned)),
 
            this, SIGNAL(numOfChannelsChanged(unsigned)));
 
    connect(reader, SIGNAL(samplesPerSecondChanged(unsigned)),
 
            this, SIGNAL(samplesPerSecondChanged(unsigned)));
 

	
 
    // switch the settings widget
 
    ui->horizontalLayout->removeWidget(currentReader->settingsWidget());
src/mainwindow.cpp
Show inline comments
 
@@ -206,7 +206,7 @@ MainWindow::MainWindow(QWidget *parent) 
 
    connect(&serialPort, &QIODevice::aboutToClose,
 
            &recordPanel, &RecordPanel::onPortClose);
 

	
 
    // init data arrays and plot
 
    // init plot
 
    numOfSamples = plotControlPanel.numOfSamples();
 
    stream.setNumSamples(numOfSamples);
 
    plotControlPanel.setChannelInfoModel(stream.infoModel());
 
@@ -234,6 +234,11 @@ MainWindow::MainWindow(QWidget *parent) 
 
    QObject::connect(ui->actionDemoMode, &QAction::toggled,
 
                     plotMan, &PlotManager::showDemoIndicator);
 

	
 
    // init stream connections
 
    connect(&dataFormatPanel, &DataFormatPanel::sourceChanged,
 
            this, &MainWindow::setStreamSource);
 
    setStreamSource(dataFormatPanel.activeSource());
 

	
 
    // load default settings
 
    QSettings settings("serialplot", "serialplot");
 
    loadAllSettings(&settings);
 
@@ -341,6 +346,18 @@ void MainWindow::onPortToggled(bool open
 
    ui->actionDemoMode->setEnabled(!open);
 
}
 

	
 
void MainWindow::setStreamSource(Source* source)
 
{
 
    // disconnect previous source
 
    auto currentSource = stream.connectedSource();
 
    if (currentSource != nullptr)
 
    {
 
        currentSource->disconnect((Sink*) &stream);
 
    }
 
    // connect to new source
 
    source->connectSink(&stream);
 
}
 

	
 
void MainWindow::clearPlot()
 
{
 
    stream.clear();
src/mainwindow.h
Show inline comments
 
@@ -112,7 +112,7 @@ private:
 

	
 
private slots:
 
    void onPortToggled(bool open);
 

	
 
    void setStreamSource(Source* source);
 
    void onNumOfSamplesChanged(int value);
 

	
 
    void clearPlot();
src/sink.cpp
Show inline comments
 
@@ -55,7 +55,7 @@ void Sink::setNumChannels(unsigned nc, b
 

	
 
void Sink::setSource(const Source* s)
 
{
 
    Q_ASSERT((source == NULL) != (s == NULL));
 
    Q_ASSERT((source == nullptr) != (s == nullptr));
 
    source = s;
 
}
 

	
 
@@ -63,3 +63,8 @@ const Source* Sink::connectedSource() co
 
{
 
    return source;
 
}
 

	
 
Source* Sink::connectedSource()
 
{
 
    return const_cast<Source*>(static_cast<const Sink&>(*this).connectedSource());
 
}
src/sink.h
Show inline comments
 
@@ -39,8 +39,9 @@ public:
 
    /// an error.
 
    void disconnectFollower(Sink* sink);
 

	
 
    /// Returns the connected source. `NULL` if it's not connected.
 
    /// Returns the connected source. `nullptr` if it's not connected.
 
    const Source* connectedSource() const;
 
    Source* connectedSource();
 

	
 
protected:
 
    /// Entry point for incoming data. Re-implementations should
 
@@ -62,7 +63,7 @@ protected:
 

	
 
private:
 
    QList<Sink*> followers;
 
    const Source* source = NULL;   ///< source that this sink is connected to
 
    const Source* source = nullptr;   ///< source that this sink is connected to
 
    bool _hasX;
 
    unsigned _numChannels;
 
};
src/source.cpp
Show inline comments
 
@@ -25,14 +25,14 @@ Source::~Source()
 
{
 
    for (auto sink : sinks)
 
    {
 
        sink->setSource(NULL);
 
        sink->setSource(nullptr);
 
    }
 
}
 

	
 
void Source::connectSink(Sink* sink)
 
{
 
    Q_ASSERT(!sinks.contains(sink));
 
    Q_ASSERT(sink->connectedSource() == NULL);
 
    Q_ASSERT(sink->connectedSource() == nullptr);
 

	
 
    sinks.append(sink);
 
    sink->setSource(this);
 
@@ -44,7 +44,7 @@ void Source::disconnect(Sink* sink)
 
    Q_ASSERT(sinks.contains(sink));
 
    Q_ASSERT(sink->connectedSource() == this);
 

	
 
    sink->setSource(NULL);
 
    sink->setSource(nullptr);
 
    sinks.removeOne(sink);
 
}
 

	
 
@@ -53,7 +53,7 @@ void Source::disconnectSinks()
 
    while (!sinks.isEmpty())
 
    {
 
        auto sink = sinks.takeFirst();
 
        sink->setSource(NULL);
 
        sink->setSource(nullptr);
 
    }
 
}
 

	
src/stream.cpp
Show inline comments
 
@@ -157,6 +157,8 @@ void Stream::feedIn(const SamplePack& da
 
    }
 

	
 
    Sink::feedIn(data);
 

	
 
    emit dataAdded();
 
}
 

	
 
void Stream::pause(bool paused)
0 comments (0 inline, 0 general)