Improved containment of target package widget functionality - it's now less tightly coupled.

This commit is contained in:
Nav
2021-09-02 21:19:46 +01:00
parent 8c08493122
commit 1dc184edbc
17 changed files with 221 additions and 94 deletions

View File

@@ -140,9 +140,10 @@ add_executable(Bloom
# Insight worker tasks # Insight worker tasks
src/Insight/InsightWorker/Tasks/InsightWorkerTask.cpp src/Insight/InsightWorker/Tasks/InsightWorkerTask.cpp
src/Insight/InsightWorker/Tasks/ReadTargetRegisters.cpp src/Insight/InsightWorker/Tasks/ReadTargetRegisters.cpp
src/Insight/InsightWorker/Tasks/RefreshTargetPinStates.cpp
# Target package widgets # Target package widgets
src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.hpp src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.cpp
src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.hpp src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.hpp
src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinBodyWidget.cpp src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinBodyWidget.cpp
src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/DualInlinePackageWidget.cpp src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/DualInlinePackageWidget.cpp

View File

@@ -3,7 +3,6 @@
#include <typeindex> #include <typeindex>
#include <QTimer> #include <QTimer>
#include "InsightWorker.hpp"
#include "src/Helpers/Paths.hpp" #include "src/Helpers/Paths.hpp"
#include "src/Logger/Logger.hpp" #include "src/Logger/Logger.hpp"
#include "src/Exceptions/InvalidConfig.hpp" #include "src/Exceptions/InvalidConfig.hpp"
@@ -69,36 +68,31 @@ void Insight::startup() {
* This allows us to use Qt's event loop whilst still being able to process our own events. * This allows us to use Qt's event loop whilst still being able to process our own events.
*/ */
auto eventDispatchTimer = new QTimer(&(this->application)); auto eventDispatchTimer = new QTimer(&(this->application));
connect(eventDispatchTimer, &QTimer::timeout, this, &Insight::dispatchEvents); this->connect(eventDispatchTimer, &QTimer::timeout, this, &Insight::dispatchEvents);
eventDispatchTimer->start(100); eventDispatchTimer->start(100);
this->connect(this->insightWorker, &InsightWorker::targetControllerSuspended, this->mainWindow, &InsightWindow::onTargetControllerSuspended);
this->connect(this->insightWorker, &InsightWorker::targetControllerResumed, this->mainWindow, &InsightWindow::onTargetControllerResumed);
this->connect(this->insightWorker, &InsightWorker::targetStateUpdated, this->mainWindow, &InsightWindow::onTargetStateUpdate);
this->connect(this->insightWorker, &InsightWorker::targetProgramCounterUpdated, this->mainWindow, &InsightWindow::onTargetProgramCounterUpdate);
this->connect(this->insightWorker, &InsightWorker::targetIoPortsUpdated, this->mainWindow, &InsightWindow::onTargetIoPortsUpdate);
this->connect(this->mainWindow, &InsightWindow::refreshTargetPinStates, this->insightWorker, &InsightWorker::requestPinStates);
this->connect(this->mainWindow, &InsightWindow::setTargetPinState, this->insightWorker, &InsightWorker::requestPinStateUpdate);
this->mainWindow->setInsightConfig(this->insightConfig);
this->mainWindow->setEnvironmentConfig(this->environmentConfig);
this->mainWindow->init(targetDescriptor);
// Prepare worker thread // Prepare worker thread
this->workerThread = new QThread(); this->workerThread = new QThread();
this->workerThread->setObjectName("IW"); this->workerThread->setObjectName("IW");
this->insightWorker->moveToThread(this->workerThread); this->insightWorker->moveToThread(this->workerThread);
connect(this->workerThread, &QThread::started, this->insightWorker, &InsightWorker::startup); this->connect(this->workerThread, &QThread::started, this->insightWorker, &InsightWorker::startup);
connect(this->workerThread, &QThread::finished, this->insightWorker, &QObject::deleteLater); this->connect(this->workerThread, &QThread::finished, this->insightWorker, &QObject::deleteLater);
connect(this->workerThread, &QThread::finished, this->workerThread, &QThread::deleteLater); this->connect(this->workerThread, &QThread::finished, this->workerThread, &QThread::deleteLater);
connect(this->insightWorker, &InsightWorker::targetControllerSuspended, &(this->mainWindow), &InsightWindow::onTargetControllerSuspended); this->mainWindow->show();
connect(this->insightWorker, &InsightWorker::targetControllerResumed, &(this->mainWindow), &InsightWindow::onTargetControllerResumed);
connect(this->insightWorker, &InsightWorker::targetStateUpdated, &(this->mainWindow), &InsightWindow::onTargetStateUpdate);
connect(this->insightWorker, &InsightWorker::targetProgramCounterUpdated, &(this->mainWindow), &InsightWindow::onTargetProgramCounterUpdate);
connect(this->insightWorker, &InsightWorker::targetPinStatesUpdated, &(this->mainWindow), &InsightWindow::onTargetPinStatesUpdate);
connect(this->insightWorker, &InsightWorker::targetIoPortsUpdated, &(this->mainWindow), &InsightWindow::onTargetIoPortsUpdate);
connect(&(this->mainWindow), &InsightWindow::refreshTargetPinStates, this->insightWorker, &InsightWorker::requestPinStates);
connect(&(this->mainWindow), &InsightWindow::setTargetPinState, this->insightWorker, &InsightWorker::requestPinStateUpdate);
this->mainWindow.setInsightConfig(this->insightConfig);
this->mainWindow.setEnvironmentConfig(this->environmentConfig);
this->mainWindow.init(
this->application,
*(this->insightWorker),
targetDescriptor
);
this->mainWindow.show();
} }
void Insight::shutdown() { void Insight::shutdown() {
@@ -107,7 +101,7 @@ void Insight::shutdown() {
} }
Logger::info("Shutting down Insight"); Logger::info("Shutting down Insight");
this->mainWindow.close(); this->mainWindow->close();
if (this->workerThread != nullptr && this->workerThread->isRunning()) { if (this->workerThread != nullptr && this->workerThread->isRunning()) {
this->workerThread->quit(); this->workerThread->quit();

View File

@@ -4,6 +4,7 @@
#include <QApplication> #include <QApplication>
#include "src/Helpers/Thread.hpp" #include "src/Helpers/Thread.hpp"
#include "InsightWorker/InsightWorker.hpp"
#include "src/ApplicationConfig.hpp" #include "src/ApplicationConfig.hpp"
#include "src/EventManager/EventManager.hpp" #include "src/EventManager/EventManager.hpp"
#include "src/EventManager/EventListener.hpp" #include "src/EventManager/EventListener.hpp"
@@ -37,7 +38,7 @@ namespace Bloom
QApplication application; QApplication application;
InsightWorker* insightWorker = new InsightWorker(this->eventManager); InsightWorker* insightWorker = new InsightWorker(this->eventManager);
InsightWindow mainWindow; InsightWindow* mainWindow = new InsightWindow(this->application, *(this->insightWorker));
TargetControllerConsole targetControllerConsole = TargetControllerConsole( TargetControllerConsole targetControllerConsole = TargetControllerConsole(
this->eventManager, this->eventManager,

View File

@@ -24,8 +24,7 @@ namespace Bloom
public: public:
InsightWorkerTaskState state; InsightWorkerTaskState state;
InsightWorkerTask() = default; InsightWorkerTask(): QObject(nullptr) {};
InsightWorkerTask(QObject* parent): QObject(parent) {};
void execute(TargetControllerConsole& targetControllerConsole); void execute(TargetControllerConsole& targetControllerConsole);

View File

@@ -18,8 +18,8 @@ namespace Bloom
void run(TargetControllerConsole& targetControllerConsole) override; void run(TargetControllerConsole& targetControllerConsole) override;
public: public:
ReadTargetRegisters(const Targets::TargetRegisterDescriptors& descriptors, QObject* parent): ReadTargetRegisters(const Targets::TargetRegisterDescriptors& descriptors):
InsightWorkerTask(nullptr), descriptors(descriptors) {} InsightWorkerTask(), descriptors(descriptors) {}
signals: signals:
void targetRegistersRead(Targets::TargetRegisters registers); void targetRegistersRead(Targets::TargetRegisters registers);

View File

@@ -0,0 +1,7 @@
#include "RefreshTargetPinStates.hpp"
using namespace Bloom;
void RefreshTargetPinStates::run(TargetControllerConsole& targetControllerConsole) {
emit this->targetPinStatesRetrieved(targetControllerConsole.getPinStates(this->variantId));
}

View File

@@ -0,0 +1,27 @@
#pragma once
#include <QObject>
#include <QString>
#include "InsightWorkerTask.hpp"
#include "src/Targets/TargetVariant.hpp"
#include "src/Targets/TargetPinDescriptor.hpp"
namespace Bloom
{
class RefreshTargetPinStates: public InsightWorkerTask
{
Q_OBJECT
private:
int variantId;
protected:
void run(TargetControllerConsole& targetControllerConsole) override;
public:
RefreshTargetPinStates(int variantId): InsightWorkerTask(), variantId(variantId) {}
signals:
void targetPinStatesRetrieved(Bloom::Targets::TargetPinStateMappingType pinStatesByNumber);
};
}

View File

@@ -6,10 +6,13 @@
#include "AboutWindow.hpp" #include "AboutWindow.hpp"
#include "Widgets/TargetWidgets/DIP/DualInlinePackageWidget.hpp" #include "Widgets/TargetWidgets/DIP/DualInlinePackageWidget.hpp"
#include "Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.hpp" #include "Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.hpp"
#include "src/Logger/Logger.hpp" #include "src/Logger/Logger.hpp"
#include "src/Exceptions/Exception.hpp" #include "src/Exceptions/Exception.hpp"
#include "src/Targets/TargetDescriptor.hpp"
#include "src/Helpers/Paths.hpp" #include "src/Helpers/Paths.hpp"
#include "src/Targets/TargetDescriptor.hpp"
#include "AboutWindow.hpp"
using namespace Bloom; using namespace Bloom;
using namespace Bloom::Exceptions; using namespace Bloom::Exceptions;
@@ -22,12 +25,10 @@ using Bloom::Targets::TargetVariant;
using Bloom::Targets::TargetPackage; using Bloom::Targets::TargetPackage;
using Bloom::Targets::TargetPinDescriptor; using Bloom::Targets::TargetPinDescriptor;
void InsightWindow::init( InsightWindow::InsightWindow(
QApplication& application, QApplication& application,
TargetDescriptor targetDescriptor InsightWorker& insightWorker
) { ): QObject(&application), insightWorker(insightWorker) {
this->targetDescriptor = std::move(targetDescriptor);
auto mainWindowUiFile = QFile( auto mainWindowUiFile = QFile(
QString::fromStdString(Paths::compiledResourcesPath() QString::fromStdString(Paths::compiledResourcesPath()
+ "/src/Insight/UserInterfaces/InsightWindow/UiFiles/InsightWindow.ui" + "/src/Insight/UserInterfaces/InsightWindow/UiFiles/InsightWindow.ui"
@@ -85,9 +86,11 @@ void InsightWindow::init(
this->footer = this->mainWindowWidget->findChild<QWidget*>("footer"); this->footer = this->mainWindowWidget->findChild<QWidget*>("footer");
this->targetStatusLabel = this->footer->findChild<QLabel*>("target-state"); this->targetStatusLabel = this->footer->findChild<QLabel*>("target-state");
this->programCounterValueLabel = this->footer->findChild<QLabel*>("target-program-counter-value"); this->programCounterValueLabel = this->footer->findChild<QLabel*>("target-program-counter-value");
}
void InsightWindow::init(TargetDescriptor targetDescriptor) {
this->targetDescriptor = std::move(targetDescriptor);
this->activate(); this->activate();
/* /*
* Do not delete svgWidget. It seems like it's absolutely pointless, but it's really not. I know this is gross but * Do not delete svgWidget. It seems like it's absolutely pointless, but it's really not. I know this is gross but
* I don't seem to have any other option. * I don't seem to have any other option.
@@ -316,6 +319,7 @@ void InsightWindow::selectVariant(const TargetVariant* variant) {
this->targetPackageWidget = new InsightTargetWidgets::Dip::DualInlinePackageWidget( this->targetPackageWidget = new InsightTargetWidgets::Dip::DualInlinePackageWidget(
*variant, *variant,
this, this,
this->insightWorker,
this->ioContainerWidget this->ioContainerWidget
); );
@@ -323,6 +327,7 @@ void InsightWindow::selectVariant(const TargetVariant* variant) {
this->targetPackageWidget = new InsightTargetWidgets::Qfp::QuadFlatPackageWidget( this->targetPackageWidget = new InsightTargetWidgets::Qfp::QuadFlatPackageWidget(
*variant, *variant,
this, this,
this->insightWorker,
this->ioContainerWidget this->ioContainerWidget
); );
} }
@@ -356,10 +361,6 @@ void InsightWindow::toggleUi(bool disable) {
this->refreshIoInspectionButton->repaint(); this->refreshIoInspectionButton->repaint();
} }
if (this->ioContainerWidget != nullptr) {
this->ioContainerWidget->setDisabled(disable);
this->ioContainerWidget->repaint();
}
} }
void InsightWindow::onTargetControllerSuspended() { void InsightWindow::onTargetControllerSuspended() {
@@ -418,14 +419,10 @@ void InsightWindow::onTargetStateUpdate(TargetState newState) {
if (newState == TargetState::RUNNING) { if (newState == TargetState::RUNNING) {
this->targetStatusLabel->setText("Running"); this->targetStatusLabel->setText("Running");
this->programCounterValueLabel->setText("-"); this->programCounterValueLabel->setText("-");
this->toggleUi(true);
} else if (newState == TargetState::STOPPED) { } else if (newState == TargetState::STOPPED) {
this->targetStatusLabel->setText("Stopped"); this->targetStatusLabel->setText("Stopped");
this->toggleUi(false);
if (this->selectedVariant != nullptr) {
emit this->refreshTargetPinStates(this->selectedVariant->id);
}
} else { } else {
this->targetStatusLabel->setText("Unknown"); this->targetStatusLabel->setText("Unknown");
@@ -444,21 +441,6 @@ void InsightWindow::onTargetIoPortsUpdate() {
} }
} }
void InsightWindow::onTargetPinStatesUpdate(int variantId, Bloom::Targets::TargetPinStateMappingType pinStatesByNumber) {
if (this->targetPackageWidget != nullptr
&& this->selectedVariant != nullptr
&& this->selectedVariant->id == variantId
) {
this->targetPackageWidget->updatePinStates(pinStatesByNumber);
if (this->targetState == TargetState::STOPPED && this->uiDisabled) {
this->toggleUi(false);
} else {
this->targetPackageWidget->repaint();
}
}
}
void InsightWindow::togglePinIoState(InsightTargetWidgets::TargetPinWidget* pinWidget) { void InsightWindow::togglePinIoState(InsightTargetWidgets::TargetPinWidget* pinWidget) {
auto pinState = pinWidget->getPinState(); auto pinState = pinWidget->getPinState();

View File

@@ -6,13 +6,16 @@
#include <memory> #include <memory>
#include <optional> #include <optional>
#include "AboutWindow.hpp"
#include "src/ApplicationConfig.hpp" #include "src/ApplicationConfig.hpp"
#include "Widgets/TargetWidgets/TargetPackageWidget.hpp" #include "src/Insight/InsightWorker/InsightWorker.hpp"
#include "src/Targets/TargetState.hpp" #include "src/Targets/TargetState.hpp"
#include "src/Targets/TargetDescriptor.hpp" #include "src/Targets/TargetDescriptor.hpp"
#include "src/Targets/TargetVariant.hpp" #include "src/Targets/TargetVariant.hpp"
#include "Widgets/TargetWidgets/TargetPackageWidget.hpp"
#include "AboutWindow.hpp"
namespace Bloom namespace Bloom
{ {
class InsightWindow: public QObject class InsightWindow: public QObject
@@ -23,6 +26,8 @@ namespace Bloom
EnvironmentConfig environmentConfig; EnvironmentConfig environmentConfig;
TargetConfig targetConfig; TargetConfig targetConfig;
InsightWorker& insightWorker;
bool activated = false; bool activated = false;
Targets::TargetDescriptor targetDescriptor; Targets::TargetDescriptor targetDescriptor;
@@ -57,7 +62,7 @@ namespace Bloom
void deactivate(); void deactivate();
public: public:
InsightWindow() = default; InsightWindow(QApplication& application, InsightWorker& insightWorker);
void setEnvironmentConfig(const EnvironmentConfig& environmentConfig) { void setEnvironmentConfig(const EnvironmentConfig& environmentConfig) {
this->environmentConfig = environmentConfig; this->environmentConfig = environmentConfig;
@@ -68,17 +73,13 @@ namespace Bloom
this->insightConfig = insightConfig; this->insightConfig = insightConfig;
} }
void init( void init(Targets::TargetDescriptor targetDescriptor);
QApplication& application,
Targets::TargetDescriptor targetDescriptor
);
void show(); void show();
public slots: public slots:
void onTargetControllerSuspended(); void onTargetControllerSuspended();
void onTargetControllerResumed(const Bloom::Targets::TargetDescriptor& targetDescriptor); void onTargetControllerResumed(const Bloom::Targets::TargetDescriptor& targetDescriptor);
void onTargetPinStatesUpdate(int variantId, Bloom::Targets::TargetPinStateMappingType pinStatesByNumber);
void onTargetStateUpdate(Targets::TargetState newState); void onTargetStateUpdate(Targets::TargetState newState);
void onTargetProgramCounterUpdate(quint32 programCounter); void onTargetProgramCounterUpdate(quint32 programCounter);
void onTargetIoPortsUpdate(); void onTargetIoPortsUpdate();

View File

@@ -1,3 +1,5 @@
#include "DualInlinePackageWidget.hpp"
#include <QPainter> #include <QPainter>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
@@ -6,7 +8,6 @@
#include <QFile> #include <QFile>
#include "../../../InsightWindow.hpp" #include "../../../InsightWindow.hpp"
#include "DualInlinePackageWidget.hpp"
#include "src/Logger/Logger.hpp" #include "src/Logger/Logger.hpp"
#include "src/Exceptions/Exception.hpp" #include "src/Exceptions/Exception.hpp"
#include "src/Helpers/Paths.hpp" #include "src/Helpers/Paths.hpp"
@@ -21,8 +22,9 @@ using Bloom::Targets::TargetVariant;
DualInlinePackageWidget::DualInlinePackageWidget( DualInlinePackageWidget::DualInlinePackageWidget(
const TargetVariant& targetVariant, const TargetVariant& targetVariant,
QObject* insightWindowObj, QObject* insightWindowObj,
InsightWorker& insightWorker,
QWidget* parent QWidget* parent
): TargetPackageWidget(targetVariant, insightWindowObj, parent) { ): TargetPackageWidget(targetVariant, insightWorker, parent) {
auto stylesheetFile = QFile(QString::fromStdString( auto stylesheetFile = QFile(QString::fromStdString(
Paths::compiledResourcesPath() Paths::compiledResourcesPath()
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/Stylesheets/DualInlinePackage.qss" + "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/Stylesheets/DualInlinePackage.qss"

View File

@@ -30,6 +30,11 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
void drawWidget(QPainter& painter); void drawWidget(QPainter& painter);
public: public:
DualInlinePackageWidget(const Targets::TargetVariant& targetVariant, QObject* insightWindowObj, QWidget* parent); DualInlinePackageWidget(
const Targets::TargetVariant& targetVariant,
QObject* insightWindowObj,
InsightWorker& insightWorker,
QWidget* parent
);
}; };
} }

View File

@@ -1,3 +1,5 @@
#include "QuadFlatPackageWidget.hpp"
#include <QPainter> #include <QPainter>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
@@ -6,7 +8,6 @@
#include <QFile> #include <QFile>
#include "../../../InsightWindow.hpp" #include "../../../InsightWindow.hpp"
#include "QuadFlatPackageWidget.hpp"
#include "src/Helpers/Paths.hpp" #include "src/Helpers/Paths.hpp"
#include "PinWidget.hpp" #include "PinWidget.hpp"
#include "BodyWidget.hpp" #include "BodyWidget.hpp"
@@ -17,8 +18,9 @@ using namespace Bloom::Targets;
QuadFlatPackageWidget::QuadFlatPackageWidget( QuadFlatPackageWidget::QuadFlatPackageWidget(
const TargetVariant& targetVariant, const TargetVariant& targetVariant,
QObject* insightWindowObj, QObject* insightWindowObj,
InsightWorker& insightWorker,
QWidget* parent QWidget* parent
): TargetPackageWidget(targetVariant, insightWindowObj, parent) { ): TargetPackageWidget(targetVariant, insightWorker, parent) {
assert((targetVariant.pinDescriptorsByNumber.size() % 4) == 0); assert((targetVariant.pinDescriptorsByNumber.size() % 4) == 0);
auto stylesheetFile = QFile(QString::fromStdString( auto stylesheetFile = QFile(QString::fromStdString(

View File

@@ -32,6 +32,11 @@ namespace Bloom::Widgets::InsightTargetWidgets::Qfp
void drawWidget(QPainter& painter); void drawWidget(QPainter& painter);
public: public:
QuadFlatPackageWidget(const Targets::TargetVariant& targetVariant, QObject* insightWindowObj, QWidget* parent); QuadFlatPackageWidget(
const Targets::TargetVariant& targetVariant,
QObject* insightWindowObj,
InsightWorker& insightWorker,
QWidget* parent
);
}; };
} }

View File

@@ -0,0 +1,87 @@
#include "TargetPackageWidget.hpp"
#include <QEvent>
#include "src/Insight/InsightWorker/Tasks/RefreshTargetPinStates.hpp"
using namespace Bloom;
using namespace Bloom::Widgets::InsightTargetWidgets;
using Bloom::Targets::TargetState;
TargetPackageWidget::TargetPackageWidget(
Targets::TargetVariant targetVariant,
InsightWorker& insightWorker,
QWidget* parent
): QWidget(parent), targetVariant(std::move(targetVariant)), insightWorker(insightWorker) {
this->connect(
&(this->insightWorker),
&InsightWorker::targetStateUpdated,
this,
&TargetPackageWidget::onTargetStateChanged
);
this->connect(
&(this->insightWorker),
&InsightWorker::targetPinStatesUpdated,
this,
[this] (int variantId, const Targets::TargetPinStateMappingType& pinStatesByNumber) {
if (variantId == this->targetVariant.id) {
this->updatePinStates(pinStatesByNumber);
if (this->targetState == TargetState::STOPPED && !this->isEnabled()) {
this->setDisabled(false);
}
}
}
);
this->setDisabled(true);
}
void TargetPackageWidget::refreshPinStates(std::optional<std::function<void(void)>> callback) {
auto refreshTask = new RefreshTargetPinStates(this->targetVariant.id);
this->connect(
refreshTask,
&RefreshTargetPinStates::targetPinStatesRetrieved,
this,
&TargetPackageWidget::updatePinStates
);
if (callback.has_value()) {
this->connect(
refreshTask,
&InsightWorkerTask::completed,
this,
callback.value()
);
}
this->insightWorker.queueTask(refreshTask);
}
void TargetPackageWidget::updatePinStates(const Targets::TargetPinStateMappingType& pinStatesByNumber) {
for (auto& pinWidget : this->pinWidgets) {
auto pinNumber = pinWidget->getPinNumber();
if (pinStatesByNumber.contains(pinNumber)) {
pinWidget->updatePinState(pinStatesByNumber.at(pinNumber));
}
}
this->repaint();
}
void TargetPackageWidget::onTargetStateChanged(TargetState newState) {
this->targetState = newState;
if (newState == TargetState::RUNNING) {
this->setDisabled(true);
} else if (newState == TargetState::STOPPED) {
this->refreshPinStates([this] {
if (this->targetState == TargetState::STOPPED) {
this->setDisabled(false);
}
});
}
}

View File

@@ -5,6 +5,8 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include "src/Insight/InsightWorker/InsightWorker.hpp"
#include "TargetPinWidget.hpp" #include "TargetPinWidget.hpp"
#include "src/Targets/TargetVariant.hpp" #include "src/Targets/TargetVariant.hpp"
#include "src/Targets/TargetDescriptor.hpp" #include "src/Targets/TargetDescriptor.hpp"
@@ -19,19 +21,17 @@ namespace Bloom::Widgets::InsightTargetWidgets
Q_OBJECT Q_OBJECT
protected: protected:
Targets::TargetVariant targetVariant; Targets::TargetVariant targetVariant;
InsightWorker& insightWorker;
std::vector<TargetPinWidget*> pinWidgets; std::vector<TargetPinWidget*> pinWidgets;
public: Targets::TargetState targetState = Targets::TargetState::UNKNOWN;
TargetPackageWidget(Targets::TargetVariant targetVariant, QObject* insightWindowObj, QWidget* parent):
QWidget(parent), targetVariant(std::move(targetVariant)) {};
virtual void updatePinStates(std::map<int, Targets::TargetPinState> pinStatesByNumber) { protected slots:
for (auto& pinWidget : this->pinWidgets) { virtual void updatePinStates(const Targets::TargetPinStateMappingType& pinStatesByNumber);
auto pinNumber = pinWidget->getPinNumber(); void onTargetStateChanged(Targets::TargetState newState);
if (pinStatesByNumber.contains(pinNumber)) {
pinWidget->updatePinState(pinStatesByNumber.at(pinNumber)); public:
} TargetPackageWidget(Targets::TargetVariant targetVariant, InsightWorker& insightWorker, QWidget* parent);
} virtual void refreshPinStates(std::optional<std::function<void(void)>> callback = std::nullopt);
}
}; };
} }

View File

@@ -116,6 +116,13 @@ void TargetControllerConsole::requestPinStates(int variantId) {
this->eventManager.triggerEvent(requestEvent); this->eventManager.triggerEvent(requestEvent);
} }
Targets::TargetPinStateMappingType TargetControllerConsole::getPinStates(int variantId) {
auto requestEvent = std::make_shared<RetrieveTargetPinStates>();
requestEvent->variantId = variantId;
return this->triggerTargetControllerEventAndWaitForResponse(requestEvent)->pinSatesByNumber;
}
void TargetControllerConsole::setPinState(int variantId, TargetPinDescriptor pinDescriptor, TargetPinState pinState) { void TargetControllerConsole::setPinState(int variantId, TargetPinDescriptor pinDescriptor, TargetPinState pinState) {
auto updateEvent = std::make_shared<SetTargetPinState>(); auto updateEvent = std::make_shared<SetTargetPinState>();
updateEvent->variantId = variantId; updateEvent->variantId = variantId;

View File

@@ -182,6 +182,20 @@ namespace Bloom
*/ */
void removeBreakpoint(Targets::TargetBreakpoint breakpoint); void removeBreakpoint(Targets::TargetBreakpoint breakpoint);
/**
* Requests a pin state refresh from the TargetController, for a specific target variant.
*
* @param variantId
*/
void requestPinStates(int variantId);
/**
* Retrieves the pin states for a particular target variant.
*
* @param variantId
*/
Targets::TargetPinStateMappingType getPinStates(int variantId);
/** /**
* Requests a pin state update on the target, for a specific pin. * Requests a pin state update on the target, for a specific pin.
* *
@@ -190,12 +204,5 @@ namespace Bloom
* @param pinState * @param pinState
*/ */
void setPinState(int variantId, Targets::TargetPinDescriptor pinDescriptor, Targets::TargetPinState pinState); void setPinState(int variantId, Targets::TargetPinDescriptor pinDescriptor, Targets::TargetPinState pinState);
/**
* Requests a pin state refresh from the TargetController, for a specific target variant.
*
* @param variantId
*/
void requestPinStates(int variantId);
}; };
} }