Item Refactor complete
This commit is contained in:
parent
219fbfb4c7
commit
24c168cf64
17 changed files with 78 additions and 41 deletions
|
|
@ -17,17 +17,22 @@ Actor::~Actor()
|
|||
|
||||
}
|
||||
|
||||
void Actor::performAction()
|
||||
void Actor::performValueAction(uint8_t value)
|
||||
{
|
||||
if(active)
|
||||
{
|
||||
ItemUpdateRequest request;
|
||||
request.type = ITEM_UPDATE_ACTOR;
|
||||
request.payload = ItemData(QRandomGenerator::global()->generate(), "Item", triggerValue);
|
||||
request.payload = ItemData(QRandomGenerator::global()->generate(), "Item", value);
|
||||
sigItemUpdate(request);
|
||||
}
|
||||
}
|
||||
|
||||
void Actor::performAction()
|
||||
{
|
||||
performValueAction(triggerValue);
|
||||
}
|
||||
|
||||
void Actor::makeActive()
|
||||
{
|
||||
active = true;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ protected:
|
|||
bool exausted = false;
|
||||
|
||||
void performAction();
|
||||
void performValueAction(uint8_t value);
|
||||
|
||||
virtual void enactValue(uint8_t value) override;
|
||||
|
||||
signals:
|
||||
|
|
|
|||
|
|
@ -6,18 +6,19 @@ MultiFactorActor::MultiFactorActor(Actor* factorActor, const uint preCancleMin,
|
|||
preCancleMin_(preCancleMin)
|
||||
{
|
||||
activationTime.setMSecsSinceEpoch(0);
|
||||
if(factorActor) connect(factorActor, &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
||||
if(factorActor)
|
||||
connect(factorActor, &Actor::sigItemUpdate, this, &MultiFactorActor::factorActorSlot);
|
||||
}
|
||||
|
||||
void MultiFactorActor::factorActorSlot(uint8_t value)
|
||||
void MultiFactorActor::factorActorSlot(ItemUpdateRequest update)
|
||||
{
|
||||
if(value == factorDirection)
|
||||
if(update.payload.getValue() == factorDirection)
|
||||
{
|
||||
activationTime = QDateTime::currentDateTime();
|
||||
}
|
||||
}
|
||||
|
||||
void MultiFactorActor::setValue(uint8_t value)
|
||||
void MultiFactorActor::enactValue(uint8_t value)
|
||||
{
|
||||
if(value)
|
||||
{
|
||||
|
|
@ -46,7 +47,7 @@ QString MultiFactorActor::getName() const
|
|||
void MultiFactorActor::setFactorActor(std::shared_ptr<Actor> factorActor)
|
||||
{
|
||||
factorActor_=factorActor;
|
||||
connect(factorActor_.get(), &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
||||
connect(factorActor_.get(), &Actor::sigItemUpdate, this, &MultiFactorActor::factorActorSlot);
|
||||
}
|
||||
|
||||
void MultiFactorActor::store(QJsonObject &json)
|
||||
|
|
@ -73,7 +74,7 @@ void MultiFactorActor::load(const QJsonObject &json, bool preserve)
|
|||
}
|
||||
if(factorActor_)
|
||||
{
|
||||
connect(factorActor_.get(), &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
||||
connect(factorActor_.get(), &Actor::sigItemUpdate, this, &MultiFactorActor::factorActorSlot);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,17 +16,17 @@ private:
|
|||
|
||||
private slots:
|
||||
|
||||
void factorActorSlot(uint8_t value);
|
||||
void factorActorSlot(ItemUpdateRequest update);
|
||||
|
||||
public slots:
|
||||
|
||||
virtual void setValue(uint8_t value);
|
||||
virtual void enactValue(uint8_t value) override;
|
||||
|
||||
public:
|
||||
|
||||
MultiFactorActor(Actor* FactorActor = nullptr, const uint preCancleMin = 10, QObject *parent = nullptr);
|
||||
|
||||
virtual QString getName() const;
|
||||
virtual QString getName() const override;
|
||||
|
||||
void setFactorActor(std::shared_ptr<Actor> factorActor);
|
||||
std::shared_ptr<Actor> getFactorActor()
|
||||
|
|
@ -52,8 +52,8 @@ public:
|
|||
|
||||
virtual ~MultiFactorActor() {}
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, bool preserve);
|
||||
virtual void store(QJsonObject& json) override;
|
||||
virtual void load(const QJsonObject& json, bool preserve) override;
|
||||
};
|
||||
|
||||
#endif // REMINDERACTOR_H
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ void PolynomalActor::sensorEvent(Sensor sensor)
|
|||
+pow0_;
|
||||
if(result < 0) result = 0;
|
||||
else if(result > 254) result = 255;
|
||||
if(result != prevValue)sigValue(static_cast<uint8_t>(result));
|
||||
if(result != prevValue)
|
||||
performValueAction(static_cast<uint8_t>(result));
|
||||
prevValue = result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,11 +28,11 @@ void Regulator::sensorEvent(Sensor sensor)
|
|||
timer.start(timeout_*1000);
|
||||
if( sensor.field < setPoint_-band_ && (sensor.field < sensor_.field || sensor_.field > setPoint_-band_ || first) )
|
||||
{
|
||||
sigValue(triggerValue);
|
||||
performValueAction(triggerValue);
|
||||
}
|
||||
else if( sensor.field > setPoint_+band_ && (sensor.field > sensor_.field || sensor_.field < setPoint_+band_ || first) )
|
||||
{
|
||||
sigValue(!triggerValue);
|
||||
performValueAction(!triggerValue);
|
||||
}
|
||||
first = false;
|
||||
sensor_ = sensor;
|
||||
|
|
@ -42,15 +42,14 @@ void Regulator::sensorEvent(Sensor sensor)
|
|||
void Regulator::makeInactive()
|
||||
{
|
||||
first = true;
|
||||
if(active)
|
||||
sigValue(!triggerValue);
|
||||
performValueAction(!triggerValue);
|
||||
timer.stop();
|
||||
Actor::makeInactive();
|
||||
}
|
||||
|
||||
void Regulator::timeout()
|
||||
{
|
||||
sigValue(safeValue_);
|
||||
performValueAction(safeValue_);
|
||||
}
|
||||
|
||||
void Regulator::setPoint(float setPoint)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue