move from tabs to spaces
This commit is contained in:
parent
a6aad07f05
commit
fa45072998
86 changed files with 2611 additions and 2486 deletions
|
|
@ -19,71 +19,71 @@ Actor::~Actor()
|
|||
|
||||
void Actor::performAction()
|
||||
{
|
||||
if(active)
|
||||
{
|
||||
sigValue(triggerValue);
|
||||
}
|
||||
if(active)
|
||||
{
|
||||
sigValue(triggerValue);
|
||||
}
|
||||
}
|
||||
|
||||
void Actor::makeActive()
|
||||
{
|
||||
active = true;
|
||||
active = true;
|
||||
}
|
||||
|
||||
|
||||
void Actor::makeInactive()
|
||||
{
|
||||
active = false;
|
||||
active = false;
|
||||
}
|
||||
|
||||
QString Actor::actionName()
|
||||
{
|
||||
QString string;
|
||||
if(triggerValue == 0 ) string = "off";
|
||||
else if(triggerValue == 1 ) string = "on";
|
||||
else string = "value to " + QString::number(triggerValue);
|
||||
return string;
|
||||
QString string;
|
||||
if(triggerValue == 0 ) string = "off";
|
||||
else if(triggerValue == 1 ) string = "on";
|
||||
else string = "value to " + QString::number(triggerValue);
|
||||
return string;
|
||||
}
|
||||
|
||||
void Actor::setActive(uint8_t state)
|
||||
{
|
||||
state ? makeActive() : makeInactive();
|
||||
state ? makeActive() : makeInactive();
|
||||
}
|
||||
|
||||
bool Actor::isActive()
|
||||
{
|
||||
return active;
|
||||
return active;
|
||||
}
|
||||
|
||||
bool Actor::isExausted()
|
||||
{
|
||||
return exausted;
|
||||
return exausted;
|
||||
}
|
||||
|
||||
void Actor::store(QJsonObject& json)
|
||||
{
|
||||
Item::store(json);
|
||||
json["Active"] = active;
|
||||
json["Exausted"] = exausted;
|
||||
json["TriggerValue"] = triggerValue;
|
||||
Item::store(json);
|
||||
json["Active"] = active;
|
||||
json["Exausted"] = exausted;
|
||||
json["TriggerValue"] = triggerValue;
|
||||
}
|
||||
|
||||
void Actor::load(const QJsonObject& json, const bool preserve)
|
||||
{
|
||||
Item::load(json, preserve);
|
||||
active = json["Active"].toBool();
|
||||
exausted = json["Exausted"].toBool();
|
||||
triggerValue = json["TriggerValue"].toInt();
|
||||
Item::load(json, preserve);
|
||||
active = json["Active"].toBool();
|
||||
exausted = json["Exausted"].toBool();
|
||||
triggerValue = json["TriggerValue"].toInt();
|
||||
}
|
||||
|
||||
void Actor::setTriggerValue(uint8_t value)
|
||||
{
|
||||
triggerValue=value;
|
||||
triggerValue=value;
|
||||
}
|
||||
|
||||
uint8_t Actor::getTriggerValue()
|
||||
{
|
||||
return triggerValue;
|
||||
return triggerValue;
|
||||
}
|
||||
|
||||
void Actor::onValueChanged(uint8_t value)
|
||||
|
|
@ -93,28 +93,28 @@ void Actor::onValueChanged(uint8_t value)
|
|||
|
||||
std::shared_ptr<Actor> Actor::createActor(const QString& type)
|
||||
{
|
||||
std::shared_ptr<Actor> actor;
|
||||
if(type == "Alarm") actor = std::shared_ptr<Actor>(new AlarmTime());
|
||||
else if(type == "Sensor") actor = std::shared_ptr<Actor>(new SensorActor());
|
||||
else if(type == "Timer") actor = std::shared_ptr<Actor>(new TimerActor());
|
||||
else if(type == "Regulator") actor = std::shared_ptr<Actor>(new Regulator());
|
||||
else if(type == "Polynomal") actor = std::shared_ptr<Actor>(new PolynomalActor());
|
||||
else if(type == "MultiFactor") actor = std::shared_ptr<Actor>(new MultiFactorActor());
|
||||
else if(type == "Actor") actor = std::shared_ptr<Actor>(new Actor());
|
||||
return actor;
|
||||
std::shared_ptr<Actor> actor;
|
||||
if(type == "Alarm") actor = std::shared_ptr<Actor>(new AlarmTime());
|
||||
else if(type == "Sensor") actor = std::shared_ptr<Actor>(new SensorActor());
|
||||
else if(type == "Timer") actor = std::shared_ptr<Actor>(new TimerActor());
|
||||
else if(type == "Regulator") actor = std::shared_ptr<Actor>(new Regulator());
|
||||
else if(type == "Polynomal") actor = std::shared_ptr<Actor>(new PolynomalActor());
|
||||
else if(type == "MultiFactor") actor = std::shared_ptr<Actor>(new MultiFactorActor());
|
||||
else if(type == "Actor") actor = std::shared_ptr<Actor>(new Actor());
|
||||
return actor;
|
||||
}
|
||||
|
||||
std::shared_ptr<Actor> Actor::loadActor(const QJsonObject &json)
|
||||
{
|
||||
QString type = json["Type"].toString("Actor");
|
||||
std::shared_ptr<Actor> actor = createActor(type);
|
||||
if(actor) actor->load(json);
|
||||
return actor;
|
||||
QString type = json["Type"].toString("Actor");
|
||||
std::shared_ptr<Actor> actor = createActor(type);
|
||||
if(actor) actor->load(json);
|
||||
return actor;
|
||||
}
|
||||
|
||||
void Actor::setValue(uint8_t value)
|
||||
{
|
||||
Item::setValue(value);
|
||||
setActive(value);
|
||||
Item::setValue(value);
|
||||
setActive(value);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,46 +9,46 @@
|
|||
|
||||
class Actor : public Item
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
uint8_t triggerValue = 0;
|
||||
uint8_t triggerValue = 0;
|
||||
|
||||
protected:
|
||||
bool active = true;
|
||||
bool exausted = false;
|
||||
bool active = true;
|
||||
bool exausted = false;
|
||||
|
||||
void performAction();
|
||||
void performAction();
|
||||
|
||||
signals:
|
||||
|
||||
void sigValue(uint8_t value);
|
||||
void sigValue(uint8_t value);
|
||||
|
||||
public slots:
|
||||
virtual void makeActive();
|
||||
virtual void makeInactive();
|
||||
virtual void setActive(uint8_t state);
|
||||
virtual void onValueChanged(uint8_t state);
|
||||
virtual void makeActive();
|
||||
virtual void makeInactive();
|
||||
virtual void setActive(uint8_t state);
|
||||
virtual void onValueChanged(uint8_t state);
|
||||
|
||||
virtual void setValue(uint8_t value);
|
||||
virtual void setValue(uint8_t value);
|
||||
|
||||
public:
|
||||
Actor(QObject* parent = nullptr);
|
||||
virtual ~Actor();
|
||||
bool isExausted();
|
||||
Actor(QObject* parent = nullptr);
|
||||
virtual ~Actor();
|
||||
bool isExausted();
|
||||
|
||||
virtual QString actionName();
|
||||
virtual QString actionName();
|
||||
|
||||
bool isActive();
|
||||
void setTriggerValue(uint8_t value);
|
||||
bool isActive();
|
||||
void setTriggerValue(uint8_t value);
|
||||
|
||||
uint8_t getTriggerValue();
|
||||
uint8_t getTriggerValue();
|
||||
|
||||
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 load(const QJsonObject& json, const bool preserve = false);
|
||||
static std::shared_ptr<Actor> loadActor(const QJsonObject& json);
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||
static std::shared_ptr<Actor> loadActor(const QJsonObject& json);
|
||||
};
|
||||
|
||||
#endif // ACTOR_H
|
||||
|
|
|
|||
|
|
@ -2,132 +2,132 @@
|
|||
|
||||
AlarmTime::AlarmTime(const QDateTime time, QObject *parent) : Actor(parent), time_(time)
|
||||
{
|
||||
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
|
||||
timer.setInterval(1000);
|
||||
run();
|
||||
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
|
||||
timer.setInterval(1000);
|
||||
run();
|
||||
}
|
||||
|
||||
AlarmTime::~AlarmTime()
|
||||
{
|
||||
makeInactive();
|
||||
makeInactive();
|
||||
}
|
||||
|
||||
void AlarmTime::run()
|
||||
{
|
||||
makeInactive();
|
||||
makeInactive();
|
||||
|
||||
active = true;
|
||||
timer.start();
|
||||
active = true;
|
||||
timer.start();
|
||||
}
|
||||
|
||||
void AlarmTime::makeActive()
|
||||
{
|
||||
run();
|
||||
run();
|
||||
}
|
||||
|
||||
QString AlarmTime::getName() const
|
||||
{
|
||||
if(name_.size() > 0)return name_;
|
||||
else
|
||||
{
|
||||
QString string;
|
||||
string = "Alarm: ";
|
||||
if(repeat_ == REPEAT_DAILY)
|
||||
{
|
||||
string.append("daily ");
|
||||
string.append(time_.toString("HH:mm"));
|
||||
}
|
||||
else if(repeat_ == REPEAT_WEEKLY)
|
||||
{
|
||||
string.append("weekly ");
|
||||
string.append(time_.toString("ddd HH:mm"));
|
||||
if(name_.size() > 0)return name_;
|
||||
else
|
||||
{
|
||||
QString string;
|
||||
string = "Alarm: ";
|
||||
if(repeat_ == REPEAT_DAILY)
|
||||
{
|
||||
string.append("daily ");
|
||||
string.append(time_.toString("HH:mm"));
|
||||
}
|
||||
else if(repeat_ == REPEAT_WEEKLY)
|
||||
{
|
||||
string.append("weekly ");
|
||||
string.append(time_.toString("ddd HH:mm"));
|
||||
|
||||
}
|
||||
else if(repeat_ == REPEAT_MONTHLY)
|
||||
{
|
||||
string.append("monthly ");
|
||||
string.append(time_.toString("dd HH:mm"));
|
||||
}
|
||||
else if(repeat_ == REPEAT_YEARLY)
|
||||
{
|
||||
string.append("yearly ");
|
||||
string.append(time_.toString("dd.mm HH:mm"));
|
||||
}
|
||||
else if(repeat_ == REPEAT_MONTHLY)
|
||||
{
|
||||
string.append("monthly ");
|
||||
string.append(time_.toString("dd HH:mm"));
|
||||
}
|
||||
else if(repeat_ == REPEAT_YEARLY)
|
||||
{
|
||||
string.append("yearly ");
|
||||
string.append(time_.toString("dd.mm HH:mm"));
|
||||
|
||||
}
|
||||
else string.append(time_.toString("dd.mm.yyyy HH:mm"));
|
||||
return string;
|
||||
}
|
||||
}
|
||||
else string.append(time_.toString("dd.mm.yyyy HH:mm"));
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
void AlarmTime::setRepeat(const uint8_t repeat)
|
||||
{
|
||||
repeat_=repeat;
|
||||
exausted = false;
|
||||
repeat_=repeat;
|
||||
exausted = false;
|
||||
}
|
||||
|
||||
uint8_t AlarmTime::getRepeat()
|
||||
{
|
||||
return repeat_;
|
||||
return repeat_;
|
||||
}
|
||||
|
||||
QDateTime AlarmTime::getDateTime()
|
||||
{
|
||||
return time_;
|
||||
return time_;
|
||||
}
|
||||
|
||||
void AlarmTime::makeInactive()
|
||||
{
|
||||
timer.stop();
|
||||
active = false;
|
||||
timer.stop();
|
||||
active = false;
|
||||
}
|
||||
|
||||
void AlarmTime::doTick()
|
||||
{
|
||||
if(
|
||||
(
|
||||
(triggerd_ == false) &&
|
||||
(time_.date().year() == QDate::currentDate().year() || repeat_ != REPEAT_NEVER) &&
|
||||
(time_.date().month() == QDate::currentDate().month() || repeat_ == REPEAT_MONTHLY || repeat_ == REPEAT_DAILY) &&
|
||||
(time_.date().day() == QDate::currentDate().day() || repeat_ == REPEAT_DAILY)
|
||||
)
|
||||
||
|
||||
(
|
||||
(repeat_ == REPEAT_WEEKLY) &&
|
||||
(time_.date().dayOfWeek() == QDate::currentDate().dayOfWeek())
|
||||
)
|
||||
)
|
||||
{
|
||||
if(time_.time().hour() == QTime::currentTime().hour() && time_.time().minute() == QTime::currentTime().minute())
|
||||
{
|
||||
triggerd_=true;
|
||||
performAction();
|
||||
if(repeat_ == REPEAT_NEVER) exausted = true;
|
||||
}
|
||||
}
|
||||
else if( repeat_ != REPEAT_NEVER && time_.time().hour() != QTime::currentTime().hour() ) triggerd_=false;
|
||||
if(
|
||||
(
|
||||
(triggerd_ == false) &&
|
||||
(time_.date().year() == QDate::currentDate().year() || repeat_ != REPEAT_NEVER) &&
|
||||
(time_.date().month() == QDate::currentDate().month() || repeat_ == REPEAT_MONTHLY || repeat_ == REPEAT_DAILY) &&
|
||||
(time_.date().day() == QDate::currentDate().day() || repeat_ == REPEAT_DAILY)
|
||||
)
|
||||
||
|
||||
(
|
||||
(repeat_ == REPEAT_WEEKLY) &&
|
||||
(time_.date().dayOfWeek() == QDate::currentDate().dayOfWeek())
|
||||
)
|
||||
)
|
||||
{
|
||||
if(time_.time().hour() == QTime::currentTime().hour() && time_.time().minute() == QTime::currentTime().minute())
|
||||
{
|
||||
triggerd_=true;
|
||||
performAction();
|
||||
if(repeat_ == REPEAT_NEVER) exausted = true;
|
||||
}
|
||||
}
|
||||
else if( repeat_ != REPEAT_NEVER && time_.time().hour() != QTime::currentTime().hour() ) triggerd_=false;
|
||||
}
|
||||
|
||||
void AlarmTime::changeTime(const QDateTime& time)
|
||||
{
|
||||
time_=time;
|
||||
exausted = false;
|
||||
qDebug()<<"time: "<<time_;
|
||||
time_=time;
|
||||
exausted = false;
|
||||
qDebug()<<"time: "<<time_;
|
||||
}
|
||||
|
||||
|
||||
void AlarmTime::store(QJsonObject& json)
|
||||
{
|
||||
json["Type"] = "Alarm";
|
||||
Actor::store(json);
|
||||
json["Time"] = time_.toString();
|
||||
json["Repeat"] = repeat_;
|
||||
json["Type"] = "Alarm";
|
||||
Actor::store(json);
|
||||
json["Time"] = time_.toString();
|
||||
json["Repeat"] = repeat_;
|
||||
}
|
||||
|
||||
void AlarmTime::load(const QJsonObject& json, const bool preserve)
|
||||
{
|
||||
bool oldActive = isActive();
|
||||
Actor::load(json, preserve);
|
||||
time_ = QDateTime::fromString(json["Time"].toString(""));
|
||||
repeat_ = json["Repeat"].toInt(REPEAT_NEVER);
|
||||
if(oldActive != isActive()) setActive(isActive());
|
||||
bool oldActive = isActive();
|
||||
Actor::load(json, preserve);
|
||||
time_ = QDateTime::fromString(json["Time"].toString(""));
|
||||
repeat_ = json["Repeat"].toInt(REPEAT_NEVER);
|
||||
if(oldActive != isActive()) setActive(isActive());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,41 +14,41 @@
|
|||
|
||||
class AlarmTime : public Actor, public QRunnable
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
static const uint8_t REPEAT_NEVER = 0;
|
||||
static const uint8_t REPEAT_DAILY = 1;
|
||||
static const uint8_t REPEAT_WEEKLY = 2;
|
||||
static const uint8_t REPEAT_MONTHLY = 3;
|
||||
static const uint8_t REPEAT_YEARLY = 4;
|
||||
static const uint8_t REPEAT_NEVER = 0;
|
||||
static const uint8_t REPEAT_DAILY = 1;
|
||||
static const uint8_t REPEAT_WEEKLY = 2;
|
||||
static const uint8_t REPEAT_MONTHLY = 3;
|
||||
static const uint8_t REPEAT_YEARLY = 4;
|
||||
|
||||
private:
|
||||
|
||||
bool triggerd_ = false;
|
||||
QDateTime time_;
|
||||
QTimer timer;
|
||||
uint8_t repeat_ = REPEAT_NEVER;
|
||||
bool triggerd_ = false;
|
||||
QDateTime time_;
|
||||
QTimer timer;
|
||||
uint8_t repeat_ = REPEAT_NEVER;
|
||||
|
||||
public:
|
||||
explicit AlarmTime(const QDateTime time = QDateTime::currentDateTime(), QObject *parent = nullptr);
|
||||
~AlarmTime();
|
||||
explicit AlarmTime(const QDateTime time = QDateTime::currentDateTime(), QObject *parent = nullptr);
|
||||
~AlarmTime();
|
||||
|
||||
QDateTime getDateTime();
|
||||
QDateTime getDateTime();
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||
|
||||
uint8_t getRepeat();
|
||||
uint8_t getRepeat();
|
||||
|
||||
public slots:
|
||||
|
||||
void run();
|
||||
virtual void makeActive();
|
||||
virtual void makeInactive();
|
||||
virtual QString getName() const;
|
||||
void doTick();
|
||||
void changeTime(const QDateTime& time);
|
||||
void setRepeat(const uint8_t repeat);
|
||||
void run();
|
||||
virtual void makeActive();
|
||||
virtual void makeInactive();
|
||||
virtual QString getName() const;
|
||||
void doTick();
|
||||
void changeTime(const QDateTime& time);
|
||||
void setRepeat(const uint8_t repeat);
|
||||
};
|
||||
|
||||
#endif // ALARMTIME_H
|
||||
|
|
|
|||
|
|
@ -1,79 +1,79 @@
|
|||
#include "factoractor.h"
|
||||
|
||||
MultiFactorActor::MultiFactorActor(Actor* factorActor, const uint preCancleMin, QObject *parent):
|
||||
Actor(parent),
|
||||
factorActor_(factorActor),
|
||||
preCancleMin_(preCancleMin)
|
||||
Actor(parent),
|
||||
factorActor_(factorActor),
|
||||
preCancleMin_(preCancleMin)
|
||||
{
|
||||
activationTime.setMSecsSinceEpoch(0);
|
||||
if(factorActor) connect(factorActor, &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
||||
activationTime.setMSecsSinceEpoch(0);
|
||||
if(factorActor) connect(factorActor, &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
||||
}
|
||||
|
||||
void MultiFactorActor::factorActorSlot(uint8_t value)
|
||||
{
|
||||
if(value == factorDirection)
|
||||
{
|
||||
activationTime = QDateTime::currentDateTime();
|
||||
}
|
||||
if(value == factorDirection)
|
||||
{
|
||||
activationTime = QDateTime::currentDateTime();
|
||||
}
|
||||
}
|
||||
|
||||
void MultiFactorActor::setValue(uint8_t value)
|
||||
{
|
||||
if(value)
|
||||
{
|
||||
QDateTime current = QDateTime::currentDateTime();
|
||||
if(current.addSecs(-preCancleMin_*60) > activationTime )
|
||||
{
|
||||
performAction();
|
||||
}
|
||||
bool exausted = true;
|
||||
for(size_t i = 0; i < getActors().size(); ++i) if(!getActors()[i]->isExausted()) exausted = false;
|
||||
}
|
||||
if(value)
|
||||
{
|
||||
QDateTime current = QDateTime::currentDateTime();
|
||||
if(current.addSecs(-preCancleMin_*60) > activationTime )
|
||||
{
|
||||
performAction();
|
||||
}
|
||||
bool exausted = true;
|
||||
for(size_t i = 0; i < getActors().size(); ++i) if(!getActors()[i]->isExausted()) exausted = false;
|
||||
}
|
||||
}
|
||||
|
||||
QString MultiFactorActor::getName() const
|
||||
{
|
||||
if(name_.size() > 0) return name_;
|
||||
else
|
||||
{
|
||||
QString string;
|
||||
string = "Multi Factor \"" + (factorActor_ ? factorActor_->getName() : "NULL") + "\"";
|
||||
return string;
|
||||
}
|
||||
if(name_.size() > 0) return name_;
|
||||
else
|
||||
{
|
||||
QString string;
|
||||
string = "Multi Factor \"" + (factorActor_ ? factorActor_->getName() : "NULL") + "\"";
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
void MultiFactorActor::setFactorActor(std::shared_ptr<Actor> factorActor)
|
||||
{
|
||||
factorActor_=factorActor;
|
||||
connect(factorActor_.get(), &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
||||
factorActor_=factorActor;
|
||||
connect(factorActor_.get(), &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
||||
}
|
||||
|
||||
void MultiFactorActor::store(QJsonObject &json)
|
||||
{
|
||||
json["Type"] = "MultiFactor";
|
||||
Actor::store(json);
|
||||
json["PreCancleMinutes"] = static_cast<int>(preCancleMin_);
|
||||
json["FactorDirection"] = factorDirection;
|
||||
QJsonObject factorActorObject;
|
||||
if(factorActor_)
|
||||
{
|
||||
factorActor_->store(factorActorObject);
|
||||
}
|
||||
json["Type"] = "MultiFactor";
|
||||
Actor::store(json);
|
||||
json["PreCancleMinutes"] = static_cast<int>(preCancleMin_);
|
||||
json["FactorDirection"] = factorDirection;
|
||||
QJsonObject factorActorObject;
|
||||
if(factorActor_)
|
||||
{
|
||||
factorActor_->store(factorActorObject);
|
||||
}
|
||||
}
|
||||
|
||||
void MultiFactorActor::load(const QJsonObject &json, bool preserve)
|
||||
{
|
||||
Actor::load(json, preserve);
|
||||
preCancleMin_ = static_cast<uint>(json["PreCancleMinutes"].toInt(10));
|
||||
factorDirection = json["FacotorDirection"].toBool(true);
|
||||
if(json["FactorActor"].isObject())
|
||||
{
|
||||
factorActor_ = Actor::loadActor(json["FactorActor"].toObject());
|
||||
}
|
||||
if(factorActor_)
|
||||
{
|
||||
connect(factorActor_.get(), &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
||||
}
|
||||
Actor::load(json, preserve);
|
||||
preCancleMin_ = static_cast<uint>(json["PreCancleMinutes"].toInt(10));
|
||||
factorDirection = json["FacotorDirection"].toBool(true);
|
||||
if(json["FactorActor"].isObject())
|
||||
{
|
||||
factorActor_ = Actor::loadActor(json["FactorActor"].toObject());
|
||||
}
|
||||
if(factorActor_)
|
||||
{
|
||||
connect(factorActor_.get(), &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,37 +8,52 @@ class MultiFactorActor: public Actor
|
|||
{
|
||||
private:
|
||||
|
||||
std::shared_ptr<Actor> factorActor_;
|
||||
QDateTime activationTime;
|
||||
uint preCancleMin_;
|
||||
std::shared_ptr<Actor> factorActor_;
|
||||
QDateTime activationTime;
|
||||
uint preCancleMin_;
|
||||
|
||||
bool factorDirection = true;
|
||||
bool factorDirection = true;
|
||||
|
||||
private slots:
|
||||
|
||||
void factorActorSlot(uint8_t value);
|
||||
void factorActorSlot(uint8_t value);
|
||||
|
||||
public slots:
|
||||
|
||||
virtual void setValue(uint8_t value);
|
||||
virtual void setValue(uint8_t value);
|
||||
|
||||
public:
|
||||
|
||||
MultiFactorActor(Actor* FactorActor = nullptr, const uint preCancleMin = 10, QObject *parent = nullptr);
|
||||
MultiFactorActor(Actor* FactorActor = nullptr, const uint preCancleMin = 10, QObject *parent = nullptr);
|
||||
|
||||
virtual QString getName() const;
|
||||
virtual QString getName() const;
|
||||
|
||||
void setFactorActor(std::shared_ptr<Actor> factorActor);
|
||||
std::shared_ptr<Actor> getFactorActor(){return factorActor_;}
|
||||
void setFactorDirection(const bool direction){factorDirection = direction;}
|
||||
bool getFactorDirection(){return factorDirection;}
|
||||
uint getPreCancleTime(){return preCancleMin_;}
|
||||
void setPreCancleTime(uint minutes){preCancleMin_ = minutes;}
|
||||
void setFactorActor(std::shared_ptr<Actor> factorActor);
|
||||
std::shared_ptr<Actor> getFactorActor()
|
||||
{
|
||||
return factorActor_;
|
||||
}
|
||||
void setFactorDirection(const bool direction)
|
||||
{
|
||||
factorDirection = direction;
|
||||
}
|
||||
bool getFactorDirection()
|
||||
{
|
||||
return factorDirection;
|
||||
}
|
||||
uint getPreCancleTime()
|
||||
{
|
||||
return preCancleMin_;
|
||||
}
|
||||
void setPreCancleTime(uint minutes)
|
||||
{
|
||||
preCancleMin_ = minutes;
|
||||
}
|
||||
|
||||
virtual ~MultiFactorActor(){}
|
||||
virtual ~MultiFactorActor() {}
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, bool preserve);
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, bool preserve);
|
||||
};
|
||||
|
||||
#endif // REMINDERACTOR_H
|
||||
|
|
|
|||
|
|
@ -12,72 +12,74 @@ PolynomalActor::PolynomalActor(QObject* parent): Actor(parent)
|
|||
|
||||
void PolynomalActor::setSensor(const Sensor sensor)
|
||||
{
|
||||
sensor_ = sensor;
|
||||
sensor_ = sensor;
|
||||
}
|
||||
|
||||
|
||||
void PolynomalActor::setCoeffiancts( const double pow3, const double pow2, const double pow1, const double pow0 )
|
||||
{
|
||||
pow3_=pow3;
|
||||
pow2_=pow2;
|
||||
pow1_=pow1;
|
||||
pow0_=pow0;
|
||||
pow3_=pow3;
|
||||
pow2_=pow2;
|
||||
pow1_=pow1;
|
||||
pow0_=pow0;
|
||||
}
|
||||
void PolynomalActor::getCoeffiancts( double& pow3, double& pow2, double& pow1, double& pow0 )
|
||||
{
|
||||
pow3=pow3_;
|
||||
pow2=pow2_;
|
||||
pow1=pow1_;
|
||||
pow0=pow0_;
|
||||
pow3=pow3_;
|
||||
pow2=pow2_;
|
||||
pow1=pow1_;
|
||||
pow0=pow0_;
|
||||
}
|
||||
|
||||
void PolynomalActor::sensorEvent(Sensor sensor)
|
||||
{
|
||||
if(active && sensor == sensor_)
|
||||
{
|
||||
double result = pow3_*(sensor.field*sensor.field*sensor.field)+pow2_*(sensor.field*sensor.field)+pow1_*sensor.field+pow0_;
|
||||
if(result < 0) result = 0;
|
||||
else if(result > 254) result = 255;
|
||||
if(result != prevValue)sigValue(static_cast<uint8_t>(result));
|
||||
prevValue = result;
|
||||
}
|
||||
if(active && sensor == sensor_)
|
||||
{
|
||||
double result = pow3_*(sensor.field*sensor.field*sensor.field)+pow2_*(sensor.field*sensor.field)+pow1_*sensor.field
|
||||
+pow0_;
|
||||
if(result < 0) result = 0;
|
||||
else if(result > 254) result = 255;
|
||||
if(result != prevValue)sigValue(static_cast<uint8_t>(result));
|
||||
prevValue = result;
|
||||
}
|
||||
}
|
||||
|
||||
void PolynomalActor::store(QJsonObject& json)
|
||||
{
|
||||
json["Type"] = "Polynomal";
|
||||
Actor::store(json);
|
||||
json["Pow3"] = pow3_;
|
||||
json["Pow2"] = pow2_;
|
||||
json["Pow1"] = pow1_;
|
||||
json["Pow0"] = pow0_;
|
||||
json["SensorType"] = static_cast<int>(sensor_.type);
|
||||
json["SensorId"] = static_cast<int>(sensor_.id);
|
||||
json["SensorField"] = sensor_.field;
|
||||
json["SensorName"] = sensor_.name;
|
||||
json["Type"] = "Polynomal";
|
||||
Actor::store(json);
|
||||
json["Pow3"] = pow3_;
|
||||
json["Pow2"] = pow2_;
|
||||
json["Pow1"] = pow1_;
|
||||
json["Pow0"] = pow0_;
|
||||
json["SensorType"] = static_cast<int>(sensor_.type);
|
||||
json["SensorId"] = static_cast<int>(sensor_.id);
|
||||
json["SensorField"] = sensor_.field;
|
||||
json["SensorName"] = sensor_.name;
|
||||
}
|
||||
|
||||
void PolynomalActor::load(const QJsonObject& json, bool preserve)
|
||||
{
|
||||
Actor::load(json, preserve);
|
||||
pow3_ = json["Pow3"].toDouble(0);
|
||||
pow2_ = json["Pow2"].toDouble(0);
|
||||
pow1_ = json["Pow1"].toDouble(1);
|
||||
pow0_ = json["Pow0"].toDouble(0);
|
||||
sensor_.type = json["SensorType"].toInt(0);
|
||||
sensor_.id = json["SensorId"].toInt(0);
|
||||
sensor_.field = json["SensorField"].toInt(0);
|
||||
sensor_.name = json["SensorName"].toString("Sensor");
|
||||
Actor::load(json, preserve);
|
||||
pow3_ = json["Pow3"].toDouble(0);
|
||||
pow2_ = json["Pow2"].toDouble(0);
|
||||
pow1_ = json["Pow1"].toDouble(1);
|
||||
pow0_ = json["Pow0"].toDouble(0);
|
||||
sensor_.type = json["SensorType"].toInt(0);
|
||||
sensor_.id = json["SensorId"].toInt(0);
|
||||
sensor_.field = json["SensorField"].toInt(0);
|
||||
sensor_.name = json["SensorName"].toString("Sensor");
|
||||
}
|
||||
|
||||
QString PolynomalActor::getName() const
|
||||
{
|
||||
if(name_.size() > 0) return name_;
|
||||
else
|
||||
{
|
||||
QString string;
|
||||
string = QString::number(pow3_) + "x^3 + " + QString::number(pow2_) + "x^2 + " + QString::number(pow1_) + "x + " + QString::number(pow0_) + " (x: " + sensor_.name + ")";
|
||||
return string;
|
||||
}
|
||||
if(name_.size() > 0) return name_;
|
||||
else
|
||||
{
|
||||
QString string;
|
||||
string = QString::number(pow3_) + "x^3 + " + QString::number(pow2_) + "x^2 + " + QString::number(
|
||||
pow1_) + "x + " + QString::number(pow0_) + " (x: " + sensor_.name + ")";
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,35 +5,38 @@
|
|||
|
||||
class PolynomalActor: public Actor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
Sensor sensor_;
|
||||
double pow3_ = 0;
|
||||
double pow2_ = 0;
|
||||
double pow1_ = 1;
|
||||
double pow0_ = 0;
|
||||
Sensor sensor_;
|
||||
double pow3_ = 0;
|
||||
double pow2_ = 0;
|
||||
double pow1_ = 1;
|
||||
double pow0_ = 0;
|
||||
|
||||
double prevValue = -1;
|
||||
double prevValue = -1;
|
||||
|
||||
public slots:
|
||||
|
||||
void sensorEvent(Sensor sensor);
|
||||
void sensorEvent(Sensor sensor);
|
||||
|
||||
public:
|
||||
|
||||
void setCoeffiancts( const double pow3, const double pow2, const double pow1, const double pow0 );
|
||||
void getCoeffiancts( double& pow3, double& pow2, double& pow1, double& pow0 );
|
||||
void setCoeffiancts( const double pow3, const double pow2, const double pow1, const double pow0 );
|
||||
void getCoeffiancts( double& pow3, double& pow2, double& pow1, double& pow0 );
|
||||
|
||||
PolynomalActor(const Sensor sensor, QObject* parent = nullptr);
|
||||
PolynomalActor(QObject* parent = nullptr);
|
||||
void setSensor(const Sensor sensor);
|
||||
Sensor getSensor(){return sensor_;}
|
||||
virtual QString getName() const;
|
||||
virtual ~PolynomalActor(){}
|
||||
PolynomalActor(const Sensor sensor, QObject* parent = nullptr);
|
||||
PolynomalActor(QObject* parent = nullptr);
|
||||
void setSensor(const Sensor sensor);
|
||||
Sensor getSensor()
|
||||
{
|
||||
return sensor_;
|
||||
}
|
||||
virtual QString getName() const;
|
||||
virtual ~PolynomalActor() {}
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, bool preserve);
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, bool preserve);
|
||||
};
|
||||
|
||||
#endif // POLYNOMALACTOR_H
|
||||
|
|
|
|||
|
|
@ -14,72 +14,72 @@ Regulator::Regulator(QObject* parent): Actor(parent)
|
|||
|
||||
void Regulator::setSensor(const Sensor sensor)
|
||||
{
|
||||
sensor_ = sensor;
|
||||
sensor_ = sensor;
|
||||
}
|
||||
|
||||
void Regulator::sensorEvent(Sensor sensor)
|
||||
{
|
||||
if(active && sensor == sensor_)
|
||||
{
|
||||
if( sensor.field < setPoint_-band_ && (sensor.field < sensor_.field || sensor_.field > setPoint_-band_ || first) )
|
||||
{
|
||||
sigValue(triggerValue);
|
||||
}
|
||||
else if( sensor.field > setPoint_+band_ && (sensor.field > sensor_.field || sensor_.field < setPoint_+band_ || first) )
|
||||
{
|
||||
sigValue(!triggerValue);
|
||||
}
|
||||
first = false;
|
||||
sensor_ = sensor;
|
||||
}
|
||||
if(active && sensor == sensor_)
|
||||
{
|
||||
if( sensor.field < setPoint_-band_ && (sensor.field < sensor_.field || sensor_.field > setPoint_-band_ || first) )
|
||||
{
|
||||
sigValue(triggerValue);
|
||||
}
|
||||
else if( sensor.field > setPoint_+band_ && (sensor.field > sensor_.field || sensor_.field < setPoint_+band_ || first) )
|
||||
{
|
||||
sigValue(!triggerValue);
|
||||
}
|
||||
first = false;
|
||||
sensor_ = sensor;
|
||||
}
|
||||
}
|
||||
|
||||
void Regulator::setPoint(float setPoint)
|
||||
{
|
||||
setPoint_ = setPoint;
|
||||
setPoint_ = setPoint;
|
||||
}
|
||||
|
||||
void Regulator::setBand ( float band )
|
||||
{
|
||||
band_ = band;
|
||||
band_ = band;
|
||||
}
|
||||
|
||||
void Regulator::setInvert( bool invert )
|
||||
{
|
||||
invert_ = invert;
|
||||
invert_ = invert;
|
||||
}
|
||||
|
||||
void Regulator::store(QJsonObject& json)
|
||||
{
|
||||
json["Type"] = "Regulator";
|
||||
Actor::store(json);
|
||||
json["Band"] = band_;
|
||||
json["SetPoint"] = setPoint_;
|
||||
json["SensorType"] = static_cast<int>(sensor_.type);
|
||||
json["SensorId"] = static_cast<int>(sensor_.id);
|
||||
json["SensorField"] = sensor_.field;
|
||||
json["SensorName"] = sensor_.name;
|
||||
json["Type"] = "Regulator";
|
||||
Actor::store(json);
|
||||
json["Band"] = band_;
|
||||
json["SetPoint"] = setPoint_;
|
||||
json["SensorType"] = static_cast<int>(sensor_.type);
|
||||
json["SensorId"] = static_cast<int>(sensor_.id);
|
||||
json["SensorField"] = sensor_.field;
|
||||
json["SensorName"] = sensor_.name;
|
||||
}
|
||||
|
||||
void Regulator::load(const QJsonObject& json, bool preserve)
|
||||
{
|
||||
Actor::load(json, preserve);
|
||||
band_ = json["Band"].toDouble(1);
|
||||
setPoint_ = json["SetPoint"].toDouble(22);
|
||||
sensor_.type = json["SensorType"].toInt(0);
|
||||
sensor_.id = json["SensorId"].toInt(0);
|
||||
sensor_.field = json["SensorField"].toInt(0);
|
||||
sensor_.name = json["SensorName"].toString("Sensor");
|
||||
Actor::load(json, preserve);
|
||||
band_ = json["Band"].toDouble(1);
|
||||
setPoint_ = json["SetPoint"].toDouble(22);
|
||||
sensor_.type = json["SensorType"].toInt(0);
|
||||
sensor_.id = json["SensorId"].toInt(0);
|
||||
sensor_.field = json["SensorField"].toInt(0);
|
||||
sensor_.name = json["SensorName"].toString("Sensor");
|
||||
}
|
||||
|
||||
QString Regulator::getName() const
|
||||
{
|
||||
if(name_.size() > 0) return name_;
|
||||
else
|
||||
{
|
||||
QString string;
|
||||
string = "Regulate \"" + sensor_.name + "\" to ";
|
||||
string.append(QString::number(setPoint_) + " ");
|
||||
return string;
|
||||
}
|
||||
if(name_.size() > 0) return name_;
|
||||
else
|
||||
{
|
||||
QString string;
|
||||
string = "Regulate \"" + sensor_.name + "\" to ";
|
||||
string.append(QString::number(setPoint_) + " ");
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,35 +4,44 @@
|
|||
|
||||
class Regulator : public Actor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
Sensor sensor_;
|
||||
float setPoint_ = 0;
|
||||
float band_ = 1;
|
||||
bool invert_ = false;
|
||||
Sensor sensor_;
|
||||
float setPoint_ = 0;
|
||||
float band_ = 1;
|
||||
bool invert_ = false;
|
||||
|
||||
bool first = true;
|
||||
bool first = true;
|
||||
|
||||
public slots:
|
||||
|
||||
void sensorEvent(Sensor sensor);
|
||||
void sensorEvent(Sensor sensor);
|
||||
|
||||
void setSensor(const Sensor sensor);
|
||||
void setPoint( float setPoint );
|
||||
void setBand ( float band );
|
||||
void setInvert( bool invert );
|
||||
void setSensor(const Sensor sensor);
|
||||
void setPoint( float setPoint );
|
||||
void setBand ( float band );
|
||||
void setInvert( bool invert );
|
||||
|
||||
public:
|
||||
|
||||
float getBand() {return band_;}
|
||||
float getSetPoint() {return setPoint_;}
|
||||
Regulator(const Sensor sensor, QObject* parent = nullptr);
|
||||
Regulator(QObject* parent = nullptr);
|
||||
Sensor getSensor(){return sensor_;}
|
||||
virtual QString getName() const;
|
||||
virtual ~Regulator(){}
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, bool preserve);
|
||||
float getBand()
|
||||
{
|
||||
return band_;
|
||||
}
|
||||
float getSetPoint()
|
||||
{
|
||||
return setPoint_;
|
||||
}
|
||||
Regulator(const Sensor sensor, QObject* parent = nullptr);
|
||||
Regulator(QObject* parent = nullptr);
|
||||
Sensor getSensor()
|
||||
{
|
||||
return sensor_;
|
||||
}
|
||||
virtual QString getName() const;
|
||||
virtual ~Regulator() {}
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, bool preserve);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,74 +14,76 @@ SensorActor::SensorActor(QObject* parent): Actor(parent)
|
|||
|
||||
void SensorActor::setSensor(const Sensor sensor)
|
||||
{
|
||||
sensor_ = sensor;
|
||||
sensor_ = sensor;
|
||||
}
|
||||
|
||||
void SensorActor::sensorEvent(Sensor sensor)
|
||||
{
|
||||
if(sensor == sensor_)
|
||||
{
|
||||
if((sloap_ == SLOPE_UP || sloap_ == SLOPE_BOTH) && sensor_.field < threshold_ && sensor.field >= threshold_ ) performAction();
|
||||
else if((sloap_ == SLOPE_DOWN || sloap_ == SLOPE_BOTH) && sensor_.field > threshold_ && sensor.field <= threshold_) performAction();
|
||||
sensor_ = sensor;
|
||||
}
|
||||
if(sensor == sensor_)
|
||||
{
|
||||
if((sloap_ == SLOPE_UP || sloap_ == SLOPE_BOTH) && sensor_.field < threshold_
|
||||
&& sensor.field >= threshold_ ) performAction();
|
||||
else if((sloap_ == SLOPE_DOWN || sloap_ == SLOPE_BOTH) && sensor_.field > threshold_
|
||||
&& sensor.field <= threshold_) performAction();
|
||||
sensor_ = sensor;
|
||||
}
|
||||
}
|
||||
|
||||
void SensorActor::setSloap(uint8_t sloap)
|
||||
{
|
||||
sloap_=sloap;
|
||||
sloap_=sloap;
|
||||
}
|
||||
|
||||
void SensorActor::setThreshold(float threshold)
|
||||
{
|
||||
threshold_ = threshold;
|
||||
threshold_ = threshold;
|
||||
}
|
||||
|
||||
float SensorActor::getThreshold()
|
||||
{
|
||||
return threshold_;
|
||||
return threshold_;
|
||||
}
|
||||
uint8_t SensorActor::getSloap()
|
||||
{
|
||||
return sloap_;
|
||||
return sloap_;
|
||||
}
|
||||
|
||||
void SensorActor::store(QJsonObject& json)
|
||||
{
|
||||
json["Type"] = "Sensor";
|
||||
Actor::store(json);
|
||||
json["Sloap"] = sloap_;
|
||||
json["Threshold"] = threshold_;
|
||||
json["SensorType"] = static_cast<int>(sensor_.type);
|
||||
json["SensorId"] = static_cast<int>(sensor_.id);
|
||||
json["SensorField"] = sensor_.field;
|
||||
json["SensorName"] = sensor_.name;
|
||||
json["Type"] = "Sensor";
|
||||
Actor::store(json);
|
||||
json["Sloap"] = sloap_;
|
||||
json["Threshold"] = threshold_;
|
||||
json["SensorType"] = static_cast<int>(sensor_.type);
|
||||
json["SensorId"] = static_cast<int>(sensor_.id);
|
||||
json["SensorField"] = sensor_.field;
|
||||
json["SensorName"] = sensor_.name;
|
||||
}
|
||||
|
||||
void SensorActor::load(const QJsonObject& json, bool preserve)
|
||||
{
|
||||
Actor::load(json, preserve);
|
||||
sloap_ = json["Sloap"].toInt(0);
|
||||
threshold_ = json["Threshold"].toDouble(0);
|
||||
sensor_.type = json["SensorType"].toInt(0);
|
||||
sensor_.id = json["SensorId"].toInt(0);
|
||||
sensor_.field = json["SensorField"].toInt(0);
|
||||
sensor_.name = json["SensorName"].toString("Sensor");
|
||||
Actor::load(json, preserve);
|
||||
sloap_ = json["Sloap"].toInt(0);
|
||||
threshold_ = json["Threshold"].toDouble(0);
|
||||
sensor_.type = json["SensorType"].toInt(0);
|
||||
sensor_.id = json["SensorId"].toInt(0);
|
||||
sensor_.field = json["SensorField"].toInt(0);
|
||||
sensor_.name = json["SensorName"].toString("Sensor");
|
||||
}
|
||||
|
||||
QString SensorActor::getName() const
|
||||
{
|
||||
if(name_.size() > 0) return name_;
|
||||
else
|
||||
{
|
||||
QString string;
|
||||
string = "Sensor \"" + sensor_.name + "\"";
|
||||
if(name_.size() > 0) return name_;
|
||||
else
|
||||
{
|
||||
QString string;
|
||||
string = "Sensor \"" + sensor_.name + "\"";
|
||||
|
||||
if(sloap_ == SLOPE_UP) string.append(" rises to ");
|
||||
else if (sloap_ == SLOPE_DOWN) string.append(" drops to ");
|
||||
else if (sloap_ == SLOPE_BOTH) string.append(" passes ");
|
||||
if(sloap_ == SLOPE_UP) string.append(" rises to ");
|
||||
else if (sloap_ == SLOPE_DOWN) string.append(" drops to ");
|
||||
else if (sloap_ == SLOPE_BOTH) string.append(" passes ");
|
||||
|
||||
string.append(QString::number(threshold_) + " ");
|
||||
return string;
|
||||
}
|
||||
string.append(QString::number(threshold_) + " ");
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,39 +4,42 @@
|
|||
|
||||
class SensorActor : public Actor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
static constexpr uint8_t SLOPE_UP = 0;
|
||||
static constexpr uint8_t SLOPE_DOWN = 1;
|
||||
static constexpr uint8_t SLOPE_BOTH = 2;
|
||||
static constexpr uint8_t SLOPE_UP = 0;
|
||||
static constexpr uint8_t SLOPE_DOWN = 1;
|
||||
static constexpr uint8_t SLOPE_BOTH = 2;
|
||||
|
||||
private:
|
||||
Sensor sensor_;
|
||||
uint8_t sloap_ = SLOPE_UP;
|
||||
float threshold_ = 0;
|
||||
Sensor sensor_;
|
||||
uint8_t sloap_ = SLOPE_UP;
|
||||
float threshold_ = 0;
|
||||
|
||||
public slots:
|
||||
|
||||
void sensorEvent(Sensor sensor);
|
||||
|
||||
void setSloap(uint8_t sloap);
|
||||
void setSensor(const Sensor sensor);
|
||||
void setThreshold( float threshold );
|
||||
void sensorEvent(Sensor sensor);
|
||||
|
||||
void setSloap(uint8_t sloap);
|
||||
void setSensor(const Sensor sensor);
|
||||
void setThreshold( float threshold );
|
||||
|
||||
public:
|
||||
|
||||
SensorActor(const Sensor sensor, QObject* parent = nullptr);
|
||||
SensorActor(QObject* parent = nullptr);
|
||||
Sensor getSensor(){return sensor_;}
|
||||
virtual QString getName() const;
|
||||
virtual ~SensorActor(){}
|
||||
SensorActor(const Sensor sensor, QObject* parent = nullptr);
|
||||
SensorActor(QObject* parent = nullptr);
|
||||
Sensor getSensor()
|
||||
{
|
||||
return sensor_;
|
||||
}
|
||||
virtual QString getName() const;
|
||||
virtual ~SensorActor() {}
|
||||
|
||||
float getThreshold();
|
||||
uint8_t getSloap();
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, bool preserve);
|
||||
float getThreshold();
|
||||
uint8_t getSloap();
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, bool preserve);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,55 +3,55 @@
|
|||
|
||||
TimerActor::TimerActor(const int timeoutSec, QObject *parent): Actor(parent), timeoutMsec_(timeoutSec*1000)
|
||||
{
|
||||
connect(&timer, &QTimer::timeout, this, &TimerActor::timeout);
|
||||
timer.setSingleShot(true);
|
||||
connect(&timer, &QTimer::timeout, this, &TimerActor::timeout);
|
||||
timer.setSingleShot(true);
|
||||
}
|
||||
|
||||
void TimerActor::onValueChanged(uint8_t state)
|
||||
{
|
||||
if((state && !triggerValue) || (!state && triggerValue))
|
||||
{
|
||||
if(timer.isActive()) timer.stop();
|
||||
timer.setInterval(timeoutMsec_);
|
||||
timer.start();
|
||||
}
|
||||
if((state && !triggerValue) || (!state && triggerValue))
|
||||
{
|
||||
if(timer.isActive()) timer.stop();
|
||||
timer.setInterval(timeoutMsec_);
|
||||
timer.start();
|
||||
}
|
||||
}
|
||||
|
||||
void TimerActor::store(QJsonObject& json)
|
||||
{
|
||||
json["Type"] = "Timer";
|
||||
Actor::store(json);
|
||||
json["Timeout"] = timeoutMsec_;
|
||||
json["Type"] = "Timer";
|
||||
Actor::store(json);
|
||||
json["Timeout"] = timeoutMsec_;
|
||||
}
|
||||
|
||||
void TimerActor::load(const QJsonObject& json, bool preserve)
|
||||
{
|
||||
Actor::load(json, preserve);
|
||||
timeoutMsec_ = json["Timeout"].toInt(10000);
|
||||
Actor::load(json, preserve);
|
||||
timeoutMsec_ = json["Timeout"].toInt(10000);
|
||||
}
|
||||
|
||||
void TimerActor::setTimeout(const int timeoutSec)
|
||||
{
|
||||
timeoutMsec_ = timeoutSec*1000;
|
||||
timeoutMsec_ = timeoutSec*1000;
|
||||
}
|
||||
|
||||
int TimerActor::getTimeout()
|
||||
{
|
||||
return timeoutMsec_/1000;
|
||||
return timeoutMsec_/1000;
|
||||
}
|
||||
|
||||
void TimerActor::timeout()
|
||||
{
|
||||
performAction();
|
||||
performAction();
|
||||
}
|
||||
|
||||
QString TimerActor::getName() const
|
||||
{
|
||||
if(name_.size() > 0) return name_;
|
||||
else
|
||||
{
|
||||
QString string;
|
||||
string = "Timeout after " + QString::number(timeoutMsec_/1000) + " seconds. ";
|
||||
return string;
|
||||
}
|
||||
if(name_.size() > 0) return name_;
|
||||
else
|
||||
{
|
||||
QString string;
|
||||
string = "Timeout after " + QString::number(timeoutMsec_/1000) + " seconds. ";
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,27 +4,27 @@
|
|||
|
||||
class TimerActor: public Actor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
private:
|
||||
int timeoutMsec_;
|
||||
int timeoutMsec_;
|
||||
|
||||
QTimer timer;
|
||||
QTimer timer;
|
||||
|
||||
private slots:
|
||||
|
||||
void timeout();
|
||||
void timeout();
|
||||
|
||||
public slots:
|
||||
|
||||
virtual void onValueChanged(uint8_t state);
|
||||
void setTimeout(const int timeoutSec);
|
||||
virtual void onValueChanged(uint8_t state);
|
||||
void setTimeout(const int timeoutSec);
|
||||
|
||||
public:
|
||||
explicit TimerActor(const int timeoutSec = 60, QObject *parent = nullptr);
|
||||
virtual QString getName() const;
|
||||
explicit TimerActor(const int timeoutSec = 60, QObject *parent = nullptr);
|
||||
virtual QString getName() const;
|
||||
|
||||
int getTimeout();
|
||||
int getTimeout();
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, bool preserve);
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, bool preserve);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue