Skip to content

Commit

Permalink
regmap: added tutorial
Browse files Browse the repository at this point in the history
Signed-off-by: IonutMuthi <[email protected]>
  • Loading branch information
IonutMuthi committed Nov 11, 2024
1 parent e57badd commit 65ca09d
Show file tree
Hide file tree
Showing 12 changed files with 410 additions and 14 deletions.
4 changes: 3 additions & 1 deletion plugins/regmap/resources/resources.qrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<RCC>
<qresource prefix="/icons"/>
<qresource prefix="/registermap">
<file>tutorial_chapters.json</file>
</qresource>
</RCC>
161 changes: 161 additions & 0 deletions plugins/regmap/resources/tutorial_chapters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{
"simple_registermap" : [
{
"index": 1,
"names": ["DEVICE_LIST"],
"description": "Select the device",
"anchor": "HP_BOTTOM",
"content": "HP_BOTTOM",
"y_offset": 10
},
{
"index": 2,
"names": ["SETTINGS_BUTTON"],
"description": "Settings",
"anchor": "HP_BOTTOM",
"content": "HP_BOTTOM",
"y_offset": 10,
"x_offset": -120
}
],
"simple_register_controller" : [
{
"index": 1,
"names": ["READ_WIDGET"],
"description": "Read value for selected device",
"anchor": "HP_BOTTOM",
"content": "HP_BOTTOM",
"y_offset": -5
},
{
"index": 2,
"names": ["WRITE_WIDGET"],
"description": "Write value to selected register. After writing a the register will automatically read value from selected register.",
"anchor": "HP_BOTTOM",
"content": "HP_BOTTOM",
"y_offset": -5
}
],
"register_controller" : [
{
"index": 1,
"names": ["READ_WIDGET"],
"description": "Read value for selected device",
"anchor": "HP_TOP",
"content": "HP_TOP",
"y_offset": -5
},
{
"index": 2,
"names": ["WRITE_WIDGET"],
"description": "Write value to selected register. After writing a the register will automatically read value from selected register.",
"anchor": "HP_TOP",
"content": "HP_TOP",
"y_offset": -5

},
{
"index": 3,
"names": ["TOGGLE_DETAILED_BUTTON"],
"description": "Show/hide detailed bitfields",
"anchor": "HP_TOP",
"content": "HP_TOP",
"y_offset": -5,
"x_offset": -120
}
],
"registermap": [
{
"index": 1,
"names": ["DEVICE_LIST"],
"description": "Select the device",
"anchor": "HP_BOTTOM",
"content": "HP_BOTTOM",
"y_offset": 10
},
{
"index": 2,
"names": ["SEARCH_BAR"],
"description": "Search regiter by name or address of register or bitfields of register",
"anchor": "HP_BOTTOM",
"content": "HP_BOTTOM",
"y_offset": 10
},
{
"index": 3,
"names": ["SETTINGS_BUTTON"],
"description": "Settings",
"anchor": "HP_BOTTOM",
"content": "HP_BOTTOM",
"y_offset": 10,
"x_offset": -120
}

],
"settings" : [
{
"index": 1,
"names": ["AUTOREAD"],
"description": "When enabled each time a new register is selected a read is automatically done.",
"anchor": "HP_BOTTOM",
"content": "HP_BOTTOM",
"y_offset": 10,
"x_offset": -120
},
{
"index": 2,
"names": ["READ_INTERVAL"],
"description": "Provide a start and end interval values to be able to read all registers in that interval.",
"anchor": "HP_BOTTOM",
"content": "HP_BOTTOM",
"y_offset": 10,
"x_offset": -120
},
{
"index": 3,
"names": ["FIND_PATH"],
"description": "Select a file that will be used for Write Values and Register Dump actions.",
"anchor": "HP_BOTTOM",
"content": "HP_BOTTOM",
"y_offset": 10,
"x_offset": -120
},
{
"index": 4,
"names": ["WRITE_VALUES"],
"description": "Write all values from provided files to registers.",
"anchor": "HP_BOTTOM",
"content": "HP_BOTTOM",
"y_offset": 10,
"x_offset": -120
},
{
"index": 5,
"names": ["REGISTER_DUMP"],
"description": "Save all read registers to selected file.",
"anchor": "HP_BOTTOM",
"content": "HP_BOTTOM",
"y_offset": 10,
"x_offset": -120
}
],
"device_register_map": [
{
"index": 1,
"names": ["DETAILED_BITFIELDS"],
"description": "Detailed bitfields where you can change individual bitfields values",
"anchor": "HP_TOP",
"content": "HP_TOP",
"y_offset": 10
},
{
"index": 2,
"names": ["REGISTER_MAP"],
"description": "Map of all registers where you can see values and information",
"anchor": "HP_TOP",
"content": "HP_TOP",
"y_offset": 300,
"x_offset": 500
}
]
}
34 changes: 34 additions & 0 deletions plugins/regmap/src/deviceregistermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ DeviceRegisterMap::DeviceRegisterMap(RegisterMapTemplate *registerMapTemplate, R
tableHeadWidgetLayout->addWidget(registerTableHead, 1);
tableHeadWidgetLayout->addWidget(colBitCount, 8);
registerMapTableLayout->addWidget(tableHeadWidget);

registerMapTableWidget = new RegisterMapTable(registerMapTemplate->getRegisterList(), this);
registerMapTable->setProperty("tutorial_name", "REGISTER_MAP");

QWidget *aux = registerMapTableWidget->getWidget();
if(aux) {
Expand Down Expand Up @@ -180,12 +182,17 @@ DeviceRegisterMap::DeviceRegisterMap(RegisterMapTemplate *registerMapTemplate, R
tool->addWidgetToCentralContainerHelper(controllerWidget);
controllerLayout->addWidget(registerController);

initSimpleTutorial();
if(registerMapTemplate) {
registerChanged(registerMapTemplate->getRegisterList()->first());
initTutorial();

} else {
tool->centralContainer()->layout()->addItem(
new QSpacerItem(10, 10, QSizePolicy::Preferred, QSizePolicy::Expanding));
}

connect(this, &DeviceRegisterMap::tutorialAborted, this, &DeviceRegisterMap::abortTutorial);
}

DeviceRegisterMap::~DeviceRegisterMap()
Expand All @@ -212,6 +219,7 @@ void DeviceRegisterMap::registerChanged(RegisterModel *regModel)
}

registerDetailedWidget = new RegisterDetailedWidget(regModel, tool->bottomContainer());
registerDetailedWidget->setProperty("tutorial_name", "DETAILED_BITFIELDS");
registerDetailedWidget->setMaximumHeight(140);
tool->bottomCentral()->layout()->addWidget(registerDetailedWidget);

Expand Down Expand Up @@ -251,6 +259,8 @@ bool DeviceRegisterMap::hasTemplate()
}

bool DeviceRegisterMap::getAutoread() { return autoread; }
void DeviceRegisterMap::startTutorial() { registerController->startTutorial(); }
void DeviceRegisterMap::startSimpleTutorial() { registerController->startSimpleTutorial(); }

void DeviceRegisterMap::initSettings()
{
Expand All @@ -259,3 +269,27 @@ void DeviceRegisterMap::initSettings()
&RegisterMapValues::registerDump);
QObject::connect(this, &DeviceRegisterMap::requestWrite, registerMapValues, &RegisterMapValues::requestWrite);
}

void DeviceRegisterMap::initTutorial()
{

controllerTutorialFinish = connect(registerController, &RegisterController::tutorialFinished, this, [=]() {
QWidget *parent = Util::findContainingWindow(this);
tutorial = new gui::TutorialBuilder(this, ":/registermap/tutorial_chapters.json", "device_register_map",
parent);

connect(tutorial, &gui::TutorialBuilder::finished, this, [=]() { Q_EMIT tutorialFinished(); });
connect(tutorial, &gui::TutorialBuilder::aborted, this, &DeviceRegisterMap::tutorialAborted);
tutorial->setTitle("Tutorial");
tutorial->start();
});
}

void DeviceRegisterMap::initSimpleTutorial()
{
connect(registerController, &RegisterController::tutorialAborted, this, &DeviceRegisterMap::tutorialAborted);
connect(registerController, &RegisterController::simpleTutorialFinished, this,
&DeviceRegisterMap::simpleTutorialFinished);
}

void DeviceRegisterMap::abortTutorial() { disconnect(controllerTutorialFinish); }
21 changes: 17 additions & 4 deletions plugins/regmap/src/deviceregistermap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QObject>
#include <QWidget>
#include <tooltemplate.h>
#include <tutorialbuilder.h>
#include "scopy-regmap_export.h"

class QVBoxLayout;
Expand Down Expand Up @@ -57,6 +58,16 @@ class SCOPY_REGMAP_EXPORT DeviceRegisterMap : public QWidget
void applyFilters(QString filter);
bool hasTemplate();
bool getAutoread();
void startTutorial();
void startSimpleTutorial();

Q_SIGNALS:
void requestRead(uint32_t address);
void requestWrite(uint32_t address, uint32_t value);
void requestRegisterDump(QString path);
void tutorialFinished();
void simpleTutorialFinished();
void tutorialAborted();

private:
ToolTemplate *tool;
Expand All @@ -73,10 +84,12 @@ class SCOPY_REGMAP_EXPORT DeviceRegisterMap : public QWidget
void initSettings();
int selectedRegister;

Q_SIGNALS:
void requestRead(uint32_t address);
void requestWrite(uint32_t address, uint32_t value);
void requestRegisterDump(QString path);
void initTutorial();
void initSimpleTutorial();
void abortTutorial();
gui::TutorialBuilder *tutorial;
QMetaObject::Connection controllerTutorialFinish;
QMetaObject::Connection mapTutorialFinish;
};
} // namespace scopy::regmap
#endif // DEVICEREGISTERMAP_HPP
1 change: 1 addition & 0 deletions plugins/regmap/src/register/registerdetailedwidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class RegisterDetailedWidget : public QWidget
private:
QVector<BitFieldDetailedWidget *> *bitFieldList;
int regWidth;

Q_SIGNALS:
void bitFieldValueChanged(QString value);
};
Expand Down
35 changes: 33 additions & 2 deletions plugins/regmap/src/registercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ RegisterController::RegisterController(QWidget *parent)
writeWidgetLayout->addWidget(writeButton, 1, Qt::AlignRight);

applyStyle();

readWidget->setProperty("tutorial_name", "READ_WIDGET");
writeWidget->setProperty("tutorial_name", "WRITE_WIDGET");
}

RegisterController::~RegisterController()
Expand Down Expand Up @@ -162,8 +165,8 @@ void RegisterController::setHasMap(bool hasMap)
QObject::connect(detailedRegisterToggle, &QPushButton::toggled, this,
&RegisterController::toggleDetailedMenu);
writeWidgetLayout->addWidget(detailedRegisterToggle, 0.5, Qt::AlignRight);
Style::setStyle(detailedRegisterToggle, style::properties::button::squareIconButton, true, true);
detailedRegisterToggle->setFixedSize(32, 32);

detailedRegisterToggle->setProperty("tutorial_name", "TOGGLE_DETAILED_BUTTON");
}
}

Expand All @@ -179,3 +182,31 @@ void RegisterController::applyStyle()

// setStyleSheet(RegmapStyleHelper::regmapControllerStyle(nullptr));
}

void RegisterController::startTutorial()
{
QWidget *parent = Util::findContainingWindow(this);
registerMapTutorial =
new gui::TutorialBuilder(this, ":/registermap/tutorial_chapters.json", "register_controller", parent);

connect(registerMapTutorial, &gui::TutorialBuilder::finished, this, [=]() { Q_EMIT tutorialFinished(); });
connect(registerMapTutorial, &gui::TutorialBuilder::aborted, this, &RegisterController::tutorialAborted);

registerMapTutorial->setTitle("Tutorial");
registerMapTutorial->start();
}

void RegisterController::startSimpleTutorial()
{
QWidget *parent = Util::findContainingWindow(this);
registerMapSimpleTutorial = new gui::TutorialBuilder(this, ":/registermap/tutorial_chapters.json",
"simple_register_controller", parent);

connect(registerMapSimpleTutorial, &gui::TutorialBuilder::finished, this,
[=]() { Q_EMIT simpleTutorialFinished(); });

connect(registerMapSimpleTutorial, &gui::TutorialBuilder::aborted, this, &RegisterController::tutorialAborted);

registerMapSimpleTutorial->setTitle("Tutorial");
registerMapSimpleTutorial->start();
}
22 changes: 15 additions & 7 deletions plugins/regmap/src/registercontroller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "scopy-regmap_export.h"

#include <QWidget>
#include <tutorialbuilder.h>

class QHBoxLayout;
class QSpinBox;
Expand Down Expand Up @@ -54,6 +55,18 @@ class SCOPY_REGMAP_EXPORT RegisterController : public QWidget
void registerValueChanged(QString value);
QString getAddress();
void setHasMap(bool hasMap);
void startTutorial();
void startSimpleTutorial();

Q_SIGNALS:
void requestRead(uint32_t address);
void requestWrite(uint32_t address, uint32_t value);
void registerAddressChanged(uint32_t address);
void valueChanged(QString value);
void toggleDetailedMenu(bool toggled);
void tutorialFinished();
void simpleTutorialFinished();
void tutorialAborted();

private:
QHBoxLayout *mainLayout;
Expand All @@ -72,13 +85,8 @@ class SCOPY_REGMAP_EXPORT RegisterController : public QWidget
bool addressChanged = false;
bool hasMap = false;
void applyStyle();

Q_SIGNALS:
void requestRead(uint32_t address);
void requestWrite(uint32_t address, uint32_t value);
void registerAddressChanged(uint32_t address);
void valueChanged(QString value);
void toggleDetailedMenu(bool toggled);
gui::TutorialBuilder *registerMapTutorial;
gui::TutorialBuilder *registerMapSimpleTutorial;
};
} // namespace scopy::regmap
#endif // REGISTERCONTROLLER_HPP
Loading

0 comments on commit 65ca09d

Please sign in to comment.