Compare commits
No commits in common. "9648c7c040a388d891639d3a5cc46ad522821771" and "24c168cf644f68fb08149795b8dec4926bf21c51" have entirely different histories.
9648c7c040
...
24c168cf64
5 changed files with 31 additions and 56 deletions
|
|
@ -161,34 +161,26 @@ Item& Item::operator=(const ItemData& other)
|
||||||
|
|
||||||
void Item::requestUpdate(ItemUpdateRequest update)
|
void Item::requestUpdate(ItemUpdateRequest update)
|
||||||
{
|
{
|
||||||
assert(update.type != ITEM_UPDATE_INVALID);
|
if(!hasChanged(update.payload))
|
||||||
if(update.type != ITEM_UPDATE_LOADED && value_ == update.payload.getValue())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(update.type == ITEM_UPDATE_ACTOR && override_)
|
if(update.type == ITEM_UPDATE_ACTOR && override_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qDebug()<<"Item Update Request for"<<getName()<<" type "<<update.type<<" value "<<update.payload.getValue();
|
if(update.type != ITEM_UPDATE_LOADED
|
||||||
|
&& (programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY))
|
||||||
if(update.type != ITEM_UPDATE_LOADED &&
|
|
||||||
update.type != ITEM_UPDATE_BACKEND &&
|
|
||||||
(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY))
|
|
||||||
enactValue(update.payload.getValue());
|
enactValue(update.payload.getValue());
|
||||||
|
|
||||||
if(update.type != ITEM_UPDATE_LOADED)
|
*this = update.payload;
|
||||||
|
update.payload = *this;
|
||||||
|
|
||||||
|
if(update.type == ITEM_UPDATE_LOADED)
|
||||||
{
|
{
|
||||||
value_ = update.payload.getValue();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
name_ = update.payload.getName();
|
|
||||||
//itemId_ = update.payload.id();
|
|
||||||
hidden_ = update.payload.isHidden();
|
|
||||||
actors_.clear();
|
actors_.clear();
|
||||||
for(std::shared_ptr<Actor>& actor : update.newActors)
|
for(std::shared_ptr<Actor>& actor : update.newActors)
|
||||||
addActor(actor);
|
addActor(actor);
|
||||||
}
|
}
|
||||||
update.payload = *this;
|
|
||||||
updated(update);
|
updated(update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -294,7 +286,6 @@ ItemUpdateRequest Item::createValueUpdateRequest(uint8_t value,
|
||||||
bool withActors)
|
bool withActors)
|
||||||
{
|
{
|
||||||
ItemUpdateRequest update;
|
ItemUpdateRequest update;
|
||||||
update.type = type;
|
|
||||||
update.payload = *this;
|
update.payload = *this;
|
||||||
update.payload.setValueData(value);
|
update.payload.setValueData(value);
|
||||||
if(withActors)
|
if(withActors)
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,7 @@ typedef enum {
|
||||||
ITEM_UPDATE_ACTOR,
|
ITEM_UPDATE_ACTOR,
|
||||||
ITEM_UPDATE_REMOTE,
|
ITEM_UPDATE_REMOTE,
|
||||||
ITEM_UPDATE_LOADED,
|
ITEM_UPDATE_LOADED,
|
||||||
ITEM_UPDATE_BACKEND,
|
ITEM_UPDATE_BACKEND
|
||||||
ITEM_UPDATE_INVALID
|
|
||||||
} item_update_type_t;
|
} item_update_type_t;
|
||||||
|
|
||||||
class ItemData
|
class ItemData
|
||||||
|
|
@ -68,7 +67,7 @@ public:
|
||||||
|
|
||||||
struct ItemUpdateRequest
|
struct ItemUpdateRequest
|
||||||
{
|
{
|
||||||
item_update_type_t type = ITEM_UPDATE_INVALID;
|
item_update_type_t type;
|
||||||
ItemData payload;
|
ItemData payload;
|
||||||
std::vector<std::shared_ptr<Actor> > newActors;
|
std::vector<std::shared_ptr<Actor> > newActors;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ void ItemStore::addItem(const std::shared_ptr<Item>& item, item_update_type_t up
|
||||||
ItemUpdateRequest request = item->createValueUpdateRequest(item->getValue(),
|
ItemUpdateRequest request = item->createValueUpdateRequest(item->getValue(),
|
||||||
updateType,
|
updateType,
|
||||||
updateType == ITEM_UPDATE_LOADED);
|
updateType == ITEM_UPDATE_LOADED);
|
||||||
request.newActors = item->getActors();
|
|
||||||
updateItem(request);
|
updateItem(request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -57,7 +56,6 @@ 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)
|
||||||
{
|
{
|
||||||
qDebug()<<__func__;
|
|
||||||
addItems(items, ITEM_UPDATE_LOADED);
|
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_)
|
||||||
|
|
@ -88,6 +86,7 @@ void ItemStore::updateItem(const ItemUpdateRequest& update)
|
||||||
if(items_[i]->operator==(update.payload))
|
if(items_[i]->operator==(update.payload))
|
||||||
{
|
{
|
||||||
items_[i]->requestUpdate(update);
|
items_[i]->requestUpdate(update);
|
||||||
|
qDebug() << "Item" << items_[i]->getName() << "updated";
|
||||||
itemUpdated(update);
|
itemUpdated(update);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -107,6 +106,7 @@ void ItemStore::store(QJsonObject& json)
|
||||||
|
|
||||||
void ItemStore::itemUpdateSlot(ItemUpdateRequest update)
|
void ItemStore::itemUpdateSlot(ItemUpdateRequest update)
|
||||||
{
|
{
|
||||||
|
qDebug() << "Item" << update.payload.getName() << "updated from update slot";
|
||||||
itemUpdated(update);
|
itemUpdated(update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
#include "microcontroller.h"
|
#include "microcontroller.h"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
void Microcontroller::relayToggle(int state, int relay)
|
void Microcontroller::relayToggle(int state, int relay)
|
||||||
{
|
{
|
||||||
char buffer[8];
|
char buffer[8];
|
||||||
|
|
@ -46,34 +49,22 @@ void Microcontroller::setAuxPwm(int duty)
|
||||||
|
|
||||||
void Microcontroller::write(const QByteArray& buffer)
|
void Microcontroller::write(const QByteArray& buffer)
|
||||||
{
|
{
|
||||||
writeQue.enqueue(buffer);
|
if(_port != nullptr)
|
||||||
if(!writeTimer.isActive())
|
|
||||||
{
|
{
|
||||||
writeTimer.setInterval(0);
|
_port->write(buffer);
|
||||||
writeTimer.start();
|
_port->waitForBytesWritten(1000);
|
||||||
}
|
}
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(40));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::write(char* buffer, const size_t length)
|
void Microcontroller::write(char* buffer, const size_t length)
|
||||||
{
|
{
|
||||||
write(QByteArray(buffer, length));
|
if(_port != nullptr)
|
||||||
}
|
|
||||||
|
|
||||||
void Microcontroller::onWriteTimerTimeout()
|
|
||||||
{
|
{
|
||||||
writeTimer.setInterval(50);
|
_port->write(buffer, length);
|
||||||
if(connected())
|
_port->waitForBytesWritten(1000);
|
||||||
{
|
|
||||||
if(!writeQue.empty())
|
|
||||||
{
|
|
||||||
QByteArray data = writeQue.dequeue();
|
|
||||||
_port->write(data);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
writeTimer.stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(40));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::setPattern(int pattern)
|
void Microcontroller::setPattern(int pattern)
|
||||||
|
|
@ -91,10 +82,8 @@ void Microcontroller::startSunrise()
|
||||||
|
|
||||||
bool Microcontroller::connected()
|
bool Microcontroller::connected()
|
||||||
{
|
{
|
||||||
if(_port != nullptr)
|
if(_port != nullptr) return _port->isOpen();
|
||||||
return _port->isOpen();
|
else return false;
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::refresh()
|
void Microcontroller::refresh()
|
||||||
|
|
@ -104,17 +93,13 @@ void Microcontroller::refresh()
|
||||||
|
|
||||||
//housekeeping
|
//housekeeping
|
||||||
|
|
||||||
Microcontroller::Microcontroller(QIODevice* port): Microcontroller()
|
Microcontroller::Microcontroller(QIODevice* port)
|
||||||
{
|
{
|
||||||
setIODevice(port);
|
setIODevice(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
Microcontroller::Microcontroller()
|
Microcontroller::Microcontroller()
|
||||||
{
|
{
|
||||||
writeTimer.setInterval(50);
|
|
||||||
writeTimer.setSingleShot(false);
|
|
||||||
connect(&writeTimer, &QTimer::timeout, this, &Microcontroller::onWriteTimerTimeout);
|
|
||||||
qDebug()<<__func__<<writeTimer.isActive();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Microcontroller::~Microcontroller()
|
Microcontroller::~Microcontroller()
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QRunnable>
|
#include <QRunnable>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QEventLoop>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QByteArray>
|
#include <QAbstractButton>
|
||||||
#include <QQueue>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "items/item.h"
|
#include "items/item.h"
|
||||||
|
|
@ -32,12 +32,13 @@ private:
|
||||||
|
|
||||||
bool listMode = false;
|
bool listMode = false;
|
||||||
|
|
||||||
|
//uint8_t _auxState = 0;
|
||||||
|
|
||||||
QIODevice* _port = nullptr;
|
QIODevice* _port = nullptr;
|
||||||
QQueue<QByteArray> writeQue;
|
|
||||||
QTimer writeTimer;
|
|
||||||
|
|
||||||
std::vector< std::shared_ptr<Item> > relayList;
|
std::vector< std::shared_ptr<Item> > relayList;
|
||||||
|
|
||||||
|
QScopedPointer<QEventLoop> loop;
|
||||||
QString _buffer;
|
QString _buffer;
|
||||||
|
|
||||||
void processMicroReturn();
|
void processMicroReturn();
|
||||||
|
|
@ -74,7 +75,6 @@ public slots:
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void isReadyRead();
|
void isReadyRead();
|
||||||
void onWriteTimerTimeout();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void textRecived(const QString string);
|
void textRecived(const QString string);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue