Skip to content

Commit

Permalink
Added datalogger API's
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandru Lie <[email protected]>
  • Loading branch information
liealex committed Oct 29, 2024
1 parent b8bac16 commit 8152c79
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gui/include/gui/printplotmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SCOPY_GUI_EXPORT PrintPlotManager : public QObject
public:
explicit PrintPlotManager(QObject *parent = nullptr);

void printPlots(QList<PlotWidget *> plotList, QString toolName);
void printPlots(QList<PlotWidget *> plotList, QString toolName, QString folderPath = "");
void setPrintWithSymbols(bool printWithSymbols);
signals:

Expand Down
11 changes: 7 additions & 4 deletions gui/src/printplotmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ PrintPlotManager::PrintPlotManager(QObject *parent)
: QObject{parent}
{}

void PrintPlotManager::printPlots(QList<PlotWidget *> plotList, QString toolName)
void PrintPlotManager::printPlots(QList<PlotWidget *> plotList, QString toolName, QString folderPath)
{
// select folder where to save
QString folderPath = QFileDialog::getExistingDirectory(
nullptr, "Select Folder", "",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::DontUseNativeDialog);
if(folderPath.isEmpty()) {
folderPath =
QFileDialog::getExistingDirectory(nullptr, "Select Folder", "",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks |
QFileDialog::DontUseNativeDialog);
}

if(!folderPath.isEmpty()) {
// use current date and tool name to crete the file name
Expand Down
8 changes: 8 additions & 0 deletions plugins/datalogger/include/datalogger/datalogger_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "scopy-datalogger_export.h"

#include <dataloggerplugin.h>
#include <sevensegmentdisplay.hpp>
#include <sevensegmentmonitorsettings.hpp>

namespace scopy::datamonitor {

Expand All @@ -22,6 +24,12 @@ class SCOPY_DATALOGGER_EXPORT DataLogger_API : public ApiObject
Q_INVOKABLE QString disableMonitor(QString monitor);
Q_INVOKABLE void setRunning(bool running);
Q_INVOKABLE void clearData();
Q_INVOKABLE void print(QString filePath);
Q_INVOKABLE void changeTool(QString name);
Q_INVOKABLE void setMinMax(bool enable);
Q_INVOKABLE void changePrecision(int decimals);
Q_INVOKABLE void setMinYAxis(double min);
Q_INVOKABLE void setMaxYAxis(double max);

// TOOL RELATED
Q_INVOKABLE QString createTool();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace datamonitor {
class SCOPY_DATALOGGER_EXPORT SevenSegmentMonitorSettings : public QWidget
{
friend class DataMonitorStyleHelper;
friend class DataLogger_API;
Q_OBJECT
public:
explicit SevenSegmentMonitorSettings(QWidget *parent = nullptr);
Expand Down
89 changes: 87 additions & 2 deletions plugins/datalogger/src/datalogger_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ QString DataLogger_API::disableMonitor(QString monitor)

void DataLogger_API::setRunning(bool running)
{
Q_ASSERT(m_dataLoggerPlugin != nullptr);
m_dataLoggerPlugin->toggleRunState(running);
Q_ASSERT(m_dataLoggerPlugin->m_dataAcquisitionManager != nullptr);
ToolMenuEntry *tool = ToolMenuEntry::findToolMenuEntryByName(m_dataLoggerPlugin->m_toolList, "Data Logger ");
if(tool) {
tool->setRunning(running);
tool->runToggled(running);
}
}

void DataLogger_API::clearData()
Expand All @@ -91,6 +95,87 @@ void DataLogger_API::clearData()
m_dataLoggerPlugin->m_dataAcquisitionManager->clearMonitorsData();
}

void DataLogger_API::print(QString filepath)
{
Q_ASSERT(m_dataLoggerPlugin->m_dataAcquisitionManager != nullptr);
ToolMenuEntry *tool = ToolMenuEntry::findToolMenuEntryByName(m_dataLoggerPlugin->m_toolList, "Data Logger ");
if(tool) {
DatamonitorTool *monitorTool = dynamic_cast<DatamonitorTool *>(tool->tool());
QList<PlotWidget *> plotList;
plotList.push_back(monitorTool->m_monitorPlot->plot());
monitorTool->printplotManager->printPlots(plotList, "DataLogger", filepath);
}
}

void DataLogger_API::changeTool(QString name)
{
Q_ASSERT(!m_dataLoggerPlugin->m_toolList.isEmpty());

ToolMenuEntry *tool = ToolMenuEntry::findToolMenuEntryByName(m_dataLoggerPlugin->m_toolList, "Data Logger ");
if(tool) {
DatamonitorTool *monitorTool = dynamic_cast<DatamonitorTool *>(tool->tool());
if(name == "Plot") {
monitorTool->showPlot->click();
} else if(name == "Text") {
monitorTool->showText->click();
} else if(name == "7 Segment") {
monitorTool->showSegments->click();
} else {
qWarning(CAT_DATAMONITOR_API) << "No tool available with name " << name;
}
}
}

void DataLogger_API::setMinMax(bool enable)
{
Q_ASSERT(!m_dataLoggerPlugin->m_toolList.isEmpty());

ToolMenuEntry *tool = ToolMenuEntry::findToolMenuEntryByName(m_dataLoggerPlugin->m_toolList, "Data Logger ");
if(tool) {
DatamonitorTool *monitorTool = dynamic_cast<DatamonitorTool *>(tool->tool());
SevenSegmentMonitorSettings *monitorSettings =
monitorTool->m_dataMonitorSettings->getSevenSegmentMonitorSettings();
monitorTool->sevenSegmetMonitors->togglePeakHolder(enable);
monitorSettings->peakHolderToggle->onOffswitch()->setChecked(enable);
}
}

void DataLogger_API::changePrecision(int decimals)
{
Q_ASSERT(!m_dataLoggerPlugin->m_toolList.isEmpty());

ToolMenuEntry *tool = ToolMenuEntry::findToolMenuEntryByName(m_dataLoggerPlugin->m_toolList, "Data Logger ");
if(tool) {
DatamonitorTool *monitorTool = dynamic_cast<DatamonitorTool *>(tool->tool());
SevenSegmentMonitorSettings *monitorSettings =
monitorTool->m_dataMonitorSettings->getSevenSegmentMonitorSettings();
monitorTool->sevenSegmetMonitors->updatePrecision(decimals);
monitorSettings->precision->setText(QString::number(decimals));
}
}

void DataLogger_API::setMinYAxis(double min)
{
Q_ASSERT(!m_dataLoggerPlugin->m_toolList.isEmpty());

ToolMenuEntry *tool = ToolMenuEntry::findToolMenuEntryByName(m_dataLoggerPlugin->m_toolList, "Data Logger ");
if(tool) {
DatamonitorTool *monitorTool = dynamic_cast<DatamonitorTool *>(tool->tool());
monitorTool->m_monitorPlot->updateYAxisIntervalMin(min);
}
}

void DataLogger_API::setMaxYAxis(double max)
{
Q_ASSERT(!m_dataLoggerPlugin->m_toolList.isEmpty());

ToolMenuEntry *tool = ToolMenuEntry::findToolMenuEntryByName(m_dataLoggerPlugin->m_toolList, "Data Logger ");
if(tool) {
DatamonitorTool *monitorTool = dynamic_cast<DatamonitorTool *>(tool->tool());
monitorTool->m_monitorPlot->updateYAxisIntervalMax(max);
}
}

QString DataLogger_API::createTool()
{
Q_ASSERT(m_dataLoggerPlugin != nullptr);
Expand Down

0 comments on commit 8152c79

Please sign in to comment.