Continue refactor
This commit is contained in:
parent
18cf2b01bd
commit
219fbfb4c7
14 changed files with 104 additions and 125 deletions
|
|
@ -21,7 +21,10 @@ void Actor::performAction()
|
||||||
{
|
{
|
||||||
if(active)
|
if(active)
|
||||||
{
|
{
|
||||||
sigValue(triggerValue);
|
ItemUpdateRequest request;
|
||||||
|
request.type = ITEM_UPDATE_ACTOR;
|
||||||
|
request.payload = ItemData(QRandomGenerator::global()->generate(), "Item", triggerValue);
|
||||||
|
sigItemUpdate(request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,9 +89,9 @@ uint8_t Actor::getTriggerValue()
|
||||||
return triggerValue;
|
return triggerValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actor::onValueChanged(uint8_t value)
|
void Actor::onItemUpdated(ItemUpdateRequest update)
|
||||||
{
|
{
|
||||||
(void)value;
|
(void) update;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Actor> Actor::createActor(const QString& type)
|
std::shared_ptr<Actor> Actor::createActor(const QString& type)
|
||||||
|
|
@ -112,9 +115,7 @@ std::shared_ptr<Actor> Actor::loadActor(const QJsonObject &json)
|
||||||
return actor;
|
return actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actor::setValue(uint8_t value)
|
void Actor::enactValue(uint8_t value)
|
||||||
{
|
{
|
||||||
Item::setValue(value);
|
|
||||||
setActive(value);
|
setActive(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,18 +19,17 @@ protected:
|
||||||
bool exausted = false;
|
bool exausted = false;
|
||||||
|
|
||||||
void performAction();
|
void performAction();
|
||||||
|
virtual void enactValue(uint8_t value) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void sigValue(uint8_t value);
|
void sigItemUpdate(ItemUpdateRequest update);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void makeActive();
|
virtual void makeActive();
|
||||||
virtual void makeInactive();
|
virtual void makeInactive();
|
||||||
virtual void setActive(uint8_t state);
|
virtual void setActive(uint8_t state);
|
||||||
virtual void onValueChanged(uint8_t state);
|
virtual void onItemUpdated(ItemUpdateRequest update);
|
||||||
|
|
||||||
virtual void setValue(uint8_t value);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Actor(QObject* parent = nullptr);
|
Actor(QObject* parent = nullptr);
|
||||||
|
|
@ -46,8 +45,8 @@ public:
|
||||||
|
|
||||||
static std::shared_ptr<Actor> createActor(const QString& type);
|
static std::shared_ptr<Actor> createActor(const QString& type);
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json) override;
|
||||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
virtual void load(const QJsonObject& json, const bool preserve = false) override;
|
||||||
static std::shared_ptr<Actor> loadActor(const QJsonObject& json);
|
static std::shared_ptr<Actor> loadActor(const QJsonObject& json);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,5 +10,5 @@ FixedItemSource::FixedItemSource(Microcontroller* micro, QObject *parent):
|
||||||
|
|
||||||
void FixedItemSource::refresh()
|
void FixedItemSource::refresh()
|
||||||
{
|
{
|
||||||
gotItems({powerItem, rgbItem, auxItem});
|
gotItems({powerItem, rgbItem, auxItem}, ITEM_UPDATE_BACKEND);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,11 @@ uint8_t ItemData::getValue() const
|
||||||
return value_;
|
return value_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ItemData::setValueData(uint8_t value)
|
||||||
|
{
|
||||||
|
value_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t ItemData::id() const
|
uint32_t ItemData::id() const
|
||||||
{
|
{
|
||||||
return itemId_;
|
return itemId_;
|
||||||
|
|
@ -156,42 +161,28 @@ Item& Item::operator=(const ItemData& other)
|
||||||
|
|
||||||
void Item::requestUpdate(ItemUpdateRequest update)
|
void Item::requestUpdate(ItemUpdateRequest update)
|
||||||
{
|
{
|
||||||
if(!hasChanged(update.data))
|
if(!hasChanged(update.payload))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(update.type == ITEM_UPDATE_USER || (update.type == ITEM_UPDATE_ACTOR && !override_) || update.type == ITEM_UPDATE_REMOTE)
|
if(update.type == ITEM_UPDATE_ACTOR && override_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(update.type != ITEM_UPDATE_LOADED
|
||||||
|
&& (programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY))
|
||||||
|
enactValue(update.payload.getValue());
|
||||||
|
|
||||||
|
*this = update.payload;
|
||||||
|
update.payload = *this;
|
||||||
|
|
||||||
|
if(update.type == ITEM_UPDATE_LOADED)
|
||||||
{
|
{
|
||||||
if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)
|
actors_.clear();
|
||||||
enactValue(update.data.getValue());
|
for(std::shared_ptr<Actor>& actor : update.newActors)
|
||||||
*this = update.data;
|
addActor(actor);
|
||||||
update.data = *this;
|
}
|
||||||
|
|
||||||
updated(update);
|
updated(update);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void Item::actorSetValue(uint8_t value)
|
|
||||||
{
|
|
||||||
if(!override_ && (programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY))
|
|
||||||
setValue(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Item::setValue(uint8_t value)
|
|
||||||
{
|
|
||||||
qDebug()<<__func__;
|
|
||||||
informValue(value);
|
|
||||||
updated(*this);
|
|
||||||
if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)
|
|
||||||
enactValue(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Item::informValue(uint8_t value)
|
|
||||||
{
|
|
||||||
if(value_ != value)
|
|
||||||
{
|
|
||||||
value_ = value;
|
|
||||||
valueChanged(value_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Item::enactValue(uint8_t value)
|
void Item::enactValue(uint8_t value)
|
||||||
{
|
{
|
||||||
|
|
@ -203,8 +194,8 @@ void Item::addActor(std::shared_ptr<Actor> actor)
|
||||||
actor->setParent(this);
|
actor->setParent(this);
|
||||||
actors_.push_back(actor);
|
actors_.push_back(actor);
|
||||||
if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)
|
if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)
|
||||||
connect(actor.get(), &Actor::sigValue, this, &Item::actorSetValue);
|
connect(actor.get(), &Actor::sigItemUpdate, this, &Item::requestUpdate);
|
||||||
connect(this, &Item::valueChanged, actor.get(), &Actor::onValueChanged);
|
connect(this, &Item::updated, actor.get(), &Actor::onItemUpdated);
|
||||||
|
|
||||||
std::shared_ptr<SensorActor> sensorActor = std::dynamic_pointer_cast<SensorActor>(actor);
|
std::shared_ptr<SensorActor> sensorActor = std::dynamic_pointer_cast<SensorActor>(actor);
|
||||||
if(sensorActor)
|
if(sensorActor)
|
||||||
|
|
@ -263,14 +254,6 @@ void Item::setActorsActive(bool in)
|
||||||
in ? actors_[i]->makeActive() : actors_[i]->makeInactive();
|
in ? actors_[i]->makeActive() : actors_[i]->makeInactive();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::mergeLoaded(Item& item)
|
|
||||||
{
|
|
||||||
name_ = item.name_;
|
|
||||||
actors_.clear();
|
|
||||||
for(std::shared_ptr<Actor> actor : item.actors_)
|
|
||||||
addActor(actor);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<Item> Item::loadItem(const QJsonObject& json)
|
std::shared_ptr<Item> Item::loadItem(const QJsonObject& json)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Item> newItem = nullptr;
|
std::shared_ptr<Item> newItem = nullptr;
|
||||||
|
|
@ -298,3 +281,14 @@ std::shared_ptr<Item> Item::loadItem(const QJsonObject& json)
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ItemUpdateRequest Item::createValueUpdateRequest(uint8_t value,
|
||||||
|
item_update_type_t type,
|
||||||
|
bool withActors)
|
||||||
|
{
|
||||||
|
ItemUpdateRequest update;
|
||||||
|
update.payload = *this;
|
||||||
|
update.payload.setValueData(value);
|
||||||
|
if(withActors)
|
||||||
|
update.newActors = actors_;
|
||||||
|
return update;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,9 @@ typedef enum {
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ITEM_UPDATE_USER = 0,
|
ITEM_UPDATE_USER = 0,
|
||||||
ITEM_UPDATE_ACTOR,
|
ITEM_UPDATE_ACTOR,
|
||||||
ITEM_UPDATE_REMOTE
|
ITEM_UPDATE_REMOTE,
|
||||||
|
ITEM_UPDATE_LOADED,
|
||||||
|
ITEM_UPDATE_BACKEND
|
||||||
} item_update_type_t;
|
} item_update_type_t;
|
||||||
|
|
||||||
class ItemData
|
class ItemData
|
||||||
|
|
@ -52,6 +54,7 @@ public:
|
||||||
bool hasChanged(const ItemData& other);
|
bool hasChanged(const ItemData& other);
|
||||||
void setName(QString name);
|
void setName(QString name);
|
||||||
uint8_t getValue() const;
|
uint8_t getValue() const;
|
||||||
|
void setValueData(uint8_t value);
|
||||||
bool getLoaded() const;
|
bool getLoaded() const;
|
||||||
void setLoaded(bool loaded);
|
void setLoaded(bool loaded);
|
||||||
bool isHidden() const;
|
bool isHidden() const;
|
||||||
|
|
@ -65,8 +68,8 @@ public:
|
||||||
struct ItemUpdateRequest
|
struct ItemUpdateRequest
|
||||||
{
|
{
|
||||||
item_update_type_t type;
|
item_update_type_t type;
|
||||||
ItemData data;
|
ItemData payload;
|
||||||
bool valueOnly;
|
std::vector<std::shared_ptr<Actor> > newActors;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -81,7 +84,7 @@ signals:
|
||||||
void updated(ItemUpdateRequest update);
|
void updated(ItemUpdateRequest update);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void requestUpdate(ItemUpdateRequest update);
|
virtual void requestUpdate(ItemUpdateRequest update);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -100,7 +103,9 @@ public:
|
||||||
void setActorsActive(bool in);
|
void setActorsActive(bool in);
|
||||||
void setOverride(const bool in);
|
void setOverride(const bool in);
|
||||||
bool getOverride();
|
bool getOverride();
|
||||||
void mergeLoaded(Item& item);
|
ItemUpdateRequest createValueUpdateRequest(uint8_t value,
|
||||||
|
item_update_type_t type,
|
||||||
|
bool withActors = false);
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json);
|
||||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ void ItemLoaderSource::refresh()
|
||||||
qDebug()<<"Loaded item"<<newItem->getName();
|
qDebug()<<"Loaded item"<<newItem->getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gotItems(items);
|
gotItems(items, ITEM_UPDATE_LOADED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemLoaderSource::updateJson(const QJsonObject& json)
|
void ItemLoaderSource::updateJson(const QJsonObject& json)
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ public slots:
|
||||||
virtual void refresh() = 0;
|
virtual void refresh() = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void gotItems(std::vector<std::shared_ptr<Item>> items, bool inform = true);
|
void gotItems(std::vector<std::shared_ptr<Item>> items, item_update_type_t updateType);
|
||||||
void requestReplaceItems(std::vector<std::shared_ptr<Item>> items);
|
void requestReplaceItems(std::vector<std::shared_ptr<Item>> items);
|
||||||
void updateItems(std::vector<ItemData> items, bool inform = true);
|
void updateItems(std::vector<ItemUpdateRequest> updates);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ITEMSOURCE_H
|
#endif // ITEMSOURCE_H
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ ItemStore::ItemStore(QObject *parent): QObject(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemStore::addItem(std::shared_ptr<Item> item, bool inform)
|
void ItemStore::addItem(const std::shared_ptr<Item>& item, item_update_type_t updateType)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Item> matched = nullptr;
|
std::shared_ptr<Item> matched = nullptr;
|
||||||
for(unsigned i = 0; i < items_.size(); i++ )
|
for(unsigned i = 0; i < items_.size(); i++ )
|
||||||
|
|
@ -26,17 +26,18 @@ void ItemStore::addItem(std::shared_ptr<Item> item, bool inform)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(item->getLoaded())
|
ItemUpdateRequest request = item->createValueUpdateRequest(item->getValue(),
|
||||||
matched->mergeLoaded(*item);
|
updateType,
|
||||||
else if(item->getValue() != matched->getValue())
|
updateType == ITEM_UPDATE_LOADED);
|
||||||
updateItem(*item, inform);
|
updateItem(request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemStore::addItems(const std::vector<std::shared_ptr<Item>>& itemIn, bool inform)
|
void ItemStore::addItems(const std::vector<std::shared_ptr<Item>>& itemIn,
|
||||||
|
item_update_type_t updateType)
|
||||||
{
|
{
|
||||||
for(unsigned j = 0; j < itemIn.size(); j++)
|
for(unsigned j = 0; j < itemIn.size(); j++)
|
||||||
addItem(itemIn[j], inform);
|
addItem(itemIn[j], updateType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemStore::removeItem(const ItemData& item)
|
void ItemStore::removeItem(const ItemData& item)
|
||||||
|
|
@ -55,7 +56,7 @@ void ItemStore::removeItem(const ItemData& item)
|
||||||
|
|
||||||
void ItemStore::replaceItems(const std::vector<std::shared_ptr<Item>>& items)
|
void ItemStore::replaceItems(const std::vector<std::shared_ptr<Item>>& items)
|
||||||
{
|
{
|
||||||
addItems(items, true);
|
addItems(items, ITEM_UPDATE_LOADED);
|
||||||
std::vector<ItemData> deletedItems;
|
std::vector<ItemData> deletedItems;
|
||||||
for(std::shared_ptr<Item> item : items_)
|
for(std::shared_ptr<Item> item : items_)
|
||||||
{
|
{
|
||||||
|
|
@ -72,33 +73,21 @@ void ItemStore::clear()
|
||||||
items_.clear();
|
items_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ItemStore::updateItems(const std::vector<ItemUpdateRequest>& updates)
|
||||||
void ItemStore::updateItems(std::vector<ItemData> items, bool inform)
|
|
||||||
{
|
{
|
||||||
for(const ItemData& item : items)
|
for(const ItemUpdateRequest& update : updates)
|
||||||
updateItem(item, inform);
|
updateItem(update);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemStore::updateItem(const ItemData& item, bool inform)
|
void ItemStore::updateItem(const ItemUpdateRequest& update)
|
||||||
{
|
{
|
||||||
for(unsigned i = 0; i < items_.size(); i++ )
|
for(unsigned i = 0; i < items_.size(); i++ )
|
||||||
{
|
{
|
||||||
if(items_[i]->operator==(item))
|
if(items_[i]->operator==(update.payload))
|
||||||
{
|
{
|
||||||
if(items_[i]->hasChanged(item))
|
items_[i]->requestUpdate(update);
|
||||||
{
|
qDebug() << "Item" << items_[i]->getName() << "updated";
|
||||||
if(items_[i]->getValue() != item.getValue())
|
itemUpdated(update);
|
||||||
{
|
|
||||||
items_[i]->setLoaded(false);
|
|
||||||
if(inform)
|
|
||||||
items_[i]->informValue(item.getValue());
|
|
||||||
else
|
|
||||||
items_[i]->setValue(item.getValue());
|
|
||||||
}
|
|
||||||
qDebug()<<"Item"<<items_[i]->getName()<<"updated"<<(inform ? "with inform" : "");
|
|
||||||
if(!inform)
|
|
||||||
itemUpdated(items_[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -115,16 +104,10 @@ void ItemStore::store(QJsonObject& json)
|
||||||
json["Items"] = itemsArray;
|
json["Items"] = itemsArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemStore::itemUpdateSlot(ItemData data)
|
void ItemStore::itemUpdateSlot(ItemUpdateRequest update)
|
||||||
{
|
{
|
||||||
for(std::shared_ptr<Item>& item: items_)
|
qDebug() << "Item" << update.payload.getName() << "updated from update slot";
|
||||||
{
|
itemUpdated(update);
|
||||||
if(*item == data)
|
|
||||||
{
|
|
||||||
qDebug()<<"Item"<<data.getName()<<"updated from update slot";
|
|
||||||
itemUpdated(std::weak_ptr<Item>(item));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Item> ItemStore::getItem(uint32_t id)
|
std::shared_ptr<Item> ItemStore::getItem(uint32_t id)
|
||||||
|
|
|
||||||
|
|
@ -33,21 +33,21 @@ signals:
|
||||||
|
|
||||||
void itemDeleted(ItemData item);
|
void itemDeleted(ItemData item);
|
||||||
void itemAdded(std::weak_ptr<Item> Item);
|
void itemAdded(std::weak_ptr<Item> Item);
|
||||||
void itemUpdated(std::weak_ptr<Item> Item);
|
void itemUpdated(ItemUpdateRequest update);
|
||||||
void sigRefresh();
|
void sigRefresh();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void removeItem(const ItemData& item);
|
void removeItem(const ItemData& item);
|
||||||
void addItem(std::shared_ptr<Item> item, bool inform = true);
|
void addItem(const std::shared_ptr<Item>& item, item_update_type_t updateType);
|
||||||
void addItems(const std::vector<std::shared_ptr<Item>>& itemsIn, bool inform = true);
|
void addItems(const std::vector<std::shared_ptr<Item>>& itemsIn, item_update_type_t updateType);
|
||||||
void replaceItems(const std::vector<std::shared_ptr<Item>>& items);
|
void replaceItems(const std::vector<std::shared_ptr<Item>>& items);
|
||||||
void updateItems(std::vector<ItemData> items, bool inform = true);
|
void updateItems(const std::vector<ItemUpdateRequest>& updates);
|
||||||
void updateItem(const ItemData& item, bool inform = true);
|
void updateItem(const ItemUpdateRequest& update);
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void itemUpdateSlot(ItemData data);
|
void itemUpdateSlot(ItemUpdateRequest update);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ItemStore globalItems;
|
extern ItemStore globalItems;
|
||||||
|
|
|
||||||
|
|
@ -23,16 +23,6 @@ void Relay::enactValue(uint8_t value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Relay::on()
|
|
||||||
{
|
|
||||||
setValue(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Relay::off()
|
|
||||||
{
|
|
||||||
setValue(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Relay::toggle()
|
void Relay::toggle()
|
||||||
{
|
{
|
||||||
value_ ? off() : on();
|
value_ ? off() : on();
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
#include<stdint.h>
|
#include<stdint.h>
|
||||||
#include<QObject>
|
#include<QObject>
|
||||||
|
|
||||||
#include "sensors/sensor.h"
|
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
|
||||||
class Microcontroller;
|
class Microcontroller;
|
||||||
|
|
@ -21,11 +20,6 @@ private:
|
||||||
protected:
|
protected:
|
||||||
virtual void enactValue(uint8_t value) override;
|
virtual void enactValue(uint8_t value) override;
|
||||||
|
|
||||||
public slots:
|
|
||||||
void on();
|
|
||||||
void off();
|
|
||||||
void toggle();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Relay(uint8_t id = 0, QString name = "", uint16_t address = 0, bool state = false, QObject* parent = nullptr);
|
Relay(uint8_t id = 0, QString name = "", uint16_t address = 0, bool state = false, QObject* parent = nullptr);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ void Microcontroller::processList(const QString& buffer)
|
||||||
else if(buffer.contains("EOL"))
|
else if(buffer.contains("EOL"))
|
||||||
{
|
{
|
||||||
listMode = false;
|
listMode = false;
|
||||||
gotItems(relayList);
|
gotItems(relayList, ITEM_UPDATE_BACKEND);
|
||||||
relayList.clear();
|
relayList.clear();
|
||||||
}
|
}
|
||||||
else listMode = false;
|
else listMode = false;
|
||||||
|
|
@ -150,7 +150,10 @@ void Microcontroller::processList(const QString& buffer)
|
||||||
|
|
||||||
void Microcontroller::processRelayState(const QString& buffer)
|
void Microcontroller::processRelayState(const QString& buffer)
|
||||||
{
|
{
|
||||||
updateItems({static_cast<ItemData>(*processRelayLine(buffer))});
|
ItemUpdateRequest update;
|
||||||
|
update.type = ITEM_UPDATE_BACKEND;
|
||||||
|
update.payload = static_cast<ItemData>(*processRelayLine(buffer));
|
||||||
|
updateItems({update});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::processSensorState(const QString& buffer)
|
void Microcontroller::processSensorState(const QString& buffer)
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ void TcpClient::processIncomeingJson(const QByteArray& jsonbytes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!items.empty())
|
if(!items.empty())
|
||||||
gotItems(items, true);
|
gotItems(items, ITEM_UPDATE_REMOTE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -59,18 +59,28 @@ void ItemWidget::deleteItem()
|
||||||
void ItemWidget::moveToValue(int value)
|
void ItemWidget::moveToValue(int value)
|
||||||
{
|
{
|
||||||
if(auto workingItem = item_.lock())
|
if(auto workingItem = item_.lock())
|
||||||
workingItem->setValue(value);
|
{
|
||||||
|
ItemUpdateRequest request = workingItem->createValueUpdateRequest(value, ITEM_UPDATE_USER);
|
||||||
|
workingItem->requestUpdate(request);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
disable();
|
disable();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ItemWidget::moveToState(bool state)
|
void ItemWidget::moveToState(bool state)
|
||||||
{
|
{
|
||||||
if(auto workingItem = item_.lock())
|
if(auto workingItem = item_.lock())
|
||||||
workingItem->setValue(state);
|
{
|
||||||
|
ItemUpdateRequest request = workingItem->createValueUpdateRequest(state, ITEM_UPDATE_USER);
|
||||||
|
workingItem->requestUpdate(request);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
disable();
|
disable();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ItemWidget::disable()
|
void ItemWidget::disable()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue