Item Refactor complete
This commit is contained in:
parent
219fbfb4c7
commit
24c168cf64
17 changed files with 78 additions and 41 deletions
|
|
@ -17,17 +17,22 @@ Actor::~Actor()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actor::performAction()
|
void Actor::performValueAction(uint8_t value)
|
||||||
{
|
{
|
||||||
if(active)
|
if(active)
|
||||||
{
|
{
|
||||||
ItemUpdateRequest request;
|
ItemUpdateRequest request;
|
||||||
request.type = ITEM_UPDATE_ACTOR;
|
request.type = ITEM_UPDATE_ACTOR;
|
||||||
request.payload = ItemData(QRandomGenerator::global()->generate(), "Item", triggerValue);
|
request.payload = ItemData(QRandomGenerator::global()->generate(), "Item", value);
|
||||||
sigItemUpdate(request);
|
sigItemUpdate(request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Actor::performAction()
|
||||||
|
{
|
||||||
|
performValueAction(triggerValue);
|
||||||
|
}
|
||||||
|
|
||||||
void Actor::makeActive()
|
void Actor::makeActive()
|
||||||
{
|
{
|
||||||
active = true;
|
active = true;
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ protected:
|
||||||
bool exausted = false;
|
bool exausted = false;
|
||||||
|
|
||||||
void performAction();
|
void performAction();
|
||||||
|
void performValueAction(uint8_t value);
|
||||||
|
|
||||||
virtual void enactValue(uint8_t value) override;
|
virtual void enactValue(uint8_t value) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,19 @@ MultiFactorActor::MultiFactorActor(Actor* factorActor, const uint preCancleMin,
|
||||||
preCancleMin_(preCancleMin)
|
preCancleMin_(preCancleMin)
|
||||||
{
|
{
|
||||||
activationTime.setMSecsSinceEpoch(0);
|
activationTime.setMSecsSinceEpoch(0);
|
||||||
if(factorActor) connect(factorActor, &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
if(factorActor)
|
||||||
|
connect(factorActor, &Actor::sigItemUpdate, this, &MultiFactorActor::factorActorSlot);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiFactorActor::factorActorSlot(uint8_t value)
|
void MultiFactorActor::factorActorSlot(ItemUpdateRequest update)
|
||||||
{
|
{
|
||||||
if(value == factorDirection)
|
if(update.payload.getValue() == factorDirection)
|
||||||
{
|
{
|
||||||
activationTime = QDateTime::currentDateTime();
|
activationTime = QDateTime::currentDateTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiFactorActor::setValue(uint8_t value)
|
void MultiFactorActor::enactValue(uint8_t value)
|
||||||
{
|
{
|
||||||
if(value)
|
if(value)
|
||||||
{
|
{
|
||||||
|
|
@ -46,7 +47,7 @@ QString MultiFactorActor::getName() const
|
||||||
void MultiFactorActor::setFactorActor(std::shared_ptr<Actor> factorActor)
|
void MultiFactorActor::setFactorActor(std::shared_ptr<Actor> factorActor)
|
||||||
{
|
{
|
||||||
factorActor_=factorActor;
|
factorActor_=factorActor;
|
||||||
connect(factorActor_.get(), &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
connect(factorActor_.get(), &Actor::sigItemUpdate, this, &MultiFactorActor::factorActorSlot);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiFactorActor::store(QJsonObject &json)
|
void MultiFactorActor::store(QJsonObject &json)
|
||||||
|
|
@ -73,7 +74,7 @@ void MultiFactorActor::load(const QJsonObject &json, bool preserve)
|
||||||
}
|
}
|
||||||
if(factorActor_)
|
if(factorActor_)
|
||||||
{
|
{
|
||||||
connect(factorActor_.get(), &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
connect(factorActor_.get(), &Actor::sigItemUpdate, this, &MultiFactorActor::factorActorSlot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,17 +16,17 @@ private:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void factorActorSlot(uint8_t value);
|
void factorActorSlot(ItemUpdateRequest update);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
virtual void setValue(uint8_t value);
|
virtual void enactValue(uint8_t value) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MultiFactorActor(Actor* FactorActor = nullptr, const uint preCancleMin = 10, QObject *parent = nullptr);
|
MultiFactorActor(Actor* FactorActor = nullptr, const uint preCancleMin = 10, QObject *parent = nullptr);
|
||||||
|
|
||||||
virtual QString getName() const;
|
virtual QString getName() const override;
|
||||||
|
|
||||||
void setFactorActor(std::shared_ptr<Actor> factorActor);
|
void setFactorActor(std::shared_ptr<Actor> factorActor);
|
||||||
std::shared_ptr<Actor> getFactorActor()
|
std::shared_ptr<Actor> getFactorActor()
|
||||||
|
|
@ -52,8 +52,8 @@ public:
|
||||||
|
|
||||||
virtual ~MultiFactorActor() {}
|
virtual ~MultiFactorActor() {}
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json) override;
|
||||||
virtual void load(const QJsonObject& json, bool preserve);
|
virtual void load(const QJsonObject& json, bool preserve) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // REMINDERACTOR_H
|
#endif // REMINDERACTOR_H
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,8 @@ void PolynomalActor::sensorEvent(Sensor sensor)
|
||||||
+pow0_;
|
+pow0_;
|
||||||
if(result < 0) result = 0;
|
if(result < 0) result = 0;
|
||||||
else if(result > 254) result = 255;
|
else if(result > 254) result = 255;
|
||||||
if(result != prevValue)sigValue(static_cast<uint8_t>(result));
|
if(result != prevValue)
|
||||||
|
performValueAction(static_cast<uint8_t>(result));
|
||||||
prevValue = result;
|
prevValue = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,11 @@ void Regulator::sensorEvent(Sensor sensor)
|
||||||
timer.start(timeout_*1000);
|
timer.start(timeout_*1000);
|
||||||
if( sensor.field < setPoint_-band_ && (sensor.field < sensor_.field || sensor_.field > setPoint_-band_ || first) )
|
if( sensor.field < setPoint_-band_ && (sensor.field < sensor_.field || sensor_.field > setPoint_-band_ || first) )
|
||||||
{
|
{
|
||||||
sigValue(triggerValue);
|
performValueAction(triggerValue);
|
||||||
}
|
}
|
||||||
else if( sensor.field > setPoint_+band_ && (sensor.field > sensor_.field || sensor_.field < setPoint_+band_ || first) )
|
else if( sensor.field > setPoint_+band_ && (sensor.field > sensor_.field || sensor_.field < setPoint_+band_ || first) )
|
||||||
{
|
{
|
||||||
sigValue(!triggerValue);
|
performValueAction(!triggerValue);
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
sensor_ = sensor;
|
sensor_ = sensor;
|
||||||
|
|
@ -42,15 +42,14 @@ void Regulator::sensorEvent(Sensor sensor)
|
||||||
void Regulator::makeInactive()
|
void Regulator::makeInactive()
|
||||||
{
|
{
|
||||||
first = true;
|
first = true;
|
||||||
if(active)
|
performValueAction(!triggerValue);
|
||||||
sigValue(!triggerValue);
|
|
||||||
timer.stop();
|
timer.stop();
|
||||||
Actor::makeInactive();
|
Actor::makeInactive();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Regulator::timeout()
|
void Regulator::timeout()
|
||||||
{
|
{
|
||||||
sigValue(safeValue_);
|
performValueAction(safeValue_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Regulator::setPoint(float setPoint)
|
void Regulator::setPoint(float setPoint)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ PowerItem::PowerItem(uint32_t itemIdIn, QString name, uint8_t value, QObject* p
|
||||||
Item(itemIdIn, name, value, parent)
|
Item(itemIdIn, name, value, parent)
|
||||||
{
|
{
|
||||||
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0, "Shutdown Imminent", true));
|
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0, "Shutdown Imminent", true));
|
||||||
PowerItem::setValue(true);
|
value_ = true;
|
||||||
hidden_ = true;
|
hidden_ = true;
|
||||||
type_ = ITEM_VALUE_NO_VALUE;
|
type_ = ITEM_VALUE_NO_VALUE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,6 @@ void Relay::enactValue(uint8_t value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Relay::toggle()
|
|
||||||
{
|
|
||||||
value_ ? off() : on();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Relay::store(QJsonObject& json)
|
void Relay::store(QJsonObject& json)
|
||||||
{
|
{
|
||||||
json["Type"] = "Relay";
|
json["Type"] = "Relay";
|
||||||
|
|
|
||||||
11
src/main.cpp
11
src/main.cpp
|
|
@ -115,7 +115,12 @@ int main(int argc, char *argv[])
|
||||||
QObject::connect(&mainObject.micro, SIGNAL(textRecived(QString)), w, SLOT(changeHeaderLableText(QString)));
|
QObject::connect(&mainObject.micro, SIGNAL(textRecived(QString)), w, SLOT(changeHeaderLableText(QString)));
|
||||||
QObject::connect(w, &MainWindow::sigSetRgb, &mainObject.micro, &Microcontroller::changeRgbColor);
|
QObject::connect(w, &MainWindow::sigSetRgb, &mainObject.micro, &Microcontroller::changeRgbColor);
|
||||||
QObject::connect(w, &MainWindow::sigSave, &mainObject, [&mainObject, settingsPath](){mainObject.storeToDisk(settingsPath);});
|
QObject::connect(w, &MainWindow::sigSave, &mainObject, [&mainObject, settingsPath](){mainObject.storeToDisk(settingsPath);});
|
||||||
QObject::connect(w, &MainWindow::createdItem, &globalItems, [](std::shared_ptr<Item> item){globalItems.addItem(item, false);});
|
QObject::connect(w,
|
||||||
|
&MainWindow::createdItem,
|
||||||
|
&globalItems,
|
||||||
|
[](std::shared_ptr<Item> item) {
|
||||||
|
globalItems.addItem(item, ITEM_UPDATE_USER);
|
||||||
|
});
|
||||||
w->show();
|
w->show();
|
||||||
}
|
}
|
||||||
retVal = a.exec();
|
retVal = a.exec();
|
||||||
|
|
@ -127,7 +132,9 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
SecondaryMainObject mainObject(parser.value(hostOption), parser.value(portOption).toInt());
|
SecondaryMainObject mainObject(parser.value(hostOption), parser.value(portOption).toInt());
|
||||||
MainWindow w(&mainObject);
|
MainWindow w(&mainObject);
|
||||||
QObject::connect(&w, &MainWindow::createdItem, &globalItems, [](std::shared_ptr<Item> item){globalItems.addItem(item, false);});
|
QObject::connect(&w, &MainWindow::createdItem, &globalItems, [](std::shared_ptr<Item> item) {
|
||||||
|
globalItems.addItem(item, ITEM_UPDATE_USER);
|
||||||
|
});
|
||||||
QObject::connect(&w, &MainWindow::sigSave, mainObject.tcpClient, &TcpClient::sendItems);
|
QObject::connect(&w, &MainWindow::sigSave, mainObject.tcpClient, &TcpClient::sendItems);
|
||||||
w.show();
|
w.show();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ void Server::processIncomeingJson(const QByteArray& jsonbytes)
|
||||||
}
|
}
|
||||||
else if(!items.empty())
|
else if(!items.empty())
|
||||||
{
|
{
|
||||||
gotItems(items, false);
|
gotItems(items, ITEM_UPDATE_REMOTE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -91,3 +91,14 @@ void Server::removeClient(QWebSocket* socket)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Server::itemUpdated(ItemUpdateRequest update)
|
||||||
|
{
|
||||||
|
QJsonArray items;
|
||||||
|
QJsonObject itemjson;
|
||||||
|
update.payload.store(itemjson);
|
||||||
|
items.append(itemjson);
|
||||||
|
QJsonObject json = createMessage("ItemUpdate", items);
|
||||||
|
json["FullList"] = false;
|
||||||
|
sendJson(json);
|
||||||
|
}
|
||||||
|
|
@ -31,6 +31,9 @@ protected:
|
||||||
|
|
||||||
std::vector<Client> clients;
|
std::vector<Client> clients;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void itemUpdated(ItemUpdateRequest update) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Server(QObject* parent = nullptr);
|
Server(QObject* parent = nullptr);
|
||||||
virtual ~Server();
|
virtual ~Server();
|
||||||
|
|
|
||||||
|
|
@ -29,17 +29,7 @@ void Service::sensorEvent(Sensor sensor)
|
||||||
sendJson(json);
|
sendJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service::itemUpdated(std::weak_ptr<Item> item)
|
void Service::itemUpdated(ItemUpdateRequest update) {}
|
||||||
{
|
|
||||||
qDebug()<<"Service sending item"<<item.lock()->getName();
|
|
||||||
QJsonArray items;
|
|
||||||
QJsonObject itemjson;
|
|
||||||
item.lock()->store(itemjson);
|
|
||||||
items.append(itemjson);
|
|
||||||
QJsonObject json = createMessage("ItemUpdate", items);
|
|
||||||
json["FullList"] = false;
|
|
||||||
sendJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Service::refresh()
|
void Service::refresh()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void sensorEvent(Sensor sensor);
|
void sensorEvent(Sensor sensor);
|
||||||
void itemUpdated(std::weak_ptr<Item> item);
|
virtual void itemUpdated(ItemUpdateRequest update);
|
||||||
virtual void refresh() override;
|
virtual void refresh() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,20 @@ void TcpClient::socketReadyRead()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TcpClient::itemUpdated(ItemUpdateRequest update)
|
||||||
|
{
|
||||||
|
if(update.type == ITEM_UPDATE_USER)
|
||||||
|
{
|
||||||
|
QJsonArray items;
|
||||||
|
QJsonObject itemjson;
|
||||||
|
update.payload.store(itemjson);
|
||||||
|
items.append(itemjson);
|
||||||
|
QJsonObject json = createMessage("ItemUpdate", items);
|
||||||
|
json["FullList"] = false;
|
||||||
|
sendJson(json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TcpClient::~TcpClient()
|
TcpClient::~TcpClient()
|
||||||
{
|
{
|
||||||
delete socket;
|
delete socket;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@ class TcpClient : public Service
|
||||||
long long recievebytes = 0;
|
long long recievebytes = 0;
|
||||||
QByteArray buffer;
|
QByteArray buffer;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void itemUpdated(ItemUpdateRequest update) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TcpClient(QObject* parent = nullptr);
|
TcpClient(QObject* parent = nullptr);
|
||||||
~TcpClient();
|
~TcpClient();
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ ItemWidget::ItemWidget(std::weak_ptr<Item> item, QWidget *parent) :
|
||||||
else
|
else
|
||||||
connect(ui->checkBox, &QCheckBox::toggled, this, &ItemWidget::moveToState);
|
connect(ui->checkBox, &QCheckBox::toggled, this, &ItemWidget::moveToState);
|
||||||
connect(ui->pushButton, &QPushButton::clicked, this, &ItemWidget::showSettingsDialog);
|
connect(ui->pushButton, &QPushButton::clicked, this, &ItemWidget::showSettingsDialog);
|
||||||
connect(workingItem.get(), &Relay::valueChanged, this, &ItemWidget::stateChanged);
|
connect(workingItem.get(), &Item::updated, this, &ItemWidget::onItemUpdated);
|
||||||
connect(ui->pushButton_Remove, &QPushButton::clicked, this, &ItemWidget::deleteItem);
|
connect(ui->pushButton_Remove, &QPushButton::clicked, this, &ItemWidget::deleteItem);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -115,6 +115,11 @@ std::weak_ptr<Item> ItemWidget::getItem()
|
||||||
return item_;
|
return item_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ItemWidget::onItemUpdated(ItemUpdateRequest update)
|
||||||
|
{
|
||||||
|
stateChanged(update.payload.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
void ItemWidget::stateChanged(int state)
|
void ItemWidget::stateChanged(int state)
|
||||||
{
|
{
|
||||||
ui->slider->blockSignals(true);
|
ui->slider->blockSignals(true);
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void stateChanged(int state);
|
void stateChanged(int state);
|
||||||
|
void onItemUpdated(ItemUpdateRequest update);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ItemWidget *ui;
|
Ui::ItemWidget *ui;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue