Changeset - e70ba1409177
[Not reviewed]
recording
0 5 0
Hasan Yavuz Ă–ZDERYA - 9 years ago 2017-02-14 09:42:52
hy@ozderya.net
added checkbox to disable write buffering
5 files changed with 22 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/abstractreader.cpp
Show inline comments
 
@@ -16,14 +16,12 @@
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "abstractreader.h"
 

	
 
#include <QtDebug>
 

	
 
AbstractReader::AbstractReader(QIODevice* device, ChannelManager* channelMan,
 
                               DataRecorder* recorder, QObject* parent) :
 
    QObject(parent)
 
{
 
    _device = device;
 
    _channelMan = channelMan;
 
@@ -53,10 +51,9 @@ void AbstractReader::spsTimerTimeout()
 
void AbstractReader::addData(double* samples, unsigned length)
 
{
 
    _channelMan->addData(samples, length);
 
    if (recording)
 
    {
 
        _recorder->addData(samples, length, numOfChannels());
 
        qDebug() << "adding data";
 
    }
 
    sampleCount += length;
 
}
src/datarecorder.cpp
Show inline comments
 
@@ -23,12 +23,13 @@
 

	
 
DataRecorder::DataRecorder(QObject *parent) :
 
    QObject(parent),
 
    fileStream(&file)
 
{
 
    lastNumChannels = 0;
 
    disableBuffering = false;
 
}
 

	
 
bool DataRecorder::startRecording(QString fileName, QStringList channelNames)
 
{
 
    Q_ASSERT(!file.isOpen());
 

	
 
@@ -71,12 +72,14 @@ void DataRecorder::addData(double* data,
 
        {
 
            fileStream << data[ci * numOfSamples + i];
 
            if (ci != numOfChannels-1) fileStream << ",";
 
        }
 
        fileStream << '\n';
 
    }
 

	
 
    if (disableBuffering) fileStream.flush();
 
}
 

	
 
void DataRecorder::stopRecording()
 
{
 
    Q_ASSERT(file.isOpen());
 

	
src/datarecorder.h
Show inline comments
 
@@ -27,12 +27,15 @@
 
class DataRecorder : public QObject
 
{
 
    Q_OBJECT
 
public:
 
    explicit DataRecorder(QObject *parent = 0);
 

	
 
    /// Disables file buffering
 
    bool disableBuffering;
 

	
 
    /**
 
     * @brief Starts recording data to a file in CSV format.
 
     *
 
     * File is opened and header line (names of channels) is written.
 
     *
 
     * @param fileName name of the recording file
src/recordpanel.cpp
Show inline comments
 
@@ -50,12 +50,18 @@ RecordPanel::RecordPanel(DataRecorder* r
 
            this, &RecordPanel::selectFile);
 
    connect(&recordAction, &QAction::triggered,
 
            this, &RecordPanel::onRecord);
 

	
 
    connect(ui->cbRecordPaused, SIGNAL(toggled(bool)),
 
            this, SIGNAL(recordPausedChanged(bool)));
 

	
 
    connect(ui->cbDisableBuffering, &QCheckBox::toggled,
 
            [this](bool enabled)
 
            {
 
                _recorder->disableBuffering = enabled;
 
            });
 
}
 

	
 
RecordPanel::~RecordPanel()
 
{
 
    delete ui;
 
}
src/recordpanel.ui
Show inline comments
 
@@ -77,12 +77,22 @@
 
       <property name="checked">
 
        <bool>true</bool>
 
       </property>
 
      </widget>
 
     </item>
 
     <item>
 
      <widget class="QCheckBox" name="cbDisableBuffering">
 
       <property name="toolTip">
 
        <string>Do not buffer when writing to file. Check this if you are using other software to open the file during recording.</string>
 
       </property>
 
       <property name="text">
 
        <string>Disable buffering</string>
 
       </property>
 
      </widget>
 
     </item>
 
     <item>
 
      <spacer name="verticalSpacer">
 
       <property name="orientation">
 
        <enum>Qt::Vertical</enum>
 
       </property>
 
       <property name="sizeHint" stdset="0">
 
        <size>
0 comments (0 inline, 0 general)