Skip to content

Commit

Permalink
plugins/swiotrefactor: Added faults instrument.
Browse files Browse the repository at this point in the history
I removed the ToolView bindings and I used ToolTemplate instead.
Removed .ui files.
Cleaned the code.

Signed-off-by: andrei.danila <[email protected]>
  • Loading branch information
andreidanila1 committed Mar 26, 2024
1 parent e0ce8e6 commit f8d7af9
Show file tree
Hide file tree
Showing 21 changed files with 1,418 additions and 675 deletions.
3 changes: 3 additions & 0 deletions gui/include/gui/stylehelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class SCOPY_GUI_EXPORT StyleHelper : public QObject
static void WarningLabel(QLabel *w, QString objectName = "");
static void NoBackgroundIconButton(QPushButton *w, QIcon icon, QString objectName = "");
static void OrangeWidget(QWidget *w, QString objectName = "");
static void ActiveStoredLabel(QLabel *w, QString objectName = "");
static void FaultsFrame(QFrame *w, QString objectName = "");
static void FaultsExplanation(QWidget *w, QString objectName = "");

private:
QMap<QString, QString> colorMap;
Expand Down
40 changes: 40 additions & 0 deletions gui/src/stylehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void StyleHelper::initColorMap()
sh->colorMap.insert("ProgressBarBusy", "#F8E71C");

sh->colorMap.insert("WarningText", "#FFC904");
sh->colorMap.insert("GrayText", "#5c5c5c");
}

QString StyleHelper::getColor(QString id)
Expand Down Expand Up @@ -1276,4 +1277,43 @@ void StyleHelper::OrangeWidget(QWidget *w, QString objectName)
w->setStyleSheet(style);
}

void StyleHelper::ActiveStoredLabel(QLabel *w, QString objectName)
{
if(!objectName.isEmpty())
w->setObjectName(objectName);
QString style = QString(R"css(
QLabel{
background-color: transparent; width: 40px; height: 14px; border: 2px solid ; border-radius: 8px; border-color: white;
}
QLabel[high=false] { border-color: white; background-color: transparent; }
QLabel[high=true] { border-color: white; background-color: white; }
)css");
w->setStyleSheet(style);
}

void StyleHelper::FaultsFrame(QFrame *w, QString objectName)
{
if(!objectName.isEmpty())
w->setObjectName(objectName);
QString style = QString(R"css(
QFrame[pressed=true] { background-color: &&elementHighlight&&; border: 1px solid &&elementBackground&&; border-radius:5px; }
)css");
style.replace("&&elementHighlight&&", StyleHelper::getColor("UIElementHighlight"));
style.replace("&&elementBackground&&", StyleHelper::getColor("UIElementBackground"));

w->setStyleSheet(style);
}

void StyleHelper::FaultsExplanation(QWidget *w, QString objectName)
{
if(!objectName.isEmpty())
w->setObjectName(objectName);
QString style = QString(R"css(
QWidget[highlighted=true]{color:white;}
QWidget{color:&&defaultColor&&;}
)css");
style.replace("&&defaultColor&&", StyleHelper::getColor("GrayText"));
w->setStyleSheet(style);
}

#include "moc_stylehelper.cpp"
4 changes: 4 additions & 0 deletions plugins/swiotrefactor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ file(
# some of these will eventually be moved to the core/gui directories
src/max14906/*.cpp
src/max14906/*.cc
src/faults/*.cpp
src/faults/*.cc
src/*.cpp
src/*.cc
model/*
Expand All @@ -45,6 +47,8 @@ file(
include/${SCOPY_MODULE}/*.hpp
include/${SCOPY_MODULE}/max14906/*.h
include/${SCOPY_MODULE}/max14906/*.hpp
include/${SCOPY_MODULE}/faults/*.h
include/${SCOPY_MODULE}/faults/*.hpp
)
file(GLOB UI_LIST ui/*.ui)

Expand Down
16 changes: 0 additions & 16 deletions plugins/swiotrefactor/include/swiotrefactor/faults.h

This file was deleted.

74 changes: 74 additions & 0 deletions plugins/swiotrefactor/include/swiotrefactor/faults/faults.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2023 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef FAULTS_H
#define FAULTS_H

#include "scopy-swiotrefactor_export.h"
#include "faultspage.h"
#include <pluginbase/toolmenuentry.h>

#include <iio.h>
#include <gui/widgets/toolbuttons.h>

#include <gui/channel_manager.hpp>
#include <gui/generic_menu.hpp>
#include <gui/tool_view.hpp>
#include <gui/tooltemplate.h>

namespace scopy::swiotrefactor {
class SCOPY_SWIOTREFACTOR_EXPORT Faults : public QWidget
{
Q_OBJECT
public:
explicit Faults(QString uri, ToolMenuEntry *tme, QWidget *parent = nullptr);
~Faults();

void pollFaults();

Q_SIGNALS:
void backBtnPressed();

public Q_SLOTS:
void runButtonClicked(bool toggled);
void singleButtonClicked();

private Q_SLOTS:
void onBackBtnPressed();

private:
void connectSignalsAndSlots();
void initTutorialProperties();
QPushButton *createConfigBtn(QWidget *parent);

ToolTemplate *m_tool;
RunBtn *m_runBtn;
SingleShotBtn *m_singleBtn;
QPushButton *m_configBtn;

QTimer *m_timer;
QThread *m_thread;

FaultsPage *m_faultsPage;

ToolMenuEntry *m_tme;
};
} // namespace scopy::swiotrefactor
#endif // FAULTS_H
99 changes: 99 additions & 0 deletions plugins/swiotrefactor/include/swiotrefactor/faults/faultsdevice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2023 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef FAULTSDEVICE_H
#define FAULTSDEVICE_H

#include "scopy-swiotrefactor_export.h"
#include "faultsgroup.h"
#include <QLineEdit>
#include <QPushButton>
#include <QTextEdit>
#include <QWidget>

#include <iio.h>
#include <iioutil/commandqueue.h>

namespace scopy::swiotrefactor {
class FaultsGroup;

class SCOPY_SWIOTREFACTOR_EXPORT FaultsDevice : public QWidget
{
Q_OBJECT
public:
explicit FaultsDevice(const QString &name, QString path, QString uri, QVector<uint32_t> &registers,
QWidget *parent = nullptr);
~FaultsDevice();

void update();

void readRegister();
public Q_SLOTS:
void resetStored();
void updateExplanations();
void updateExplanation(int index);
void onFaultNumericUpdated();
void onFaultRegisterRead(int iReg, uint32_t value);

Q_SIGNALS:
void specialFaultsUpdated(int index, QString channelFunction);
void faultNumericUpdated();
void faultRegisterRead(int iReg, uint32_t value);

private Q_SLOTS:
void updateMinimumHeight();
void deviceConfigCmdFinished(scopy::Command *cmd);
void functionConfigCmdFinished(scopy::Command *cmd);

private:
void establishConnection(QString name);
void initSpecialFaults();
void initTutorialProperties();
void connectSignalsAndSlots();
QWidget *createTopWidget(QWidget *parent);
QWidget *createExplanationSection(QWidget *parent);

QLineEdit *m_registerNoLineEdit;
QPushButton *m_resetBtn;
QPushButton *m_clearBtn;
QWidget *m_faultsExplanation;

QString m_uri;
CommandQueue *m_cmdQueue;

FaultsGroup *m_faultsGroup;
QVector<QWidget *> m_faultExplanationWidgets;

QString m_name;

struct iio_device *m_device;
struct iio_device *m_swiot;
struct iio_context *m_context;

uint32_t m_faultNumeric = 0;
QVector<uint32_t> m_registers;
QVector<uint32_t> m_registerValues;
QVector<Command *> m_deviceConfigCmds;
QVector<Command *> m_functionConfigCmds;
};

} // namespace scopy::swiotrefactor

#endif // FAULTSDEVICE_H
77 changes: 77 additions & 0 deletions plugins/swiotrefactor/include/swiotrefactor/faults/faultsgroup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2023 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef FAULTSGROUP_H
#define FAULTSGROUP_H

#include "scopy-swiotrefactor_export.h"
#include "faultwidget.h"
#include <set>
#include <QVector>
#include <gui/flexgridlayout.hpp>

namespace scopy::swiotrefactor {
class SCOPY_SWIOTREFACTOR_EXPORT FaultsGroup : public QWidget
{
Q_OBJECT
public:
explicit FaultsGroup(QString name, const QString &path, QWidget *parent = nullptr);
~FaultsGroup() override;

const QVector<FaultWidget *> &getFaults() const;

const QString &getName() const;
void setName(const QString &name);

void clearSelection();
void update(uint32_t faults_numeric);
QStringList getExplanations();
QString getExplanation(unsigned int id);
std::set<unsigned int> getSelectedIndexes();
std::set<unsigned int> getActiveIndexes();

Q_SIGNALS:
void selectionUpdated();
void minimumSizeChanged();
void specialFaultsUpdated(unsigned int index, QString channelFunction);
void specialFaultExplanationChanged(unsigned int, QString);

private Q_SLOTS:
void layoutUpdate();
void onFaultSelected(unsigned int id);

protected:
QWidget *buildActiveStoredWidget();
QJsonArray *getJsonArray(const QString &path);

private:
void createFaultWidgets(const QString &path);

int m_maxFaults;
QString m_name;
QVector<FaultWidget *> m_faults;
std::set<unsigned int> m_currentlySelected;
std::set<unsigned int> m_actives;
FlexGridLayout *m_customColGrid;
QWidget *m_activeStoredWidget;
};
} // namespace scopy::swiotrefactor

#endif // FAULTSGROUP_H
Loading

0 comments on commit f8d7af9

Please sign in to comment.