Files
@ 73e46f8f1ad6
Branch filter:
Location: tempo-plotter/src/abstractreader.h
73e46f8f1ad6
2.6 KiB
text/plain
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | /*
Copyright © 2017 Hasan Yavuz Özderya
This file is part of serialplot.
serialplot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
serialplot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with serialplot. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ABSTRACTREADER_H
#define ABSTRACTREADER_H
#include <QObject>
#include <QIODevice>
#include <QWidget>
#include <QTimer>
#include "channelmanager.h"
#include "datarecorder.h"
/**
* All reader classes must inherit this class.
*/
class AbstractReader : public QObject
{
Q_OBJECT
public:
explicit AbstractReader(QIODevice* device, ChannelManager* channelMan,
DataRecorder* recorder, QObject* parent = 0);
bool recording; /// is recording started
/**
* Returns a widget to be shown in data format panel when reader
* is selected.
*/
virtual QWidget* settingsWidget() = 0;
/**
* Number of channels being read.
*
* This number may be user selected or automatically determined
* from incoming stream.
*/
virtual unsigned numOfChannels() = 0;
/// Reader should only read when enabled. Default state should be
/// 'disabled'.
virtual void enable(bool enabled = true) = 0;
/**
* @brief Starts sending data to recorder.
*
* @note recorder must have been started!
*/
void startRecording();
/// Stops recording.
void stopRecording();
signals:
void numOfChannelsChanged(unsigned);
void samplesPerSecondChanged(unsigned);
public slots:
/**
* Pauses the reading.
*
* Reader should actually continue reading to keep the
* synchronization but shouldn't commit data.
*/
virtual void pause(bool) = 0;
protected:
QIODevice* _device;
/// Should be called with read data
void addData(double* samples, unsigned length);
private:
const int SPS_UPDATE_TIMEOUT = 1; // second
unsigned sampleCount;
unsigned samplesPerSecond;
ChannelManager* _channelMan;
DataRecorder* _recorder;
QTimer spsTimer;
private slots:
void spsTimerTimeout();
};
#endif // ABSTRACTREADER_H
|