Changeset - ce36704ede6f
[Not reviewed]
default
0 3 0
Hasan Yavuz Ă–ZDERYA - 9 years ago 2016-06-14 21:47:29
hy@ozderya.net
number of channels will be determined automatically from input data for ascii
3 files changed with 41 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/asciireader.cpp
Show inline comments
 
@@ -21,6 +21,9 @@
 

	
 
#include "asciireader.h"
 

	
 
/// If set to this value number of channels is determined from input
 
#define NUMOFCHANNELS_AUTO   (0)
 

	
 
AsciiReader::AsciiReader(QIODevice* device, ChannelManager* channelMan, QObject *parent) :
 
    AbstractReader(device, channelMan, parent)
 
{
 
@@ -29,10 +32,23 @@ AsciiReader::AsciiReader(QIODevice* devi
 
    sampleCount = 0;
 

	
 
    _numOfChannels = _settingsWidget.numOfChannels();
 
    autoNumOfChannels = (_numOfChannels == NUMOFCHANNELS_AUTO);
 
    // do not allow '0'
 
    if (_numOfChannels == 0)
 
    {
 
        _numOfChannels = 1;
 
    }
 

	
 
    connect(&_settingsWidget, &AsciiReaderSettings::numOfChannelsChanged,
 
            this, &AsciiReader::numOfChannelsChanged);
 
    connect(&_settingsWidget, &AsciiReaderSettings::numOfChannelsChanged,
 
            [this](unsigned value){_numOfChannels = value;});
 
            [this](unsigned value)
 
            {
 
                _numOfChannels = value;
 
                autoNumOfChannels = (_numOfChannels == NUMOFCHANNELS_AUTO);
 
                if (!autoNumOfChannels)
 
                {
 
                    emit numOfChannelsChanged(value);
 
                }
 
            });
 

	
 
    connect(device, &QIODevice::aboutToClose, [this](){discardFirstLine=true;});
 
}
 
@@ -99,8 +115,20 @@ void AsciiReader::onDataReady()
 

	
 
        auto separatedValues = line.split(',');
 

	
 
        int numReadChannels; // effective number of channels to read
 
        if (separatedValues.length() >= int(_numOfChannels))
 
        unsigned numReadChannels; // effective number of channels to read
 
        unsigned numComingChannels = separatedValues.length();
 

	
 
        if (autoNumOfChannels)
 
        {
 
            // did number of channels changed?
 
            if (numComingChannels != _numOfChannels)
 
            {
 
                _numOfChannels = numComingChannels;
 
                emit numOfChannelsChanged(numComingChannels);
 
            }
 
            numReadChannels = numComingChannels;
 
        }
 
        else if (numComingChannels >= _numOfChannels)
 
        {
 
            numReadChannels = _numOfChannels;
 
        }
 
@@ -111,7 +139,7 @@ void AsciiReader::onDataReady()
 
        }
 

	
 
        // parse read line
 
        for (int ci = 0; ci < numReadChannels; ci++)
 
        for (unsigned ci = 0; ci < numReadChannels; ci++)
 
        {
 
            bool ok;
 
            double channelSample = separatedValues[ci].toDouble(&ok);
src/asciireader.h
Show inline comments
 
@@ -39,6 +39,8 @@ public slots:
 
private:
 
    AsciiReaderSettings _settingsWidget;
 
    unsigned _numOfChannels;
 
    /// number of channels will be determined from incoming data
 
    unsigned autoNumOfChannels;
 
    bool paused;
 

	
 
    // We may have (usually true) started reading in the middle of a
src/asciireadersettings.ui
Show inline comments
 
@@ -44,13 +44,16 @@
 
        </size>
 
       </property>
 
       <property name="toolTip">
 
        <string>Select number of channels</string>
 
        <string>Select number of channels or set to 0 for Auto (determined from incoming data)</string>
 
       </property>
 
       <property name="specialValueText">
 
        <string>Auto</string>
 
       </property>
 
       <property name="keyboardTracking">
 
        <bool>false</bool>
 
       </property>
 
       <property name="minimum">
 
        <number>1</number>
 
        <number>0</number>
 
       </property>
 
       <property name="maximum">
 
        <number>32</number>
0 comments (0 inline, 0 general)