# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2016-06-14 21:47:29 # Node ID ce36704ede6f075caaa2a34c7acc140e55559449 # Parent 556aa6f2471310462379f9af43bb3a87198c2c9f number of channels will be determined automatically from input data for ascii diff --git a/src/asciireader.cpp b/src/asciireader.cpp --- a/src/asciireader.cpp +++ b/src/asciireader.cpp @@ -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); diff --git a/src/asciireader.h b/src/asciireader.h --- a/src/asciireader.h +++ b/src/asciireader.h @@ -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 diff --git a/src/asciireadersettings.ui b/src/asciireadersettings.ui --- a/src/asciireadersettings.ui +++ b/src/asciireadersettings.ui @@ -44,13 +44,16 @@ - Select number of channels + Select number of channels or set to 0 for Auto (determined from incoming data) + + + Auto false - 1 + 0 32