Add optional delay to sensor actor
This commit is contained in:
parent
58ba22b267
commit
8db0ac7290
2 changed files with 37 additions and 5 deletions
|
|
@ -4,12 +4,12 @@
|
||||||
|
|
||||||
SensorActor::SensorActor(const Sensor sensor, QObject* parent): Actor(parent), sensor_(sensor)
|
SensorActor::SensorActor(const Sensor sensor, QObject* parent): Actor(parent), sensor_(sensor)
|
||||||
{
|
{
|
||||||
|
connect(&timer_, &QTimer::timeout, this, &SensorActor::delayTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
SensorActor::SensorActor(QObject* parent): Actor(parent)
|
SensorActor::SensorActor(QObject* parent): Actor(parent)
|
||||||
{
|
{
|
||||||
|
connect(&timer_, &QTimer::timeout, this, &SensorActor::delayTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SensorActor::setSensor(const Sensor sensor)
|
void SensorActor::setSensor(const Sensor sensor)
|
||||||
|
|
@ -17,14 +17,25 @@ void SensorActor::setSensor(const Sensor sensor)
|
||||||
sensor_ = sensor;
|
sensor_ = sensor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SensorActor::delayTimeout()
|
||||||
|
{
|
||||||
|
performAction();
|
||||||
|
}
|
||||||
|
|
||||||
void SensorActor::sensorEvent(Sensor sensor, sensor_update_type_t type)
|
void SensorActor::sensorEvent(Sensor sensor, sensor_update_type_t type)
|
||||||
{
|
{
|
||||||
if(sensor == sensor_)
|
if(sensor == sensor_)
|
||||||
{
|
{
|
||||||
if((sloap_ == SLOPE_UP || sloap_ == SLOPE_BOTH) && sensor_.field < threshold_
|
if((sloap_ == SLOPE_UP || sloap_ == SLOPE_BOTH) && sensor_.field < threshold_
|
||||||
&& sensor.field >= threshold_ ) performAction();
|
&& sensor.field >= threshold_ )
|
||||||
|
{
|
||||||
|
timer_.start(delayMs_);
|
||||||
|
}
|
||||||
else if((sloap_ == SLOPE_DOWN || sloap_ == SLOPE_BOTH) && sensor_.field > threshold_
|
else if((sloap_ == SLOPE_DOWN || sloap_ == SLOPE_BOTH) && sensor_.field > threshold_
|
||||||
&& sensor.field <= threshold_) performAction();
|
&& sensor.field <= threshold_)
|
||||||
|
{
|
||||||
|
timer_.start(delayMs_);
|
||||||
|
}
|
||||||
sensor_ = sensor;
|
sensor_ = sensor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -39,21 +50,33 @@ void SensorActor::setThreshold(float threshold)
|
||||||
threshold_ = threshold;
|
threshold_ = threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SensorActor::setDelayMs(int ms)
|
||||||
|
{
|
||||||
|
delayMs_ = ms;
|
||||||
|
}
|
||||||
|
|
||||||
float SensorActor::getThreshold()
|
float SensorActor::getThreshold()
|
||||||
{
|
{
|
||||||
return threshold_;
|
return threshold_;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t SensorActor::getSloap()
|
uint8_t SensorActor::getSloap()
|
||||||
{
|
{
|
||||||
return sloap_;
|
return sloap_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SensorActor::getDelayMs()
|
||||||
|
{
|
||||||
|
return delayMs_;
|
||||||
|
}
|
||||||
|
|
||||||
void SensorActor::store(QJsonObject& json)
|
void SensorActor::store(QJsonObject& json)
|
||||||
{
|
{
|
||||||
json["Type"] = "Sensor";
|
json["Type"] = "Sensor";
|
||||||
Actor::store(json);
|
Actor::store(json);
|
||||||
json["Sloap"] = sloap_;
|
json["Sloap"] = sloap_;
|
||||||
json["Threshold"] = threshold_;
|
json["Threshold"] = threshold_;
|
||||||
|
json["Delay"] = delayMs_;
|
||||||
json["SensorType"] = static_cast<int>(sensor_.type);
|
json["SensorType"] = static_cast<int>(sensor_.type);
|
||||||
json["SensorId"] = static_cast<int>(sensor_.id);
|
json["SensorId"] = static_cast<int>(sensor_.id);
|
||||||
json["SensorField"] = sensor_.field;
|
json["SensorField"] = sensor_.field;
|
||||||
|
|
@ -65,6 +88,7 @@ void SensorActor::load(const QJsonObject& json, bool preserve)
|
||||||
Actor::load(json, preserve);
|
Actor::load(json, preserve);
|
||||||
sloap_ = json["Sloap"].toInt(0);
|
sloap_ = json["Sloap"].toInt(0);
|
||||||
threshold_ = json["Threshold"].toDouble(0);
|
threshold_ = json["Threshold"].toDouble(0);
|
||||||
|
delayMs_ = json["Delay"].toInt(0);
|
||||||
sensor_.type = static_cast<Sensor::sensor_type_t>(json["SensorType"].toInt(0));
|
sensor_.type = static_cast<Sensor::sensor_type_t>(json["SensorType"].toInt(0));
|
||||||
sensor_.id = json["SensorId"].toInt(0);
|
sensor_.id = json["SensorId"].toInt(0);
|
||||||
sensor_.field = json["SensorField"].toInt(0);
|
sensor_.field = json["SensorField"].toInt(0);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
#include "sensors/sensor.h"
|
#include "sensors/sensor.h"
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
class SensorActor : public Actor
|
class SensorActor : public Actor
|
||||||
{
|
{
|
||||||
|
|
@ -15,6 +16,11 @@ private:
|
||||||
Sensor sensor_;
|
Sensor sensor_;
|
||||||
uint8_t sloap_ = SLOPE_UP;
|
uint8_t sloap_ = SLOPE_UP;
|
||||||
float threshold_ = 0;
|
float threshold_ = 0;
|
||||||
|
int delayMs_ = 0;
|
||||||
|
QTimer timer_;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void delayTimeout();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
|
@ -22,7 +28,9 @@ public slots:
|
||||||
|
|
||||||
void setSloap(uint8_t sloap);
|
void setSloap(uint8_t sloap);
|
||||||
void setSensor(const Sensor sensor);
|
void setSensor(const Sensor sensor);
|
||||||
void setThreshold( float threshold );
|
void setThreshold(float threshold);
|
||||||
|
void setDelayMs(int ms);
|
||||||
|
int getDelayMs();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue