From 271330d5fdc260e3b940e5ad632ba995e271a99e Mon Sep 17 00:00:00 2001 From: uvos Date: Tue, 3 Dec 2024 00:24:35 +0100 Subject: [PATCH] Add the ability to enable and disable actors from the ui add safe and timeout to the regulator actor --- src/actors/regulator.cpp | 36 ++++++++++++++-- src/actors/regulator.h | 26 +++++++++-- src/ui/actorsettingsdialog.cpp | 19 +++++++-- src/ui/actorsettingsdialog.h | 1 + src/ui/actorsettingsdialog.ui | 57 +++++++++++++++++++++++++ src/ui/actorwidgets/regulatorwdiget.cpp | 5 +++ src/ui/actorwidgets/regulatorwdiget.ui | 52 +++++++++++++++++----- 7 files changed, 176 insertions(+), 20 deletions(-) diff --git a/src/actors/regulator.cpp b/src/actors/regulator.cpp index d334cce..b3ea5f6 100644 --- a/src/actors/regulator.cpp +++ b/src/actors/regulator.cpp @@ -4,12 +4,16 @@ Regulator::Regulator(const Sensor sensor, QObject* parent): Actor(parent), sensor_(sensor) { - + timer.setSingleShot(true); + timer.start(timeout_*1000); + connect(&timer, &QTimer::timeout, this, &Regulator::timeout); } Regulator::Regulator(QObject* parent): Actor(parent) { - + timer.setSingleShot(true); + timer.start(timeout_*1000); + connect(&timer, &QTimer::timeout, this, &Regulator::timeout); } void Regulator::setSensor(const Sensor sensor) @@ -21,6 +25,7 @@ void Regulator::sensorEvent(Sensor sensor) { if(active && sensor == sensor_) { + timer.start(timeout_*1000); if( sensor.field < setPoint_-band_ && (sensor.field < sensor_.field || sensor_.field > setPoint_-band_ || first) ) { sigValue(triggerValue); @@ -39,9 +44,15 @@ void Regulator::makeInactive() first = true; if(active) sigValue(!triggerValue); + timer.stop(); Actor::makeInactive(); } +void Regulator::timeout() +{ + sigValue(safeValue_); +} + void Regulator::setPoint(float setPoint) { setPoint_ = setPoint; @@ -57,12 +68,25 @@ void Regulator::setInvert( bool invert ) invert_ = invert; } +void Regulator::setSafeValue(int value) +{ + safeValue_ = value; +} + +void Regulator::setTimeout(int value) +{ + timeout_ = value; + timer.start(timeout_*1000); +} + void Regulator::store(QJsonObject& json) { json["Type"] = "Regulator"; Actor::store(json); json["Band"] = band_; json["SetPoint"] = setPoint_; + json["SafeValue"] = safeValue_; + json["Timeout"] = timeout_; json["SensorType"] = static_cast(sensor_.type); json["SensorId"] = static_cast(sensor_.id); json["SensorField"] = sensor_.field; @@ -74,15 +98,21 @@ void Regulator::load(const QJsonObject& json, bool preserve) Actor::load(json, preserve); band_ = json["Band"].toDouble(1); setPoint_ = json["SetPoint"].toDouble(22); + safeValue_ = json["SafeValue"].toDouble(0); + timeout_ = json["Timeout"].toDouble(1800); sensor_.type = json["SensorType"].toInt(0); sensor_.id = json["SensorId"].toInt(0); sensor_.field = json["SensorField"].toInt(0); sensor_.name = json["SensorName"].toString("Sensor"); + timer.start(timeout_*1000); } QString Regulator::getName() const { - if(name_.size() > 0) return name_; + if(name_.size() > 0) + { + return name_; + } else { QString string; diff --git a/src/actors/regulator.h b/src/actors/regulator.h index cc742a6..733d643 100644 --- a/src/actors/regulator.h +++ b/src/actors/regulator.h @@ -1,4 +1,7 @@ #pragma once + +#include + #include "actor.h" #include "../sensors/sensor.h" @@ -11,17 +14,26 @@ private: float setPoint_ = 0; float band_ = 1; bool invert_ = false; + int timeout_ = 1800; + int safeValue_ = 0; + QTimer timer; bool first = true; +private slots: + + void timeout(); + public slots: void sensorEvent(Sensor sensor); void setSensor(const Sensor sensor); - void setPoint( float setPoint ); - void setBand ( float band ); - void setInvert( bool invert ); + void setPoint(float setPoint ); + void setBand (float band ); + void setInvert(bool invert ); + void setSafeValue(int value); + void setTimeout(int value); virtual void makeInactive() override; public: @@ -34,6 +46,14 @@ public: { return setPoint_; } + int getSafeValue() + { + return safeValue_; + } + int getTimeout() + { + return timeout_; + } Regulator(const Sensor sensor, QObject* parent = nullptr); Regulator(QObject* parent = nullptr); Sensor getSensor() diff --git a/src/ui/actorsettingsdialog.cpp b/src/ui/actorsettingsdialog.cpp index 29f313b..f89a1a0 100644 --- a/src/ui/actorsettingsdialog.cpp +++ b/src/ui/actorsettingsdialog.cpp @@ -83,14 +83,20 @@ void ActorSettingsDialog::init() connect(ui->comboBox_action, SIGNAL(currentIndexChanged(int)), this, SLOT(changeAction(int))); connect(ui->spinBox, SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int))); connect(ui->pushButton_editItem, &QPushButton::clicked, this, &ActorSettingsDialog::editAsItem); + connect(ui->pushButton_enable, &QPushButton::clicked, this, &ActorSettingsDialog::setEnabled); ui->spinBox->hide(); ui->spinBox->setValue(actor_->getTriggerValue()); - if(actor_->getTriggerValue() == 0) ui->comboBox_action->setCurrentIndex(0); - else if(actor_->getTriggerValue() == 1) ui->comboBox_action->setCurrentIndex(1); - else ui->comboBox_action->setCurrentIndex(2); + if(actor_->getTriggerValue() == 0) + ui->comboBox_action->setCurrentIndex(0); + else if(actor_->getTriggerValue() == 1) + ui->comboBox_action->setCurrentIndex(1); + else + ui->comboBox_action->setCurrentIndex(2); ui->label_Exausted->setText(actor_->isExausted() ? "True" : "False"); + ui->label_Enabled->setText(actor_->isActive() ? "True" : "False"); + ui->pushButton_enable->setText(actor_->isActive() ? "Disable" : "Enable"); } ActorSettingsDialog::~ActorSettingsDialog() @@ -104,6 +110,13 @@ void ActorSettingsDialog::editAsItem() itemSettingsDiag.exec(); } +void ActorSettingsDialog::setEnabled() +{ + actor_->setActive(!actor_->isActive()); + ui->label_Enabled->setText(actor_->isActive() ? "True" : "False"); + ui->pushButton_enable->setText(actor_->isActive() ? "Disable" : "Enable"); +} + void ActorSettingsDialog::valueChanged(int value) { actor_->setTriggerValue(value); diff --git a/src/ui/actorsettingsdialog.h b/src/ui/actorsettingsdialog.h index bd1b9e7..16c4d68 100644 --- a/src/ui/actorsettingsdialog.h +++ b/src/ui/actorsettingsdialog.h @@ -41,6 +41,7 @@ private slots: void changeAction(int index); void valueChanged(int value); void editAsItem(); + void setEnabled(); private: diff --git a/src/ui/actorsettingsdialog.ui b/src/ui/actorsettingsdialog.ui index 6b0a057..0334dec 100644 --- a/src/ui/actorsettingsdialog.ui +++ b/src/ui/actorsettingsdialog.ui @@ -85,6 +85,63 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Enabled: + + + + + + + + 0 + 0 + + + + True + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Enable + + + diff --git a/src/ui/actorwidgets/regulatorwdiget.cpp b/src/ui/actorwidgets/regulatorwdiget.cpp index 967d792..30b0623 100644 --- a/src/ui/actorwidgets/regulatorwdiget.cpp +++ b/src/ui/actorwidgets/regulatorwdiget.cpp @@ -24,12 +24,17 @@ RegulatorWdiget::RegulatorWdiget(std::shared_ptr regulator, SensorSto } ui->doubleSpinBox_setPoint->setValue(regulator->getSetPoint()); ui->doubleSpinBox_band->setValue(regulator->getBand()); + ui->spinBox_safe->setValue(regulator_->getSafeValue()); + ui->spinBox_timeout->setValue(regulator_->getTimeout()); connect(ui->listView, &SensorListWidget::clicked, this, &RegulatorWdiget::setSensor); connect(ui->doubleSpinBox_setPoint, SIGNAL(valueChanged(double)), this, SLOT(setPoint(double))); connect(ui->doubleSpinBox_band, SIGNAL(valueChanged(double)), this, SLOT(setBand(double))); + connect(ui->spinBox_safe, SIGNAL(valueChanged(int)), regulator_.get(), SLOT(setSafeValue(int))); + connect(ui->spinBox_timeout, SIGNAL(valueChanged(int)), regulator_.get(), SLOT(setTimeout(int))); } + void RegulatorWdiget::setPoint(double in) { regulator_->setPoint(in); diff --git a/src/ui/actorwidgets/regulatorwdiget.ui b/src/ui/actorwidgets/regulatorwdiget.ui index db159cf..a6784a3 100644 --- a/src/ui/actorwidgets/regulatorwdiget.ui +++ b/src/ui/actorwidgets/regulatorwdiget.ui @@ -38,15 +38,8 @@ - - - - - Set Point - - - - + + -9999.989999999999782 @@ -56,7 +49,7 @@ - + @@ -69,9 +62,46 @@ - + + + + Timeout + + + + + + + Set Point + + + + + + + + Safety Value + + + + + + + + + + s + + + 999999999 + + + 1800 + + +