Add the ability to enable and disable actors from the ui

add safe and timeout to the regulator actor
This commit is contained in:
uvos 2024-12-03 00:24:35 +01:00
parent d8471789b7
commit 271330d5fd
7 changed files with 176 additions and 20 deletions

View file

@ -4,12 +4,16 @@
Regulator::Regulator(const Sensor sensor, QObject* parent): Actor(parent), sensor_(sensor)
{
timer.setSingleShot(true);
timer.start(timeout_*1000);
connect(&timer, &QTimer::timeout, this, &Regulator::timeout);
}
Regulator::Regulator(QObject* parent): Actor(parent)
{
timer.setSingleShot(true);
timer.start(timeout_*1000);
connect(&timer, &QTimer::timeout, this, &Regulator::timeout);
}
void Regulator::setSensor(const Sensor sensor)
@ -21,6 +25,7 @@ void Regulator::sensorEvent(Sensor sensor)
{
if(active && sensor == sensor_)
{
timer.start(timeout_*1000);
if( sensor.field < setPoint_-band_ && (sensor.field < sensor_.field || sensor_.field > setPoint_-band_ || first) )
{
sigValue(triggerValue);
@ -39,9 +44,15 @@ void Regulator::makeInactive()
first = true;
if(active)
sigValue(!triggerValue);
timer.stop();
Actor::makeInactive();
}
void Regulator::timeout()
{
sigValue(safeValue_);
}
void Regulator::setPoint(float setPoint)
{
setPoint_ = setPoint;
@ -57,12 +68,25 @@ void Regulator::setInvert( bool invert )
invert_ = invert;
}
void Regulator::setSafeValue(int value)
{
safeValue_ = value;
}
void Regulator::setTimeout(int value)
{
timeout_ = value;
timer.start(timeout_*1000);
}
void Regulator::store(QJsonObject& json)
{
json["Type"] = "Regulator";
Actor::store(json);
json["Band"] = band_;
json["SetPoint"] = setPoint_;
json["SafeValue"] = safeValue_;
json["Timeout"] = timeout_;
json["SensorType"] = static_cast<int>(sensor_.type);
json["SensorId"] = static_cast<int>(sensor_.id);
json["SensorField"] = sensor_.field;
@ -74,15 +98,21 @@ void Regulator::load(const QJsonObject& json, bool preserve)
Actor::load(json, preserve);
band_ = json["Band"].toDouble(1);
setPoint_ = json["SetPoint"].toDouble(22);
safeValue_ = json["SafeValue"].toDouble(0);
timeout_ = json["Timeout"].toDouble(1800);
sensor_.type = json["SensorType"].toInt(0);
sensor_.id = json["SensorId"].toInt(0);
sensor_.field = json["SensorField"].toInt(0);
sensor_.name = json["SensorName"].toString("Sensor");
timer.start(timeout_*1000);
}
QString Regulator::getName() const
{
if(name_.size() > 0) return name_;
if(name_.size() > 0)
{
return name_;
}
else
{
QString string;