ocupancy sensor now uses libnl to collect connected devices
fixed regulator saving values as int instead of double
This commit is contained in:
parent
772d21a982
commit
b0b4a985e9
15 changed files with 93 additions and 44 deletions
|
|
@ -15,7 +15,6 @@ void ItemStore::addItem(std::shared_ptr<Item> item)
|
|||
{
|
||||
items_.push_back(std::shared_ptr<Item>(item));
|
||||
itemAdded(std::weak_ptr<Item>(items_.back()));
|
||||
qDebug()<<"item added";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -75,7 +74,6 @@ void ItemStore::itemStateChanged(const ItemData& item)
|
|||
{
|
||||
if(items_[i]->operator==(item))
|
||||
{
|
||||
qDebug()<<"is item "<<i<<" with ids: "<<item.id()<<" "<<items_[i]->id()<<"\nHas state: "<<items_[i]->getValue()<<" wants state: "<<item.getValue();
|
||||
if(items_[i]->getValue() != item.getValue())items_[i]->informValue(item.getValue());
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +93,7 @@ void ItemStore::store(QJsonObject& json)
|
|||
json["Items"] = itemsArray;
|
||||
}
|
||||
|
||||
void ItemStore::load(const QJsonObject& json, Microcontroller * const micro)
|
||||
void ItemStore::load(const QJsonObject& json)
|
||||
{
|
||||
const QJsonArray itemsArray(json["Items"].toArray(QJsonArray()));
|
||||
for(int i = 0; i < itemsArray.size(); ++i)
|
||||
|
|
@ -106,7 +104,7 @@ void ItemStore::load(const QJsonObject& json, Microcontroller * const micro)
|
|||
std::shared_ptr<Item> newItem;
|
||||
if(itemObject["Type"].toString("") == "Relay")
|
||||
{
|
||||
newItem = std::shared_ptr<Relay>(new Relay(micro));
|
||||
newItem = std::shared_ptr<Relay>(new Relay());
|
||||
}
|
||||
else if(itemObject["Type"].toString("") == "Message")
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
#include <memory>
|
||||
#include "item.h"
|
||||
#include "../sensors/sensor.h"
|
||||
#include "../microcontroller.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
|
||||
|
|
@ -21,7 +20,7 @@ public:
|
|||
inline std::vector< std::shared_ptr<Item> >* getItems(){ return &items_; }
|
||||
|
||||
void store(QJsonObject &json);
|
||||
void load(const QJsonObject &json, Microcontroller * const micro);
|
||||
void load(const QJsonObject &json);
|
||||
|
||||
void clear();
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include <QTimer>
|
||||
|
||||
BroadCast* MessageItem::broadCast_ = nullptr;
|
||||
|
||||
MessageItem::MessageItem(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent):
|
||||
Item(itemIdIn, name, value, parent)
|
||||
{
|
||||
|
|
@ -28,6 +30,8 @@ void MessageItem::setValue(uint8_t value)
|
|||
messageBox_->setModal(false);
|
||||
connect(messageBox_, &QMessageBox::finished, this, &MessageItem::closeMessageBox);
|
||||
messageBox_->show();
|
||||
if(broadCast_) broadCast_->sendMessage(name_, message_);
|
||||
|
||||
//QTimer::singleShot(600000, this, &MessageItem::closeMessageBox);
|
||||
}
|
||||
else if(!value && messageBox_)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <QMessageBox>
|
||||
|
||||
#include "item.h"
|
||||
#include "../broadcast.h"
|
||||
|
||||
class MessageItem : public Item
|
||||
{
|
||||
|
|
@ -13,6 +14,8 @@ private:
|
|||
QString message_;
|
||||
QMessageBox* messageBox_ = nullptr;
|
||||
|
||||
static BroadCast* broadCast_;
|
||||
|
||||
private slots:
|
||||
|
||||
void closeMessageBox();
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@
|
|||
|
||||
//Relay
|
||||
|
||||
Relay::Relay(Microcontroller* micro, uint8_t id, QString name, uint16_t address, bool state, QObject* parent): Item(0, name, state, parent), micro_(micro), id_(id), address_(address)
|
||||
Microcontroller* Relay::micro_ = nullptr;
|
||||
|
||||
Relay::Relay(uint8_t id, QString name, uint16_t address, bool state, QObject* parent): Item(0, name, state, parent), id_(id), address_(address)
|
||||
{
|
||||
itemId_ = address | ((uint32_t)id << 16);
|
||||
}
|
||||
|
|
@ -11,8 +13,11 @@ Relay::Relay(Microcontroller* micro, uint8_t id, QString name, uint16_t address,
|
|||
void Relay::setValue(uint8_t value)
|
||||
{
|
||||
Item::setValue(value);
|
||||
if(value)micro_->relayOn(id_);
|
||||
else micro_->relayOff(id_);
|
||||
if(micro_)
|
||||
{
|
||||
if(value)micro_->relayOn(id_);
|
||||
else micro_->relayOff(id_);
|
||||
}
|
||||
}
|
||||
|
||||
void Relay::on()
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class Relay : public Item
|
|||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
Microcontroller* micro_;
|
||||
static Microcontroller* micro_;
|
||||
|
||||
uint8_t id_;
|
||||
uint16_t address_;
|
||||
|
|
@ -26,12 +26,14 @@ public slots:
|
|||
void toggle();
|
||||
|
||||
public:
|
||||
Relay(Microcontroller* micro, 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);
|
||||
|
||||
uint16_t getAddress() const;
|
||||
uint8_t getId() const;
|
||||
void setId(uint8_t id);
|
||||
|
||||
inline static void setMicrocontroller(Microcontroller* micro){ micro_ = micro; }
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue