Skip to content

Commit

Permalink
plugins/dac: add a switch to repeat the file buffer for all channels
Browse files Browse the repository at this point in the history
For devices with multiple channels this option will allow the user
to use the same input .csv file for a dynamic number of channels,
without having to duplicate the number of columns in the file.

Signed-off-by: AlexandraTrifan <[email protected]>
  • Loading branch information
AlexandraTrifan committed Feb 10, 2025
1 parent 042be09 commit 9d43e40
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
14 changes: 11 additions & 3 deletions plugins/dac/res/tutorial_chapters.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,38 @@
},
{
"index": 4,
"names": ["REPEAT_FILE_BUFFER_BUTTON"],
"description": "Repeat the data columns from the loaded file to match the number of enabled channels.",
"anchor": "HP_BOTTOM",
"content": "HP_BOTTOM",
"y_offset": 10
},
{
"index": 5,
"names": ["CYCLIC_BUTTON"],
"description": "Select whether to use cyclic or non-cyclic buffer",
"anchor": "HP_BOTTOM",
"content": "HP_BOTTOM",
"y_offset": 10
},
{
"index": 5,
"index": 6,
"names": ["FILESIZE"],
"description": "Displays the number of samples in file, can be used to truncate the file",
"anchor": "HP_BOTTOM",
"content": "HP_BOTTOM",
"y_offset": 10
},
{
"index": 6,
"index": 7,
"names": ["RUN_BUTTON"],
"description": "Start the DAC buffer output.",
"anchor": "HP_BOTTOM",
"content": "HP_BOTTOM",
"y_offset": 10
},
{
"index": 7,
"index": 8,
"names": ["CONSOLE_LOG"],
"description": "Displays information on file load status, buffer output status or other errors.",
"anchor": "HP_TOP",
Expand Down
12 changes: 12 additions & 0 deletions plugins/dac/src/bufferdacaddon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ BufferDacAddon::BufferDacAddon(DacDataModel *model, QWidget *parent)
m_model, &DacDataModel::invalidRunParams, this, [this]() { m_runBtn->setChecked(false); },
Qt::QueuedConnection);

// Repeat file buffer section
MenuSectionWidget *repeatFileBufferContainer = new MenuSectionWidget(this);
repeatFileBufferContainer->setProperty("tutorial_name", "REPEAT_FILE_BUFFER_BUTTON");
m_repeatFileBufferBtn = new MenuOnOffSwitch("Repeat data", repeatFileBufferContainer);
connect(m_repeatFileBufferBtn->onOffswitch(), &QPushButton::toggled, this, [=, this](bool toggled) {
m_model->setRepeatFileBuffer(toggled);
});
repeatFileBufferContainer->contentLayout()->addWidget(m_repeatFileBufferBtn);
repeatFileBufferContainer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
m_repeatFileBufferBtn->onOffswitch()->setChecked(true);

// Cyclic buffer section
MenuSectionWidget *cyclicContainer = new MenuSectionWidget(this);
cyclicContainer->setProperty("tutorial_name", "CYCLIC_BUTTON");
Expand Down Expand Up @@ -162,6 +173,7 @@ BufferDacAddon::BufferDacAddon(DacDataModel *model, QWidget *parent)
filesizeContainer->contentLayout()->addWidget(m_fileSizeSpin);
filesizeContainer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);

runConfigLay->addWidget(repeatFileBufferContainer);
runConfigLay->addWidget(cyclicContainer);
runConfigLay->addWidget(filesizeContainer);
runConfigLay->addWidget(m_runBtn);
Expand Down
1 change: 1 addition & 0 deletions plugins/dac/src/bufferdacaddon.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private Q_SLOTS:
gui::MenuSpinbox *m_fileSizeSpin;
gui::MenuSpinbox *m_kernelCountSpin;
MenuOnOffSwitch *m_cyclicBtn;
MenuOnOffSwitch *m_repeatFileBufferBtn;
QTextBrowser *m_logText;
FileBrowser *fm;

Expand Down
15 changes: 13 additions & 2 deletions plugins/dac/src/dacdatamodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ DacDataModel::DacDataModel(struct iio_device *dev, QObject *parent)
, m_activeBuffer(false)
, m_buffer(nullptr)
, m_cyclicBuffer(true)
, m_repeatFileBuffer(true)
, m_interrupted(false)
, m_userBuffersize(0)
, m_userKernelBufferCount(0)
Expand Down Expand Up @@ -116,6 +117,14 @@ QMap<QString, TxNode *> DacDataModel::getBufferTxs() const { return m_bufferTxs;

QMap<QString, TxNode *> DacDataModel::getDdsTxs() const { return m_ddsTxs; }

void DacDataModel::setRepeatFileBuffer(bool repeat)
{
requestInterruption();
m_repeatFileBuffer = repeat;
autoBuffersizeAndKernelBuffers();
Q_EMIT reqInitBuffer();
}

void DacDataModel::requestInterruption()
{
m_interrupted = true;
Expand Down Expand Up @@ -262,7 +271,7 @@ bool DacDataModel::validateBufferParams()
return false;
}

if(m_data[0].size() < enabledChannelsCount) {
if(m_data[0].size() < enabledChannelsCount && !m_repeatFileBuffer) {
auto msg = "Not enough data columns for all enabled channels.";
qDebug(CAT_DAC_DATA) << msg;
Q_EMIT log(msg);
Expand Down Expand Up @@ -339,11 +348,13 @@ void DacDataModel::push()
if(!m_cyclicBuffer) {
additionalSamples = m_filesize % m_buffersize;
}

unsigned int available_data_columns = m_data[0].size();
for(int ch = 0; ch < enChannelsCount; ch++) {
allDataC.push_back({});
for(unsigned int i = 0; i < m_filesize + additionalSamples; i += m_decimation) {
sampleIdx = std::min(i, m_filesize - 1);
allDataC[ch].append(m_data[sampleIdx][ch]);
allDataC[ch].append(m_data[sampleIdx][ch % available_data_columns]);
}
totalSize += allDataC[ch].size();
}
Expand Down
2 changes: 2 additions & 0 deletions plugins/dac/src/dacdatamodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class DacDataModel : public QObject
QMap<QString, TxNode *> getBufferTxs() const;
QMap<QString, TxNode *> getDdsTxs() const;

void setRepeatFileBuffer(bool repeat);
void setCyclic(bool cyclic);
void setKernelBuffersCount(unsigned int kernelCount);
void setDecimation(double decimation);
Expand Down Expand Up @@ -89,6 +90,7 @@ private Q_SLOTS:
bool m_isBufferCapable;
bool m_isDds;
bool m_cyclicBuffer;
bool m_repeatFileBuffer;
int m_decimation;

bool m_activeDds;
Expand Down

0 comments on commit 9d43e40

Please sign in to comment.