Major wip refactor
Allow running without gui Remove serialPortMultiplexer broadcast use Add TcpServer and TcpClient Introduce the concept of an item source
This commit is contained in:
parent
cbeb8d49a7
commit
6d742e60db
38 changed files with 928 additions and 825 deletions
|
|
@ -6,9 +6,8 @@ AuxItem::AuxItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8
|
|||
|
||||
}
|
||||
|
||||
void AuxItem::setValue(uint8_t value)
|
||||
void AuxItem::enactValue(uint8_t value)
|
||||
{
|
||||
Item::setValue(value);
|
||||
micro_->setAuxPwm(value);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,13 +9,12 @@ class AuxItem: public Item
|
|||
private:
|
||||
Microcontroller* micro_;
|
||||
|
||||
public slots:
|
||||
|
||||
virtual void setValue(uint8_t value);
|
||||
protected:
|
||||
virtual void enactValue(uint8_t value) override;
|
||||
|
||||
public:
|
||||
AuxItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "",
|
||||
uint8_t value = 0, QObject* parent = nullptr);
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void store(QJsonObject& json) override;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
#include "item.h"
|
||||
|
||||
#include "src/actors/sensoractor.h"
|
||||
#include "src/actors/regulator.h"
|
||||
#include "src/actors/polynomalactor.h"
|
||||
#include "src/programmode.h"
|
||||
#include "relay.h"
|
||||
#include "../microcontroller.h"
|
||||
#include "../actors/sensoractor.h"
|
||||
#include "../actors/regulator.h"
|
||||
#include "../actors/polynomalactor.h"
|
||||
#include "messageitem.h"
|
||||
#include "systemitem.h"
|
||||
|
||||
#include <QJsonArray>
|
||||
|
||||
|
|
@ -33,11 +35,25 @@ uint32_t ItemData::id() const
|
|||
return itemId_;
|
||||
}
|
||||
|
||||
void ItemData::store(QJsonObject &json)
|
||||
{
|
||||
json["Name"] = name_;
|
||||
json["ItemId"] = static_cast<double>(itemId_);
|
||||
json["Value"] = static_cast<double>(value_);
|
||||
}
|
||||
|
||||
void ItemData::load(const QJsonObject &json, const bool preserve)
|
||||
{
|
||||
if(!preserve)
|
||||
{
|
||||
name_ = json["Name"].toString(name_);
|
||||
itemId_ = static_cast<uint32_t>(json["ItemId"].toDouble(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//item
|
||||
|
||||
bool Item::secondaryFlag = false;
|
||||
|
||||
Item::Item(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent): QObject(parent), ItemData (itemIdIn, name,
|
||||
value)
|
||||
{
|
||||
|
|
@ -55,8 +71,7 @@ Item::~Item()
|
|||
|
||||
void Item::store(QJsonObject &json)
|
||||
{
|
||||
json["Name"] = name_;
|
||||
json["ItemId"] = static_cast<double>(itemId_);
|
||||
ItemData::store(json);
|
||||
json["override"] = override_;
|
||||
QJsonArray actorsArray;
|
||||
for(size_t i = 0; i < actors_.size(); ++i)
|
||||
|
|
@ -73,11 +88,7 @@ void Item::store(QJsonObject &json)
|
|||
|
||||
void Item::load(const QJsonObject &json, const bool preserve)
|
||||
{
|
||||
if(!preserve)
|
||||
{
|
||||
name_ = json["Name"].toString(name_);
|
||||
itemId_ = static_cast<uint32_t>(json["ItemId"].toDouble(0));
|
||||
}
|
||||
ItemData::load(json, preserve);
|
||||
override_ = json["override"].toBool(false);
|
||||
const QJsonArray actorsArray(json["Actors"].toArray(QJsonArray()));
|
||||
for(int i = 0; i < actorsArray.size(); ++i)
|
||||
|
|
@ -92,28 +103,35 @@ void Item::load(const QJsonObject &json, const bool preserve)
|
|||
|
||||
void Item::actorSetValue(uint8_t value)
|
||||
{
|
||||
if(!override_) setValue(value);
|
||||
if(!override_ && (programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY))
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
void Item::setValue(uint8_t value)
|
||||
{
|
||||
value_ = value;
|
||||
valueChanged(value_);
|
||||
informValue(value);
|
||||
if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)
|
||||
enactValue(value);
|
||||
}
|
||||
|
||||
void Item::informValue(uint8_t value)
|
||||
{
|
||||
Item::setValue(value);
|
||||
value_ = value;
|
||||
valueChanged(value_);
|
||||
updated(*this);
|
||||
}
|
||||
|
||||
void Item::enactValue(uint8_t value)
|
||||
{
|
||||
(void)value;
|
||||
}
|
||||
|
||||
void Item::addActor(std::shared_ptr<Actor> actor)
|
||||
{
|
||||
actor->setParent(this);
|
||||
actors_.push_back(actor);
|
||||
if(!secondaryFlag)
|
||||
{
|
||||
if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)
|
||||
connect(actor.get(), &Actor::sigValue, this, &Item::actorSetValue);
|
||||
}
|
||||
connect(this, &Item::valueChanged, actor.get(), &Actor::onValueChanged);
|
||||
|
||||
std::shared_ptr<SensorActor> sensorActor = std::dynamic_pointer_cast<SensorActor>(actor);
|
||||
|
|
@ -167,5 +185,29 @@ bool Item::hasActors()
|
|||
|
||||
void Item::setActorsActive(bool in)
|
||||
{
|
||||
for(unsigned i = 0; i < actors_.size(); i++) in ? actors_[i]->makeActive() : actors_[i]->makeInactive();
|
||||
for(unsigned i = 0; i < actors_.size(); i++)
|
||||
in ? actors_[i]->makeActive() : actors_[i]->makeInactive();
|
||||
}
|
||||
|
||||
std::shared_ptr<Item> Item::loadItem(const QJsonObject& json)
|
||||
{
|
||||
std::shared_ptr<Item> newItem = nullptr;
|
||||
if(json["Type"].toString("") == "Relay")
|
||||
{
|
||||
newItem = std::shared_ptr<Relay>(new Relay);
|
||||
}
|
||||
else if(json["Type"].toString("") == "Message")
|
||||
{
|
||||
newItem = std::shared_ptr<MessageItem>(new MessageItem);
|
||||
}
|
||||
else if(json["Type"].toString("") == "System")
|
||||
{
|
||||
newItem = std::shared_ptr<SystemItem>(new SystemItem);
|
||||
}
|
||||
else if(json["Type"].toString("") == "Aux")
|
||||
{
|
||||
}
|
||||
if(newItem)
|
||||
newItem->load(json);
|
||||
return newItem;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,16 +16,15 @@ protected:
|
|||
uint32_t itemId_;
|
||||
|
||||
public:
|
||||
|
||||
ItemData(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0);
|
||||
|
||||
inline bool operator==(const ItemData& in) const
|
||||
{
|
||||
return itemId_==in.itemId_;
|
||||
return itemId_ == in.itemId_;
|
||||
}
|
||||
inline bool operator!=(const ItemData& in) const
|
||||
{
|
||||
return itemId_!=in.itemId_;
|
||||
return itemId_ != in.itemId_;
|
||||
}
|
||||
|
||||
uint32_t id() const;
|
||||
|
|
@ -33,6 +32,8 @@ public:
|
|||
void setName(QString name);
|
||||
uint8_t getValue() const;
|
||||
virtual QString getName() const;
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -44,20 +45,15 @@ private:
|
|||
|
||||
bool override_ = false;
|
||||
|
||||
public:
|
||||
|
||||
static bool secondaryFlag;
|
||||
|
||||
signals:
|
||||
|
||||
void valueChanged(uint8_t value);
|
||||
void updated(ItemData data);
|
||||
|
||||
private slots:
|
||||
virtual void actorSetValue(uint8_t value);
|
||||
|
||||
public slots:
|
||||
|
||||
virtual void setValue(uint8_t value);
|
||||
void setValue(uint8_t value);
|
||||
|
||||
public:
|
||||
|
||||
|
|
@ -80,5 +76,10 @@ public:
|
|||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||
|
||||
static std::shared_ptr<Item> loadItem(const QJsonObject& json);
|
||||
|
||||
protected:
|
||||
virtual void enactValue(uint8_t value);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
5
src/items/itemsource.cpp
Normal file
5
src/items/itemsource.cpp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#include "itemsource.h"
|
||||
|
||||
ItemSource::ItemSource(QObject *parent)
|
||||
: QObject{parent}
|
||||
{}
|
||||
24
src/items/itemsource.h
Normal file
24
src/items/itemsource.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef ITEMSOURCE_H
|
||||
#define ITEMSOURCE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "item.h"
|
||||
|
||||
class ItemSource : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ItemSource(QObject *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
virtual void refresh() = 0;
|
||||
|
||||
signals:
|
||||
void gotItems(std::vector<std::shared_ptr<Item>> items, bool inform = true);
|
||||
void updateItems(std::vector<ItemData> items, bool inform = true);
|
||||
};
|
||||
|
||||
#endif // ITEMSOURCE_H
|
||||
|
|
@ -1,52 +1,42 @@
|
|||
#include "itemstore.h"
|
||||
#include "relay.h"
|
||||
#include "messageitem.h"
|
||||
#include "systemitem.h"
|
||||
#include <QJsonArray>
|
||||
#include <typeinfo>
|
||||
|
||||
ItemStore::ItemStore(QObject *parent): QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void ItemStore::addItem(std::shared_ptr<Item> item)
|
||||
void ItemStore::addItem(std::shared_ptr<Item> item, bool inform)
|
||||
{
|
||||
bool mached = false;
|
||||
for(unsigned i = 0; i < items_.size(); i++ ) if(*items_[i] == *item) mached = true;
|
||||
if(!mached)
|
||||
std::shared_ptr<Item> matched = nullptr;
|
||||
for(unsigned i = 0; i < items_.size(); i++ )
|
||||
{
|
||||
if(*items_[i] == *item)
|
||||
{
|
||||
matched = items_[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!matched)
|
||||
{
|
||||
items_.push_back(std::shared_ptr<Item>(item));
|
||||
connect(item.get(), &Item::updated, this, &ItemStore::itemUpdateSlot);
|
||||
qDebug()<<"Item"<<item->getName()<<"added";
|
||||
itemAdded(std::weak_ptr<Item>(items_.back()));
|
||||
}
|
||||
else if(item->getValue() != matched->getValue())
|
||||
{
|
||||
if(inform)
|
||||
matched->informValue(item->getValue());
|
||||
else
|
||||
matched->setValue(item->getValue());
|
||||
}
|
||||
}
|
||||
|
||||
void ItemStore::addItems(const std::vector<std::shared_ptr<Item>>& itemIn)
|
||||
void ItemStore::addItems(const std::vector<std::shared_ptr<Item>>& itemIn, bool inform)
|
||||
{
|
||||
for(unsigned i = 0; i < items_.size(); i++ )
|
||||
{
|
||||
if(Relay* relay = dynamic_cast<Relay*>(items_[i].get()))
|
||||
{
|
||||
bool mached = false;
|
||||
for(unsigned j = 0; j < itemIn.size(); j++) if(*(items_[i]) == *(itemIn[j]))
|
||||
{
|
||||
mached = true;
|
||||
if(itemIn[j]->getValue() != items_[i]->getValue()) items_[i]->informValue(itemIn[j]->getValue());
|
||||
Relay* relayIn = dynamic_cast<Relay*>(itemIn[j].get());
|
||||
if(relayIn)
|
||||
{
|
||||
if(relay->getId() != relayIn->getId()) relay->setId(relayIn->getId());
|
||||
}
|
||||
|
||||
}
|
||||
if(!mached)
|
||||
{
|
||||
itemDeleted(*items_[i].get());
|
||||
items_.erase(items_.begin()+i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(unsigned j = 0; j < itemIn.size(); j++)addItem(itemIn[j]);
|
||||
|
||||
for(unsigned j = 0; j < itemIn.size(); j++)
|
||||
addItem(itemIn[j], inform);
|
||||
}
|
||||
|
||||
void ItemStore::removeItem(const ItemData& item)
|
||||
|
|
@ -55,13 +45,14 @@ void ItemStore::removeItem(const ItemData& item)
|
|||
{
|
||||
if(item == *items_[j])
|
||||
{
|
||||
qDebug()<<"Item"<<item.getName()<<"deleted";
|
||||
itemDeleted(*items_[j]);
|
||||
items_.erase(items_.begin()+j);
|
||||
--j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ItemStore::clear()
|
||||
{
|
||||
for(size_t i = 0; i < items_.size(); ++i) itemDeleted(*items_[i]);
|
||||
|
|
@ -69,19 +60,30 @@ void ItemStore::clear()
|
|||
}
|
||||
|
||||
|
||||
void ItemStore::itemStateChanged(const ItemData& item)
|
||||
void ItemStore::updateItems(std::vector<ItemData> items, bool inform)
|
||||
{
|
||||
for(const ItemData& item : items)
|
||||
updateItem(item, inform);
|
||||
}
|
||||
|
||||
|
||||
void ItemStore::updateItem(const ItemData& item, bool inform)
|
||||
{
|
||||
for(unsigned i = 0; i < items_.size(); i++ )
|
||||
{
|
||||
if(items_[i]->operator==(item))
|
||||
{
|
||||
|
||||
if(items_[i]->getValue() != item.getValue())items_[i]->informValue(item.getValue());
|
||||
if(items_[i]->getValue() != item.getValue())
|
||||
{
|
||||
if(inform)
|
||||
items_[i]->informValue(item.getValue());
|
||||
else
|
||||
items_[i]->setValue(item.getValue());
|
||||
}
|
||||
qDebug()<<"Item"<<items_[i]->getName()<<"updated";
|
||||
itemUpdated(items_[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ItemStore::store(QJsonObject& json)
|
||||
|
|
@ -101,30 +103,51 @@ void ItemStore::load(const QJsonObject& json)
|
|||
const QJsonArray itemsArray(json["Items"].toArray(QJsonArray()));
|
||||
for(int i = 0; i < itemsArray.size(); ++i)
|
||||
{
|
||||
if(itemsArray[i].isObject())
|
||||
{
|
||||
const QJsonObject itemObject = itemsArray[i].toObject();
|
||||
std::shared_ptr<Item> newItem;
|
||||
if(itemObject["Type"].toString("") == "Relay")
|
||||
{
|
||||
newItem = std::shared_ptr<Relay>(new Relay());
|
||||
}
|
||||
else if(itemObject["Type"].toString("") == "Message")
|
||||
{
|
||||
newItem = std::shared_ptr<MessageItem>(new MessageItem);
|
||||
}
|
||||
else if(itemObject["Type"].toString("") == "System")
|
||||
{
|
||||
newItem = std::shared_ptr<SystemItem>(new SystemItem());
|
||||
}
|
||||
else if(itemObject["Type"].toString("") == "Aux")
|
||||
{
|
||||
}
|
||||
if(newItem)
|
||||
{
|
||||
newItem->load(itemObject);
|
||||
addItem(newItem);
|
||||
}
|
||||
}
|
||||
if(!itemsArray[i].isObject())
|
||||
continue;
|
||||
|
||||
const QJsonObject itemObject = itemsArray[i].toObject();
|
||||
std::shared_ptr<Item> newItem = Item::loadItem(itemObject);
|
||||
if(newItem)
|
||||
addItem(newItem);
|
||||
}
|
||||
}
|
||||
|
||||
void ItemStore::itemUpdateSlot(ItemData data)
|
||||
{
|
||||
qDebug()<<__func__;
|
||||
for(std::shared_ptr<Item>& item: items_)
|
||||
{
|
||||
if(*item == data)
|
||||
itemUpdated(std::weak_ptr<Item>(item));
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Item> ItemStore::getItem(uint32_t id)
|
||||
{
|
||||
for(std::shared_ptr<Item>& item : items_)
|
||||
{
|
||||
if(item->id() == id)
|
||||
return item;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ItemStore::registerItemSource(ItemSource* source)
|
||||
{
|
||||
qDebug()<<__func__<<typeid(*source).name();
|
||||
connect(source, &ItemSource::gotItems, this, &ItemStore::addItems);
|
||||
connect(source, &ItemSource::updateItems, this, &ItemStore::updateItems);
|
||||
connect(this, &ItemStore::sigRefresh, source, &ItemSource::refresh);
|
||||
}
|
||||
|
||||
void ItemStore::refresh()
|
||||
{
|
||||
for(std::shared_ptr<Item>& item : items_)
|
||||
itemDeleted(*item);
|
||||
items_.clear();
|
||||
sigRefresh();
|
||||
}
|
||||
|
||||
ItemStore globalItems;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include <vector>
|
||||
#include <memory>
|
||||
#include "item.h"
|
||||
#include "src/sensors/sensor.h"
|
||||
#include "itemsource.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ class ItemStore: public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
std::vector< std::shared_ptr<Item> > items_;
|
||||
std::vector<std::shared_ptr<Item> > items_;
|
||||
|
||||
public:
|
||||
|
||||
|
|
@ -22,6 +22,9 @@ public:
|
|||
return &items_;
|
||||
}
|
||||
|
||||
std::shared_ptr<Item> getItem(uint32_t id);
|
||||
|
||||
void registerItemSource(ItemSource* source);
|
||||
void store(QJsonObject &json);
|
||||
void load(const QJsonObject &json);
|
||||
|
||||
|
|
@ -31,11 +34,20 @@ signals:
|
|||
|
||||
void itemDeleted(ItemData item);
|
||||
void itemAdded(std::weak_ptr<Item> Item);
|
||||
void itemUpdated(std::weak_ptr<Item> Item);
|
||||
void sigRefresh();
|
||||
|
||||
public slots:
|
||||
|
||||
void removeItem(const ItemData& item);
|
||||
void addItem(std::shared_ptr<Item> item);
|
||||
void addItems(const std::vector<std::shared_ptr<Item>>& itemsIn);
|
||||
void itemStateChanged(const ItemData& item);
|
||||
void addItem(std::shared_ptr<Item> item, bool inform = true);
|
||||
void addItems(const std::vector<std::shared_ptr<Item>>& itemsIn, bool inform = true);
|
||||
void updateItems(std::vector<ItemData> items, bool inform = true);
|
||||
void updateItem(const ItemData& item, bool inform = true);
|
||||
void refresh();
|
||||
|
||||
private slots:
|
||||
void itemUpdateSlot(ItemData data);
|
||||
};
|
||||
|
||||
extern ItemStore globalItems;
|
||||
|
|
|
|||
|
|
@ -20,9 +20,8 @@ MessageItem::~MessageItem()
|
|||
closeMessageBox();
|
||||
}
|
||||
|
||||
void MessageItem::setValue(uint8_t value)
|
||||
void MessageItem::enactValue(uint8_t value)
|
||||
{
|
||||
Item::setValue(value);
|
||||
if(value && !messageBox_)
|
||||
{
|
||||
if(!alertSoundFileName.isEmpty())
|
||||
|
|
|
|||
|
|
@ -17,12 +17,10 @@ private:
|
|||
QSoundEffect alertSound;
|
||||
|
||||
private slots:
|
||||
|
||||
void closeMessageBox();
|
||||
|
||||
public:
|
||||
|
||||
virtual void setValue(uint8_t value);
|
||||
protected:
|
||||
virtual void enactValue(uint8_t value) override;
|
||||
|
||||
public:
|
||||
|
||||
|
|
@ -36,8 +34,8 @@ public:
|
|||
void setAlert(const QString& in);
|
||||
QString getAlert();
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||
virtual void store(QJsonObject& json) override;
|
||||
virtual void load(const QJsonObject& json, const bool preserve = false) override;
|
||||
};
|
||||
|
||||
#endif // MESSAGEITEM_H
|
||||
|
|
|
|||
|
|
@ -7,15 +7,14 @@ PowerItem::PowerItem(uint32_t itemIdIn, QString name, uint8_t value, QObject* p
|
|||
parent)
|
||||
{
|
||||
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0, "Shutdown Imminent", true));
|
||||
setValue(true);
|
||||
PowerItem::setValue(true);
|
||||
}
|
||||
|
||||
void PowerItem::setValue(uint8_t value)
|
||||
void PowerItem::enactValue(uint8_t value)
|
||||
{
|
||||
qDebug()<<"shutdown";
|
||||
Item::setValue(value);
|
||||
if(!value)
|
||||
{
|
||||
qDebug()<<"shutdown";
|
||||
QTimer::singleShot(5000, this, &PowerItem::timeout);
|
||||
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 1, "Shutdown Imminent", true));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,10 @@ signals:
|
|||
void stateChanged(Sensor sensor);
|
||||
|
||||
private slots:
|
||||
|
||||
void timeout();
|
||||
|
||||
public slots:
|
||||
|
||||
virtual void setValue(uint8_t value);
|
||||
protected:
|
||||
virtual void enactValue(uint8_t value) override;
|
||||
|
||||
public:
|
||||
PowerItem(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0,
|
||||
|
|
@ -30,5 +28,5 @@ public:
|
|||
{
|
||||
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0, "Shutdown Imminent", true));
|
||||
}
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void store(QJsonObject& json) override;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,13 +12,14 @@ Relay::Relay(uint8_t id, QString name, uint16_t address, bool state, QObject* pa
|
|||
qDebug()<<"Relay "<<id_<<"Name "<<name<<" id "<<itemId_<<" state "<<state<<" addr: "<<address;
|
||||
}
|
||||
|
||||
void Relay::setValue(uint8_t value)
|
||||
void Relay::enactValue(uint8_t value)
|
||||
{
|
||||
Item::setValue(value);
|
||||
if(micro_)
|
||||
{
|
||||
if(value)micro_->relayOn(id_);
|
||||
else micro_->relayOff(id_);
|
||||
if(value)
|
||||
micro_->relayOn(id_);
|
||||
else
|
||||
micro_->relayOff(id_);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,10 @@ private:
|
|||
uint8_t id_;
|
||||
uint16_t address_;
|
||||
|
||||
public slots:
|
||||
protected:
|
||||
virtual void enactValue(uint8_t value) override;
|
||||
|
||||
virtual void setValue(uint8_t value);
|
||||
public slots:
|
||||
void on();
|
||||
void off();
|
||||
void toggle();
|
||||
|
|
@ -37,7 +38,7 @@ public:
|
|||
micro_ = micro;
|
||||
}
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||
virtual void store(QJsonObject& json) override;
|
||||
virtual void load(const QJsonObject& json, const bool preserve = false) override;
|
||||
};
|
||||
#endif // RELAY_H
|
||||
|
|
|
|||
|
|
@ -6,9 +6,8 @@ RgbItem::RgbItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8
|
|||
|
||||
}
|
||||
|
||||
void RgbItem::setValue(uint8_t value)
|
||||
void RgbItem::enactValue(uint8_t value)
|
||||
{
|
||||
Item::setValue(value);
|
||||
value ? micro_->rgbOn() : micro_->rgbOff();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,13 +9,12 @@ class RgbItem: public Item
|
|||
private:
|
||||
Microcontroller* micro_;
|
||||
|
||||
public slots:
|
||||
|
||||
virtual void setValue(uint8_t value);
|
||||
protected:
|
||||
virtual void enactValue(uint8_t value) override;
|
||||
|
||||
public:
|
||||
RgbItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "",
|
||||
uint8_t value = 0, QObject* parent = nullptr);
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void store(QJsonObject& json) override;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include "systemitem.h"
|
||||
#include <QProcess>
|
||||
|
||||
void SystemItem::setValue(uint8_t value)
|
||||
void SystemItem::enactValue(uint8_t value)
|
||||
{
|
||||
QProcess::execute(value ? onCommand_ : offCommand_);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,16 +7,13 @@ class SystemItem : public Item
|
|||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
|
||||
QString onCommand_;
|
||||
QString offCommand_;
|
||||
|
||||
public:
|
||||
|
||||
virtual void setValue(uint8_t value);
|
||||
protected:
|
||||
virtual void enactValue(uint8_t value) override;
|
||||
|
||||
public:
|
||||
|
||||
SystemItem(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0,
|
||||
QObject *parent = nullptr);
|
||||
SystemItem(const ItemData& itemData, QObject *parent = nullptr);
|
||||
|
|
@ -33,8 +30,8 @@ public:
|
|||
return offCommand_;
|
||||
}
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||
virtual void store(QJsonObject& json) override;
|
||||
virtual void load(const QJsonObject& json, const bool preserve = false) override;
|
||||
};
|
||||
|
||||
#endif // SYSTEMITEM_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue