diff --git a/plugins/swiotrefactor/include/swiotrefactor/ad74413r/ad74413r.h b/plugins/swiotrefactor/include/swiotrefactor/ad74413r/ad74413r.h index d6c08f45c3..bd3860331f 100644 --- a/plugins/swiotrefactor/include/swiotrefactor/ad74413r/ad74413r.h +++ b/plugins/swiotrefactor/include/swiotrefactor/ad74413r/ad74413r.h @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -71,24 +72,24 @@ public Q_SLOTS: void onSamplingFrequencyUpdated(int channelId, int sampFreq); Q_SIGNALS: - void timespanChanged(double val); void broadcastReadThreshold(); - void exportBtnClicked(QMap exportConfig); void activateExportButton(); void activateRunBtns(bool activate); - void backBtnPressed(); + void configBtnPressed(); private Q_SLOTS: - void onBackBtnPressed(); - void refreshSampleRate(); + void onConfigBtnPressed(); void showPlotLabels(bool b); void setupChannel(int chnlIdx, QString function); - void onBufferRefilled(QMap> bufferData); + void onSamplingFreqComputed(double freq); + void onBufferRefilled(QMap> chnlData); void onChannelBtnChecked(int chnWidgetId, bool en); private: + void updateXData(int dataSize); + void plotData(QVector curveData, int chnlIdx); void createDevicesMap(iio_context *ctx); void setupConnections(); void verifyChnlsChanges(); @@ -99,8 +100,9 @@ private Q_SLOTS: void setupDeviceBtn(); void setupChannelBtn(MenuControlButton *btn, PlotChannel *ch, QString chnlId, int chnlIdx); void setupChannelsMenuControlBtn(MenuControlButton *btn, QString name); - QPushButton *createBackBtn(); + QPushButton *createConfigBtn(); QWidget *createSettingsMenu(QWidget *parent); + PlotAxis *createXChnlAxis(QPen pen, int xMin = -1, int xMax = 0); PlotAxis *createYChnlAxis(QPen pen, QString unitType = "V", int yMin = -1, int yMax = 1); private: @@ -116,24 +118,21 @@ private Q_SLOTS: BufferAcquisitionHandler *m_acqHandler; CommandQueue *m_cmdQueue; - // ExportSettings *m_exportSettings; - struct iio_context *m_ctx; Connection *m_conn; - //// - /// \brief Added for the new adinstrument - /// - double m_frequency = 1.0; - double m_sampleRate = 4800; ToolTemplate *m_tool; RunBtn *m_runBtn; SingleShotBtn *m_singleBtn; PrintBtn *m_printBtn; - QPushButton *m_backBtn; - PlotWidget *m_plot; + QPushButton *m_configBtn; GearBtn *m_settingsBtn; + PlotWidget *m_plot; + TimePlotInfo *m_info; + PlotSamplingInfo m_currentSamplingInfo; + QMap m_plotChnls; + QMap m_iioDevicesMap; CollapsableMenuControlButton *m_devBtn; QButtonGroup *m_rightMenuBtnGrp; @@ -141,12 +140,11 @@ private Q_SLOTS: MapStackedWidget *m_channelStack; + bool m_fullyFilled = false; int m_currentChannelSelected = 0; - QMap> m_yValues; QVector m_xTime; const QString channelsMenuId = "channels"; - ///////////////// }; } // namespace swiotrefactor } // namespace scopy diff --git a/plugins/swiotrefactor/include/swiotrefactor/ad74413r/bufferacquisitionhandler.h b/plugins/swiotrefactor/include/swiotrefactor/ad74413r/bufferacquisitionhandler.h index a6d29167f9..5798b1d8fb 100644 --- a/plugins/swiotrefactor/include/swiotrefactor/ad74413r/bufferacquisitionhandler.h +++ b/plugins/swiotrefactor/include/swiotrefactor/ad74413r/bufferacquisitionhandler.h @@ -21,7 +21,6 @@ #ifndef BUFFERACQUISITIONHANDLER_H #define BUFFERACQUISITIONHANDLER_H -//#include "channelplotscalescontroller.h" #include #include #include diff --git a/plugins/swiotrefactor/include/swiotrefactor/ad74413r/buffermenu.h b/plugins/swiotrefactor/include/swiotrefactor/ad74413r/buffermenu.h index e02c4676f8..2f837fd64a 100644 --- a/plugins/swiotrefactor/include/swiotrefactor/ad74413r/buffermenu.h +++ b/plugins/swiotrefactor/include/swiotrefactor/ad74413r/buffermenu.h @@ -46,6 +46,7 @@ class BufferMenu : public QWidget public Q_SLOTS: virtual void onBroadcastThreshold(); + void onRunBtnsPressed(bool en); Q_SIGNALS: void broadcastThreshold(); @@ -53,6 +54,7 @@ public Q_SLOTS: void samplingFrequencyUpdated(int sr); protected: + IIOWidget *m_samplingFreq; QString m_chnlFunction; Connection *m_connection; QMap m_chnls; diff --git a/plugins/swiotrefactor/include/swiotrefactor/ad74413r/buffermenuview.h b/plugins/swiotrefactor/include/swiotrefactor/ad74413r/buffermenuview.h index 9c848915b0..da4cf04383 100644 --- a/plugins/swiotrefactor/include/swiotrefactor/ad74413r/buffermenuview.h +++ b/plugins/swiotrefactor/include/swiotrefactor/ad74413r/buffermenuview.h @@ -52,6 +52,8 @@ class BufferMenuView : public QWidget void broadcastThresholdForward(); void broadcastThresholdBackward(); + void runBtnsPressed(bool en); + private: void createConnections(); QWidget *createDescriptionSection(QWidget *parent); diff --git a/plugins/swiotrefactor/src/ad74413r/ad74413r.cpp b/plugins/swiotrefactor/src/ad74413r/ad74413r.cpp index 0202b5e788..8efa209e84 100644 --- a/plugins/swiotrefactor/src/ad74413r/ad74413r.cpp +++ b/plugins/swiotrefactor/src/ad74413r/ad74413r.cpp @@ -24,6 +24,7 @@ #include "swiot_logging_categories.h" #include +#include #include #include @@ -68,7 +69,7 @@ Ad74413r::Ad74413r(QString uri, ToolMenuEntry *tme, QWidget *parent) m_swiotAdLogic->initAd74413rChnlsFunctions(); } } - this->initTutorialProperties(); + initTutorialProperties(); } Ad74413r::~Ad74413r() @@ -91,37 +92,32 @@ void Ad74413r::handleConnectionDestroyed() void Ad74413r::setupConnections() { connect(m_conn, &Connection::aboutToBeDestroyed, m_readerThread, &ReaderThread::handleConnectionDestroyed); - connect(m_backBtn, &QPushButton::pressed, this, &Ad74413r::onBackBtnPressed); + connect(m_configBtn, &QPushButton::pressed, this, &Ad74413r::onConfigBtnPressed); connect(m_runBtn, &QPushButton::toggled, this, &Ad74413r::onRunBtnPressed); + connect(m_singleBtn, &QPushButton::toggled, this, &Ad74413r::onSingleBtnPressed); + connect(m_swiotAdLogic, &BufferLogic::chnlsChanged, m_readerThread, &ReaderThread::onChnlsChange); - connect(m_swiotAdLogic, &BufferLogic::samplingFrequencyComputed, m_acqHandler, - &BufferAcquisitionHandler::onSamplingFrequencyComputed); - connect(m_swiotAdLogic, &BufferLogic::samplingFrequencyComputed, this, [=, this](double frequency) { - m_frequency = frequency; - refreshSampleRate(); - }); connect(m_swiotAdLogic, &BufferLogic::samplingFrequencyComputed, m_readerThread, &ReaderThread::onSamplingFrequencyComputed); + connect(m_swiotAdLogic, &BufferLogic::samplingFrequencyComputed, m_acqHandler, + &BufferAcquisitionHandler::onSamplingFrequencyComputed); + + connect(m_swiotAdLogic, &BufferLogic::samplingFrequencyComputed, this, &Ad74413r::onSamplingFreqComputed); connect(this, &Ad74413r::activateRunBtns, this, &Ad74413r::onActivateRunBtns); + connect(m_swiotAdLogic, &BufferLogic::channelFunctionDetermined, this, &Ad74413r::setupChannel); + connect(m_tme, &ToolMenuEntry::runToggled, m_runBtn, &QPushButton::setChecked); + connect(m_readerThread, &ReaderThread::bufferRefilled, m_acqHandler, &BufferAcquisitionHandler::onBufferRefilled, Qt::QueuedConnection); connect(m_readerThread, &ReaderThread::readerThreadFinished, this, &Ad74413r::onReaderThreadFinished, Qt::QueuedConnection); - - connect(m_singleBtn, &QPushButton::toggled, this, &Ad74413r::onSingleBtnPressed); - connect(m_acqHandler, &BufferAcquisitionHandler::singleCaptureFinished, this, - &Ad74413r::onSingleCaptureFinished); - connect(this, &Ad74413r::timespanChanged, m_acqHandler, &BufferAcquisitionHandler::onTimespanChanged); - connect(this, &Ad74413r::timespanChanged, this, &Ad74413r::refreshSampleRate); - - connect(m_swiotAdLogic, &BufferLogic::channelFunctionDetermined, this, &Ad74413r::setupChannel); - - connect(m_tme, &ToolMenuEntry::runToggled, m_runBtn, &QPushButton::setChecked); connect(m_acqHandler, &BufferAcquisitionHandler::bufferDataReady, this, &Ad74413r::onBufferRefilled); + connect(m_acqHandler, &BufferAcquisitionHandler::singleCaptureFinished, this, + &Ad74413r::onSingleCaptureFinished, Qt::QueuedConnection); - // connect(m_toolView->getPrintBtn(), &QPushButton::clicked, m_acqHandler, - //&BufferAcquisitionHandler::onPrintBtnClicked); + connect(m_timespanSpin, &PositionSpinButton::valueChanged, m_acqHandler, + &BufferAcquisitionHandler::onTimespanChanged); } void Ad74413r::onChannelBtnChecked(int chnlIdx, bool en) @@ -203,19 +199,6 @@ void Ad74413r::onSingleBtnPressed(bool toggled) } } -void Ad74413r::onSingleCaptureFinished() -{ - bool runBtnChecked = m_runBtn->isChecked(); - if(!runBtnChecked) { - if(m_tme->running()) { - m_tme->setRunning(false); - } - m_singleBtn->setEnabled(true); - } - m_readerThread->requestStop(); - m_singleBtn->setChecked(false); -} - void Ad74413r::verifyChnlsChanges() { bool changes = m_swiotAdLogic->verifyChannelsEnabledChanges(m_enabledChannels); @@ -239,6 +222,32 @@ void Ad74413r::createDevicesMap(iio_context *ctx) } } +void Ad74413r::onSamplingFrequencyUpdated(int channelId, int value) +{ + m_readerThread->requestStop(); + m_swiotAdLogic->applySamplingFrequencyChanges(channelId, value); +} + +void Ad74413r::onDiagnosticFunctionUpdated() +{ + m_readerThread->requestStop(); + m_swiotAdLogic->applyChannelsEnabledChanges(m_enabledChannels); +} + +void Ad74413r::onConfigBtnPressed() +{ + bool runBtnChecked = m_runBtn->isChecked(); + bool singleBtnChecked = m_singleBtn->isChecked(); + + if(runBtnChecked) { + m_runBtn->setChecked(false); + } + if(singleBtnChecked) { + m_singleBtn->setChecked(false); + } + Q_EMIT configBtnPressed(); +} + void Ad74413r::onReaderThreadFinished() { bool singleCaptureOn = m_acqHandler->singleCapture(); @@ -256,50 +265,71 @@ void Ad74413r::onReaderThreadFinished() } } -void Ad74413r::onSamplingFrequencyUpdated(int channelId, int value) +void Ad74413r::onSingleCaptureFinished() { + bool runBtnChecked = m_runBtn->isChecked(); + if(!runBtnChecked) { + if(m_tme->running()) { + m_tme->setRunning(false); + } + m_singleBtn->setEnabled(true); + } m_readerThread->requestStop(); - m_swiotAdLogic->applySamplingFrequencyChanges(channelId, value); + m_singleBtn->setChecked(false); } -void Ad74413r::onDiagnosticFunctionUpdated() +void Ad74413r::updateXData(int dataSize) { - m_readerThread->requestStop(); - m_swiotAdLogic->applyChannelsEnabledChanges(m_enabledChannels); + double timespanValue = m_timespanSpin->value(); + double plotSamples = m_currentSamplingInfo.sampleRate * timespanValue; + if(m_xTime.size() == plotSamples && dataSize == plotSamples) { + return; + } + m_xTime.clear(); + for(int i = dataSize - 1; i >= 0; i--) { + m_xTime.push_back(-(i / plotSamples) * timespanValue); + } } -void Ad74413r::onBackBtnPressed() +void Ad74413r::plotData(QVector chnlData, int chnlIdx) { - bool runBtnChecked = m_runBtn->isChecked(); - bool singleBtnChecked = m_singleBtn->isChecked(); + int dataSize = chnlData.size(); + updateXData(dataSize); + m_plotChnls[chnlIdx]->curve()->setSamples(m_xTime.data(), chnlData.data(), dataSize); + m_currentSamplingInfo.plotSize = dataSize; + m_info->update(m_currentSamplingInfo); +} - if(runBtnChecked) { - m_runBtn->setChecked(false); - } - if(singleBtnChecked) { - m_singleBtn->setChecked(false); +void Ad74413r::onBufferRefilled(QMap> bufferData) +{ + QList chnls = m_plotChnls.keys(); + int dataIdx = 0; + for(int chnlIdx : chnls) { + if(!m_enabledChannels[chnlIdx]) { + continue; + } + plotData(bufferData[dataIdx], chnlIdx); + dataIdx++; } - Q_EMIT backBtnPressed(); + m_plot->replot(); } -void Ad74413r::initTutorialProperties() +void Ad74413r::onSamplingFreqComputed(double freq) { - // initialize components that might be used for the AD74413R tutorial - m_plot->setProperty("tutorial_name", "AD74413R_PLOT"); - m_singleBtn->setProperty("tutorial_name", "SINGLE_BUTTON"); - m_runBtn->setProperty("tutorial_name", "RUN_BUTTON"); - m_settingsBtn->setProperty("tutorial_name", "AD74413R_SETTINGS"); - m_backBtn->setProperty("tutorial_name", "CONFIG_BUTTON"); + m_currentSamplingInfo.sampleRate = freq; + m_info->update(m_currentSamplingInfo); } void Ad74413r::initPlotData() { + m_currentSamplingInfo.startingPoint = 0; + m_currentSamplingInfo.plotSize = 0; + m_currentSamplingInfo.sampleRate = MAX_SAMPLE_RATE; + m_currentSamplingInfo.freqOffset = 0; + m_xTime.clear(); - for(int i = 0; i < m_sampleRate; i++) { - m_xTime.push_back(-(i / m_sampleRate)); - } - for(int i = 0; i < MAX_CURVES_NUMBER; i++) { - m_yValues[i] = QVector(); + for(int i = m_currentSamplingInfo.sampleRate - 1; i >= 0; i--) { + m_xTime.push_back(-(i / m_currentSamplingInfo.sampleRate)); } } @@ -308,34 +338,27 @@ void Ad74413r::initPlot() m_plot->xAxis()->setInterval(-1, 0); m_plot->xAxis()->scaleDraw()->setFormatter(new MetricPrefixFormatter()); m_plot->xAxis()->scaleDraw()->setFloatPrecision(2); + m_plot->xAxis()->setVisible(false); + m_plot->yAxis()->setVisible(false); m_plot->leftHandlesArea()->setVisible(true); m_plot->replot(); } -void Ad74413r::onBufferRefilled(QMap> bufferData) +void Ad74413r::showPlotLabels(bool b) { - const QList chList = m_yValues.keys(); - for(const int &ch : chList) { - m_yValues[ch].clear(); - m_yValues[ch] = bufferData[ch]; - } - - QList chnls = m_plot->getChannels(); - for(int chnlIdx = 0; chnlIdx < chnls.size(); chnlIdx++) { - chnls[chnlIdx]->curve()->setRawSamples(m_xTime.data(), m_yValues[chnlIdx].data(), - m_yValues[chnlIdx].size()); - } - m_plot->replot(); + m_plot->setShowXAxisLabels(b); + m_plot->setShowYAxisLabels(b); + m_plot->showAxisLabels(); } -void Ad74413r::refreshSampleRate() +PlotAxis *Ad74413r::createXChnlAxis(QPen pen, int xMin, int xMax) { - double timespanValue = m_timespanSpin->value(); - m_sampleRate = m_frequency * timespanValue; - m_xTime.clear(); - for(int i = 0; i < m_sampleRate; i++) { - m_xTime.push_back(-(i / m_sampleRate) * timespanValue); - } + PlotAxis *chXAxis = new PlotAxis(QwtAxis::XBottom, m_plot, pen); + chXAxis->setVisible(false); + chXAxis->setInterval(xMin, xMax); + chXAxis->scaleDraw()->setFormatter(new MetricPrefixFormatter()); + chXAxis->scaleDraw()->setFloatPrecision(2); + return chXAxis; } PlotAxis *Ad74413r::createYChnlAxis(QPen pen, QString unitType, int yMin, int yMax) @@ -370,12 +393,15 @@ void Ad74413r::setupChannelBtn(MenuControlButton *btn, PlotChannel *ch, QString } }); - connect(btn->checkBox(), &QCheckBox::toggled, this, [=, this](bool en) { - ch->handle()->handle()->setVisible(en); - ch->setEnabled(en); - onChannelBtnChecked(chnlIdx, en); - m_plot->replot(); - }); + connect( + btn->checkBox(), &QCheckBox::toggled, this, + [=, this](bool en) { + onChannelBtnChecked(chnlIdx, en); + ch->handle()->handle()->setVisible(en); + ch->setEnabled(en); + m_plot->replot(); + }, + Qt::DirectConnection); } void Ad74413r::setupChannel(int chnlIdx, QString function) @@ -387,16 +413,17 @@ void Ad74413r::setupChannel(int chnlIdx, QString function) QString unit = m_swiotAdLogic->getPlotChnlUnitOfMeasure(chnlIdx); auto yRange = m_swiotAdLogic->getPlotChnlRangeValues(chnlIdx); + // PlotAxis *chXAxis = createXChnlAxis(chPen); PlotAxis *chYAxis = createYChnlAxis(chPen, unit, yRange.first, yRange.second); PlotChannel *plotCh = new PlotChannel(chnlId, chPen, m_plot, m_plot->xAxis(), chYAxis, this); plotCh->setEnabled(false); - plotCh->curve()->setRawSamples(m_xTime.data(), m_yValues[chnlIdx].data(), m_yValues[chnlIdx].size()); PlotAxisHandle *chHandle = new PlotAxisHandle(chPen, chYAxis, m_plot, QwtAxis::YLeft, this); chHandle->handle()->setVisible(false); plotCh->setHandle(chHandle); m_plot->addPlotAxisHandle(chHandle); m_plot->addPlotChannel(plotCh); + m_plotChnls.insert(chnlIdx, plotCh); QMap chnlsMap = m_swiotAdLogic->getIioChnl(chnlIdx); BufferMenuView *menu = new BufferMenuView(chnlsMap, m_conn, this); @@ -408,13 +435,17 @@ void Ad74413r::setupChannel(int chnlIdx, QString function) m_chnlsBtnGroup->addButton(btn); setupChannelBtn(btn, plotCh, chnlId, chnlIdx); + connect(m_runBtn, &QPushButton::toggled, menu, &BufferMenuView::runBtnsPressed); + connect(m_singleBtn, &QPushButton::toggled, menu, &BufferMenuView::runBtnsPressed); + connect(menu, &BufferMenuView::setYMin, chYAxis, &PlotAxis::setMin); connect(chYAxis, &PlotAxis::minChanged, this, [=, this]() { Q_EMIT menu->minChanged(chYAxis->min()); }); connect(menu, &BufferMenuView::setYMax, chYAxis, &PlotAxis::setMax); connect(chYAxis, &PlotAxis::maxChanged, this, [=, this]() { Q_EMIT menu->maxChanged(chYAxis->max()); }); - connect(menu, &BufferMenuView::samplingFrequencyUpdated, this, - [=, this](int sr) { onSamplingFrequencyUpdated(chnlIdx, sr); }); + connect( + menu, &BufferMenuView::samplingFrequencyUpdated, this, + [=, this](int sr) { onSamplingFrequencyUpdated(chnlIdx, sr); }, Qt::DirectConnection); connect(menu, &BufferMenuView::diagnosticFunctionUpdated, this, &Ad74413r::onDiagnosticFunctionUpdated); connect(menu, &BufferMenuView::broadcastThresholdForward, this, &Ad74413r::broadcastReadThreshold); connect(this, &Ad74413r::broadcastReadThreshold, menu, &BufferMenuView::broadcastThresholdBackward); @@ -467,6 +498,8 @@ void Ad74413r::setupToolTemplate() layout->addWidget(m_tool); m_plot = new PlotWidget(this); + m_info = new TimePlotInfo(m_plot, this); + m_plot->addPlotInfoSlot(m_info); initPlot(); setupDeviceBtn(); m_tool->addWidgetToCentralContainerHelper(m_plot); @@ -479,7 +512,7 @@ void Ad74413r::setupToolTemplate() m_singleBtn->setEnabled(false); m_singleBtn->setChecked(false); m_printBtn = new PrintBtn(this); - m_backBtn = createBackBtn(); + m_configBtn = createConfigBtn(); MenuControlButton *chnlsMenuBtn = new MenuControlButton(this); setupChannelsMenuControlBtn(chnlsMenuBtn, "Channels"); @@ -514,24 +547,17 @@ void Ad74413r::setupToolTemplate() m_tool->addWidgetToTopContainerHelper(m_runBtn, TTA_RIGHT); m_tool->addWidgetToTopContainerHelper(m_singleBtn, TTA_RIGHT); m_tool->addWidgetToTopContainerHelper(m_printBtn, TTA_LEFT); - m_tool->addWidgetToTopContainerHelper(m_backBtn, TTA_LEFT); + m_tool->addWidgetToTopContainerHelper(m_configBtn, TTA_LEFT); } -QPushButton *Ad74413r::createBackBtn() +QPushButton *Ad74413r::createConfigBtn() { - QPushButton *backBtn = new QPushButton(); - StyleHelper::BlueGrayButton(backBtn, "back_btn"); - backBtn->setFixedWidth(128); - backBtn->setCheckable(false); - backBtn->setText("Back"); - return backBtn; -} - -void Ad74413r::showPlotLabels(bool b) -{ - m_plot->setShowXAxisLabels(b); - m_plot->setShowYAxisLabels(b); - m_plot->showAxisLabels(); + QPushButton *configBtn = new QPushButton(); + StyleHelper::BlueGrayButton(configBtn, "config_btn"); + configBtn->setFixedWidth(128); + configBtn->setCheckable(false); + configBtn->setText("Config"); + return configBtn; } QWidget *Ad74413r::createSettingsMenu(QWidget *parent) @@ -555,7 +581,6 @@ QWidget *Ad74413r::createSettingsMenu(QWidget *parent) m_timespanSpin->setValue(1); connect(m_timespanSpin, &PositionSpinButton::valueChanged, this, [=, this](double value) { m_plot->xAxis()->setMin(-value); }); - connect(m_timespanSpin, &PositionSpinButton::valueChanged, this, &Ad74413r::timespanChanged); // show labels MenuOnOffSwitch *showLabels = new MenuOnOffSwitch("PLOT LABELS", plotTimespanSection); @@ -573,3 +598,13 @@ QWidget *Ad74413r::createSettingsMenu(QWidget *parent) return widget; } + +void Ad74413r::initTutorialProperties() +{ + // initialize components that might be used for the AD74413R tutorial + m_plot->setProperty("tutorial_name", "AD74413R_PLOT"); + m_singleBtn->setProperty("tutorial_name", "SINGLE_BUTTON"); + m_runBtn->setProperty("tutorial_name", "RUN_BUTTON"); + m_settingsBtn->setProperty("tutorial_name", "AD74413R_SETTINGS"); + m_configBtn->setProperty("tutorial_name", "CONFIG_BUTTON"); +} diff --git a/plugins/swiotrefactor/src/ad74413r/bufferacquisitionhandler.cpp b/plugins/swiotrefactor/src/ad74413r/bufferacquisitionhandler.cpp index 52a74ccb08..edbd76c720 100644 --- a/plugins/swiotrefactor/src/ad74413r/bufferacquisitionhandler.cpp +++ b/plugins/swiotrefactor/src/ad74413r/bufferacquisitionhandler.cpp @@ -45,16 +45,16 @@ void BufferAcquisitionHandler::onBufferRefilled(QMap> buffe m_lock->lock(); if(!(m_singleCapture && (m_bufferIndex == m_buffersNumber))) { if(bufferDataSize > 0) { + int samplingFreq = m_plotSamplingFreq * m_timespan; QList keys = bufferData.keys(); for(const auto &key : keys) { - if(m_bufferIndex == m_buffersNumber) { - if(m_dataPoints[key].size() >= m_bufferSize) { - m_dataPoints[key].erase(m_dataPoints[key].begin(), - m_dataPoints[key].begin() + m_bufferSize); - rolling = true; - } - } m_dataPoints[key].append(bufferData[key]); + int unnecessarySamples = m_dataPoints[key].size() % samplingFreq; + if(m_dataPoints[key].size() > samplingFreq) { + m_dataPoints[key].erase(m_dataPoints[key].begin(), + m_dataPoints[key].begin() + unnecessarySamples); + } + rolling = (m_bufferIndex == m_buffersNumber); } } m_bufferIndex = (rolling) ? m_bufferIndex : m_bufferIndex + 1; diff --git a/plugins/swiotrefactor/src/ad74413r/buffermenu.cpp b/plugins/swiotrefactor/src/ad74413r/buffermenu.cpp index 2ee51b1fa5..5b2dfc3c3a 100644 --- a/plugins/swiotrefactor/src/ad74413r/buffermenu.cpp +++ b/plugins/swiotrefactor/src/ad74413r/buffermenu.cpp @@ -25,6 +25,7 @@ #include #include #include +#include using namespace scopy::swiotrefactor; BufferMenu::BufferMenu(QWidget *parent, QString chnlFunction, Connection *conn, QMap chnls) @@ -36,17 +37,17 @@ BufferMenu::BufferMenu(QWidget *parent, QString chnlFunction, Connection *conn, if(m_chnls.contains(INPUT_CHNL)) { // channels sampling freq - input channel - IIOWidget *samplingFreq = + m_samplingFreq = IIOWidgetFactory::buildSingle(IIOWidgetFactory::CMDQAttrData | IIOWidgetFactory::ComboUi, {.connection = const_cast(m_connection), .channel = const_cast(m_chnls[INPUT_CHNL]), .data = "sampling_frequency", .iioDataOptions = "sampling_frequency_available"}, this); - samplingFreq->getDataStrategy()->requestData(); - addMenuWidget(samplingFreq); + m_samplingFreq->getDataStrategy()->requestData(); + addMenuWidget(m_samplingFreq); - connect(dynamic_cast(samplingFreq->getDataStrategy()), + connect(dynamic_cast(m_samplingFreq->getDataStrategy()), &CmdQChannelAttrDataStrategy::sendData, this, [=, this](QString data, QString dataOptions) { Q_EMIT samplingFrequencyUpdated(data.toInt()); }); @@ -67,6 +68,11 @@ void BufferMenu::addMenuWidget(QWidget *widget) { m_widgetsList.push_back(widget void BufferMenu::onBroadcastThreshold() {} +void BufferMenu::onRunBtnsPressed(bool en) +{ + dynamic_cast(m_samplingFreq->getUiStrategy())->ui()->setEnabled(!en); +} + QList BufferMenu::getWidgetsList() { return m_widgetsList; } CurrentInLoopMenu::CurrentInLoopMenu(QWidget *parent, QString chnlFunction, Connection *conn, diff --git a/plugins/swiotrefactor/src/ad74413r/buffermenuview.cpp b/plugins/swiotrefactor/src/ad74413r/buffermenuview.cpp index 8bd86c3fdd..eb44a7b4fa 100644 --- a/plugins/swiotrefactor/src/ad74413r/buffermenuview.cpp +++ b/plugins/swiotrefactor/src/ad74413r/buffermenuview.cpp @@ -78,6 +78,8 @@ void BufferMenuView::createConnections() connect(m_swiotAdvMenu, &BufferMenu::samplingFrequencyUpdated, this, &BufferMenuView::samplingFrequencyUpdated); connect(m_swiotAdvMenu, &BufferMenu::broadcastThreshold, this, &BufferMenuView::broadcastThresholdForward); connect(this, &BufferMenuView::broadcastThresholdBackward, m_swiotAdvMenu, &BufferMenu::onBroadcastThreshold); + + connect(this, &BufferMenuView::runBtnsPressed, m_swiotAdvMenu, &BufferMenu::onRunBtnsPressed); } QWidget *BufferMenuView::createDescriptionSection(QWidget *parent)