Fix bug that prevented aquireing new items
Add save button to master that saves json file Remove autosave on quit
This commit is contained in:
@ -99,7 +99,6 @@ void AlarmTime::doTick()
|
||||
{
|
||||
if(time_.time().hour() == QTime::currentTime().hour() && time_.time().minute() == QTime::currentTime().minute())
|
||||
{
|
||||
qDebug()<<"Trigger\n";
|
||||
triggerd_=true;
|
||||
performAction();
|
||||
if(repeat_ == REPEAT_NEVER) exausted = true;
|
||||
|
@ -71,10 +71,12 @@ void ItemStore::clear()
|
||||
|
||||
void ItemStore::itemStateChanged(const ItemData& item)
|
||||
{
|
||||
|
||||
for(unsigned i = 0; i < items_.size(); i++ )
|
||||
{
|
||||
if(items_[i]->operator==(item))
|
||||
{
|
||||
|
||||
if(items_[i]->getValue() != item.getValue())items_[i]->informValue(item.getValue());
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "poweritem.h"
|
||||
#include <QProcess>
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
|
||||
PowerItem::PowerItem(uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(itemIdIn, name, value, parent)
|
||||
{
|
||||
@ -10,6 +11,7 @@ PowerItem::PowerItem(uint32_t itemIdIn, QString name, uint8_t value, QObject* p
|
||||
|
||||
void PowerItem::setValue(uint8_t value)
|
||||
{
|
||||
qDebug()<<"shutdown";
|
||||
Item::setValue(value);
|
||||
if(!value)
|
||||
{
|
||||
@ -20,6 +22,7 @@ void PowerItem::setValue(uint8_t value)
|
||||
|
||||
void PowerItem::timeout()
|
||||
{
|
||||
qDebug()<<"shutdown timeout";
|
||||
QProcess::startDetached("syncoff");
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ 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);
|
||||
qDebug()<<"Relay "<<id_<<"Name "<<name<<" id "<<itemId_<<" state "<<state<<" addr: "<<address;
|
||||
}
|
||||
|
||||
void Relay::setValue(uint8_t value)
|
||||
|
@ -118,6 +118,7 @@ int main(int argc, char *argv[])
|
||||
MainWindow w(&mainObject);
|
||||
QObject::connect(&mainObject.micro, SIGNAL(textRecived(QString)), &w, SLOT(changeHeaderLableText(QString)));
|
||||
QObject::connect(&w, &MainWindow::sigBrodcast, &mainObject, &MainObject::sendJson);
|
||||
QObject::connect(&w, &MainWindow::sigSave, &mainObject, &MainObject::storeToDisk);
|
||||
QObject::connect(&w, &MainWindow::createdItem, &mainObject.items, &ItemStore::addItem);
|
||||
if(!mainObject.micro.connected()) w.changeHeaderLableText("No io debug only!");
|
||||
|
||||
@ -125,7 +126,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
int retVal = a.exec();
|
||||
|
||||
if(masterIODevice) delete masterIODevice;
|
||||
if(masterIODevice)
|
||||
delete masterIODevice;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
@ -56,12 +56,6 @@ MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const
|
||||
|
||||
MainObject::~MainObject()
|
||||
{
|
||||
if(master)
|
||||
{
|
||||
QJsonObject json;
|
||||
store(json);
|
||||
if(!noSave)storeJsonObjectToDisk(json, settingsPath);
|
||||
}
|
||||
}
|
||||
|
||||
void MainObject::store(QJsonObject &json)
|
||||
@ -98,9 +92,20 @@ void MainObject::load(const QJsonObject& json)
|
||||
micro.requestState();
|
||||
}
|
||||
|
||||
void MainObject::storeToDisk()
|
||||
{
|
||||
if(master && !noSave)
|
||||
{
|
||||
QJsonObject json;
|
||||
store(json);
|
||||
storeJsonObjectToDisk(json, settingsPath);
|
||||
}
|
||||
}
|
||||
|
||||
void MainObject::recivedJson(const QJsonObject json)
|
||||
{
|
||||
if(master && !noSave)storeJsonObjectToDisk(json, settingsPath);
|
||||
if(master && !noSave)
|
||||
storeJsonObjectToDisk(json, settingsPath);
|
||||
load(json);
|
||||
}
|
||||
|
||||
|
@ -72,13 +72,14 @@ public:
|
||||
~MainObject();
|
||||
|
||||
void store(QJsonObject& json);
|
||||
|
||||
void load(const QJsonObject& json);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
void storeToDisk();
|
||||
void sendJson();
|
||||
void recivedJson(const QJsonObject json);
|
||||
|
||||
|
@ -124,14 +124,13 @@ void Microcontroller::setIODevice(QIODevice *port)
|
||||
std::shared_ptr<Relay> Microcontroller::processRelayLine(const QString& buffer)
|
||||
{
|
||||
QStringList bufferList = buffer.split(' ');
|
||||
if(bufferList.size() >= 8 && buffer.startsWith("ITEM NUMBER:"))
|
||||
if(bufferList.size() >= 9 && buffer.startsWith("ITEM NUMBER:"))
|
||||
{
|
||||
QString name;
|
||||
for(int i = 8; i < bufferList.size(); i++) name.append(bufferList[i] + ' ');
|
||||
for(int i = 10; i < bufferList.size(); i++) name.append(bufferList[i] + ' ');
|
||||
if(name.size() > 1)name.remove(name.size()-1, 1);
|
||||
else name = "Relay " + QString::number(bufferList[1].toInt(nullptr, 2));
|
||||
qDebug()<<"Relay "<<bufferList[2].toInt()<<"Name "<<name<<" id "<<bufferList[4].toInt(nullptr, 2)<<" state "<<bufferList[6].toInt();
|
||||
return std::shared_ptr<Relay>( new Relay(bufferList[2].toInt(), name, bufferList[4].toInt(nullptr, 2), bufferList[6].toInt()));
|
||||
return std::shared_ptr<Relay>( new Relay(bufferList[2].toInt(), name, bufferList[4].toInt(nullptr, 2), bufferList[8].toInt()));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@ -170,7 +169,7 @@ void Microcontroller::processMicroReturn()
|
||||
if(listMode) processList(_buffer);
|
||||
else
|
||||
{
|
||||
if(_buffer.startsWith("Relays:"))
|
||||
if(_buffer.startsWith("Items:"))
|
||||
{
|
||||
listMode = true;
|
||||
relayList.clear();
|
||||
|
@ -15,6 +15,7 @@ public:
|
||||
static constexpr uint8_t TYPE_PRESSURE = 3;
|
||||
static constexpr uint8_t TYPE_BRIGHTNESS = 4;
|
||||
static constexpr uint8_t TYPE_BUTTON = 5;
|
||||
static constexpr uint8_t TYPE_ADC = 6;
|
||||
static constexpr uint8_t TYPE_LOWBATTERY = 128;
|
||||
static constexpr uint8_t TYPE_SHUTDOWN_IMMINENT = 251;
|
||||
static constexpr uint8_t TYPE_OCUPANCY = 252;
|
||||
|
@ -89,6 +89,8 @@ void ActorSettingsDialog::init()
|
||||
if(actor_->getTriggerValue() == 0) ui->comboBox_action->setCurrentIndex(0);
|
||||
else if(actor_->getTriggerValue() == 1) ui->comboBox_action->setCurrentIndex(1);
|
||||
else ui->comboBox_action->setCurrentIndex(2);
|
||||
|
||||
ui->label_Exausted->setText(actor_->isExausted() ? "True" : "False");
|
||||
}
|
||||
|
||||
ActorSettingsDialog::~ActorSettingsDialog()
|
||||
@ -107,7 +109,7 @@ void ActorSettingsDialog::valueChanged(int value)
|
||||
actor_->setTriggerValue(value);
|
||||
}
|
||||
|
||||
void ActorSettingsDialog::hideCancle(const bool hide)
|
||||
void ActorSettingsDialog::hideCancle([[maybe_unused]] const bool hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -63,6 +63,30 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Exausted:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_Exausted">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>False</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_editItem">
|
||||
<property name="text">
|
||||
|
@ -24,6 +24,7 @@ AlarmWidget::AlarmWidget(std::shared_ptr<AlarmTime> alarm, QWidget *parent) :
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->checkBox->setChecked(true);
|
||||
ui->radioButton->setEnabled(true);
|
||||
ui->radioButton_2->setEnabled(true);
|
||||
ui->radioButton_3->setEnabled(true);
|
||||
|
@ -14,8 +14,10 @@ MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
if(!mainObject->master) connect(ui->pushButton_broadcast, &QPushButton::clicked, this, &MainWindow::sigBrodcast);
|
||||
else ui->pushButton_broadcast->hide();
|
||||
if(!mainObject->master)
|
||||
connect(ui->pushButton_broadcast, &QPushButton::clicked, this, &MainWindow::sigBrodcast);
|
||||
else
|
||||
connect(ui->pushButton_broadcast, &QPushButton::clicked, this, &MainWindow::sigSave);
|
||||
|
||||
connect(ui->pushButton_power, SIGNAL(clicked()), this, SLOT(showPowerItemDialog()));
|
||||
|
||||
|
@ -41,6 +41,7 @@ private:
|
||||
signals:
|
||||
|
||||
void sigBrodcast();
|
||||
void sigSave();
|
||||
void createdItem(std::shared_ptr<Item> item);
|
||||
|
||||
private slots:
|
||||
|
Reference in New Issue
Block a user