diff --git a/SHinterface.pro b/SHinterface.pro index c7ff09f..ab27aa7 100644 --- a/SHinterface.pro +++ b/SHinterface.pro @@ -4,7 +4,7 @@ # #------------------------------------------------- -QT += core gui widgets network multimedia +QT += core gui widgets network multimedia QT += serialport diff --git a/src/actors/regulator.cpp b/src/actors/regulator.cpp index b3ea5f6..d334cce 100644 --- a/src/actors/regulator.cpp +++ b/src/actors/regulator.cpp @@ -4,16 +4,12 @@ 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) @@ -25,7 +21,6 @@ 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); @@ -44,15 +39,9 @@ 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; @@ -68,25 +57,12 @@ 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; @@ -98,21 +74,15 @@ 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 733d643..cc742a6 100644 --- a/src/actors/regulator.h +++ b/src/actors/regulator.h @@ -1,7 +1,4 @@ #pragma once - -#include - #include "actor.h" #include "../sensors/sensor.h" @@ -14,26 +11,17 @@ 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 setSafeValue(int value); - void setTimeout(int value); + void setPoint( float setPoint ); + void setBand ( float band ); + void setInvert( bool invert ); virtual void makeInactive() override; public: @@ -46,14 +34,6 @@ 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/microcontroller.cpp b/src/microcontroller.cpp index ba5f54b..c244796 100644 --- a/src/microcontroller.cpp +++ b/src/microcontroller.cpp @@ -127,16 +127,11 @@ std::shared_ptr Microcontroller::processRelayLine(const QString& buffer) if(bufferList.size() >= 9 && buffer.startsWith("ITEM NUMBER:")) { QString name; - for(int i = 10; i < bufferList.size(); i++) - name.append(bufferList[i] + ' '); - if(name.size() > 1) - name.remove(name.size()-1, 1); - else - name = "Relay " + QString::number(bufferList[1].toInt(nullptr, 2)); - return std::shared_ptr(new Relay(bufferList[2].toInt(), - name, - bufferList[6].toInt(nullptr, 2), - bufferList[8].toInt())); + for(int i = 10; i < bufferList.size(); i++) name.append(bufferList[i] + ' '); + if(name.size() > 1)name.remove(name.size()-1, 1); + else name = "Relay " + QString::number(bufferList[1].toInt(nullptr, 2)); + return std::shared_ptr( new Relay(bufferList[2].toInt(), name, bufferList[4].toInt(nullptr, 2), + bufferList[8].toInt())); } return nullptr; } diff --git a/src/ui/actorsettingsdialog.cpp b/src/ui/actorsettingsdialog.cpp index f89a1a0..29f313b 100644 --- a/src/ui/actorsettingsdialog.cpp +++ b/src/ui/actorsettingsdialog.cpp @@ -83,20 +83,14 @@ 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() @@ -110,13 +104,6 @@ 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 16c4d68..bd1b9e7 100644 --- a/src/ui/actorsettingsdialog.h +++ b/src/ui/actorsettingsdialog.h @@ -41,7 +41,6 @@ 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 0334dec..6b0a057 100644 --- a/src/ui/actorsettingsdialog.ui +++ b/src/ui/actorsettingsdialog.ui @@ -85,63 +85,6 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - Enabled: - - - - - - - - 0 - 0 - - - - True - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Enable - - - diff --git a/src/ui/actorwidgets/polynomalactorwidget.cpp b/src/ui/actorwidgets/polynomalactorwidget.cpp index 930a3f8..1c9476b 100644 --- a/src/ui/actorwidgets/polynomalactorwidget.cpp +++ b/src/ui/actorwidgets/polynomalactorwidget.cpp @@ -46,5 +46,5 @@ void PolynomalActorWidget::setPow() void PolynomalActorWidget::setSensor(const QModelIndex &index) { - actor_->setSensor(ui->listView->getSensorForIndex(index)); + actor_->setSensor(sensors_->getSensors()->at(index.row())); } diff --git a/src/ui/actorwidgets/regulatorwdiget.cpp b/src/ui/actorwidgets/regulatorwdiget.cpp index b005240..967d792 100644 --- a/src/ui/actorwidgets/regulatorwdiget.cpp +++ b/src/ui/actorwidgets/regulatorwdiget.cpp @@ -24,17 +24,12 @@ 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); @@ -47,7 +42,7 @@ void RegulatorWdiget::setBand(double band) void RegulatorWdiget::setSensor(const QModelIndex &index) { - regulator_->setSensor(ui->listView->getSensorForIndex(index)); - setPoint(ui->listView->getSensorForIndex(index).field); - ui->doubleSpinBox_setPoint->setValue(ui->listView->getSensorForIndex(index).field); + regulator_->setSensor(sensors_->getSensors()->at(index.row())); + setPoint(sensors_->getSensors()->at(index.row()).field); + ui->doubleSpinBox_setPoint->setValue(sensors_->getSensors()->at(index.row()).field); } diff --git a/src/ui/actorwidgets/regulatorwdiget.ui b/src/ui/actorwidgets/regulatorwdiget.ui index a6784a3..db159cf 100644 --- a/src/ui/actorwidgets/regulatorwdiget.ui +++ b/src/ui/actorwidgets/regulatorwdiget.ui @@ -38,8 +38,15 @@ - - + + + + + Set Point + + + + -9999.989999999999782 @@ -49,7 +56,7 @@ - + @@ -62,46 +69,9 @@ - - - - Timeout - - - - - - - Set Point - - - - + - - - - Safety Value - - - - - - - - - - s - - - 999999999 - - - 1800 - - - diff --git a/src/ui/actorwidgets/sensoractorwidget.cpp b/src/ui/actorwidgets/sensoractorwidget.cpp index 2718b1b..41276e9 100644 --- a/src/ui/actorwidgets/sensoractorwidget.cpp +++ b/src/ui/actorwidgets/sensoractorwidget.cpp @@ -17,12 +17,9 @@ SensorActorWidget::SensorActorWidget(std::shared_ptr sensorActor, S ui->label->hide(); } - if(sensorActor_->getSloap() == SensorActor::SLOPE_UP) - ui->comboBox_slope->setCurrentIndex(0); - else if(sensorActor_->getSloap() == SensorActor::SLOPE_DOWN) - ui->comboBox_slope->setCurrentIndex(1); - else if(sensorActor_->getSloap() == SensorActor::SLOPE_BOTH) - ui->comboBox_slope->setCurrentIndex(2); + if(sensorActor_->getSloap() == SensorActor::SLOPE_UP) ui->comboBox_slope->setCurrentIndex(0); + else if(sensorActor_->getSloap() == SensorActor::SLOPE_DOWN) ui->comboBox_slope->setCurrentIndex(1); + else if(sensorActor_->getSloap() == SensorActor::SLOPE_BOTH) ui->comboBox_slope->setCurrentIndex(2); ui->doubleSpinBox_threshold->setValue(sensorActor_->getThreshold()); @@ -50,5 +47,6 @@ void SensorActorWidget::setSlope(int index) void SensorActorWidget::setSensor(const QModelIndex &index) { - sensorActor_->setSensor(ui->listView->getSensorForIndex(index)); + sensorActor_->setSensor(sensors_->getSensors()->at(index.row())); + qDebug()<<"Selected "<getSensors()->at(index.row()).name; } diff --git a/src/ui/sensorlistwidget.cpp b/src/ui/sensorlistwidget.cpp index 827ab2e..ce4fe4f 100644 --- a/src/ui/sensorlistwidget.cpp +++ b/src/ui/sensorlistwidget.cpp @@ -56,7 +56,7 @@ void SensorListWidget::sensorsChanged(std::vector sensors) else itemString.append("\"Silent\""); } - setItem(static_cast(row), 0, new SensorListItem(sensors[i].name + (sensors[i].hidden ? " (H)" : ""), sensors[i])); + setItem(static_cast(row), 0, new QTableWidgetItem(sensors[i].name + (sensors[i].hidden ? " (H)" : ""))); setItem(static_cast(row), 1, new QTableWidgetItem(itemString)); if(sensors[i].type <= 128) setItem(static_cast(row), 2, new QTableWidgetItem(sensors[i].lastSeen.time().toString("hh:mm"))); @@ -67,23 +67,8 @@ void SensorListWidget::sensorsChanged(std::vector sensors) resizeColumnsToContents(); } -const Sensor& SensorListWidget::getSensorForIndex(const QModelIndex &index) -{ - return static_cast(item(index.row(), 0))->getSensor(); -} - void SensorListWidget::setShowHidden(const bool showHidden) { showHidden_=showHidden; } -const Sensor& SensorListItem::getSensor() -{ - return sensor; -} - -SensorListItem::SensorListItem(const QString& text, const Sensor& sensor): - QTableWidgetItem(text, 1001), sensor(sensor) -{ -} - diff --git a/src/ui/sensorlistwidget.h b/src/ui/sensorlistwidget.h index c963a05..13776a6 100644 --- a/src/ui/sensorlistwidget.h +++ b/src/ui/sensorlistwidget.h @@ -3,15 +3,6 @@ #include #include "../sensors/sensor.h" -class SensorListItem : public QTableWidgetItem -{ - Sensor sensor; - -public: - const Sensor& getSensor(); - SensorListItem(const QString& text, const Sensor& sensor); -}; - class SensorListWidget : public QTableWidget { Q_OBJECT @@ -20,11 +11,10 @@ class SensorListWidget : public QTableWidget public: - SensorListWidget(const bool showHidden = true, QWidget* parent = nullptr); + SensorListWidget(const bool showHidden = true, QWidget *parent = nullptr); SensorListWidget(SensorStore& sensorStore, const bool showHidden = true, QWidget* parent = nullptr); virtual ~SensorListWidget() {} void setShowHidden(const bool showHidden); - const Sensor& getSensorForIndex(const QModelIndex &index); public slots: