Compare commits
2 commits
58ba22b267
...
8e33897d29
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e33897d29 | |||
| 8db0ac7290 |
5 changed files with 131 additions and 48 deletions
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
SensorActor::SensorActor(const Sensor sensor, QObject* parent): Actor(parent), sensor_(sensor)
|
||||
{
|
||||
|
||||
connect(&timer_, &QTimer::timeout, this, &SensorActor::delayTimeout);
|
||||
}
|
||||
|
||||
SensorActor::SensorActor(QObject* parent): Actor(parent)
|
||||
{
|
||||
|
||||
connect(&timer_, &QTimer::timeout, this, &SensorActor::delayTimeout);
|
||||
}
|
||||
|
||||
void SensorActor::setSensor(const Sensor sensor)
|
||||
|
|
@ -17,14 +17,25 @@ void SensorActor::setSensor(const Sensor sensor)
|
|||
sensor_ = sensor;
|
||||
}
|
||||
|
||||
void SensorActor::delayTimeout()
|
||||
{
|
||||
performAction();
|
||||
}
|
||||
|
||||
void SensorActor::sensorEvent(Sensor sensor, sensor_update_type_t type)
|
||||
{
|
||||
if(sensor == sensor_)
|
||||
{
|
||||
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_
|
||||
&& sensor.field <= threshold_) performAction();
|
||||
&& sensor.field <= threshold_)
|
||||
{
|
||||
timer_.start(delayMs_);
|
||||
}
|
||||
sensor_ = sensor;
|
||||
}
|
||||
}
|
||||
|
|
@ -39,21 +50,33 @@ void SensorActor::setThreshold(float threshold)
|
|||
threshold_ = threshold;
|
||||
}
|
||||
|
||||
void SensorActor::setDelayMs(int ms)
|
||||
{
|
||||
delayMs_ = ms;
|
||||
}
|
||||
|
||||
float SensorActor::getThreshold()
|
||||
{
|
||||
return threshold_;
|
||||
}
|
||||
|
||||
uint8_t SensorActor::getSloap()
|
||||
{
|
||||
return sloap_;
|
||||
}
|
||||
|
||||
int SensorActor::getDelayMs()
|
||||
{
|
||||
return delayMs_;
|
||||
}
|
||||
|
||||
void SensorActor::store(QJsonObject& json)
|
||||
{
|
||||
json["Type"] = "Sensor";
|
||||
Actor::store(json);
|
||||
json["Sloap"] = sloap_;
|
||||
json["Threshold"] = threshold_;
|
||||
json["Delay"] = delayMs_;
|
||||
json["SensorType"] = static_cast<int>(sensor_.type);
|
||||
json["SensorId"] = static_cast<int>(sensor_.id);
|
||||
json["SensorField"] = sensor_.field;
|
||||
|
|
@ -65,6 +88,7 @@ void SensorActor::load(const QJsonObject& json, bool preserve)
|
|||
Actor::load(json, preserve);
|
||||
sloap_ = json["Sloap"].toInt(0);
|
||||
threshold_ = json["Threshold"].toDouble(0);
|
||||
delayMs_ = json["Delay"].toInt(0);
|
||||
sensor_.type = static_cast<Sensor::sensor_type_t>(json["SensorType"].toInt(0));
|
||||
sensor_.id = json["SensorId"].toInt(0);
|
||||
sensor_.field = json["SensorField"].toInt(0);
|
||||
|
|
@ -84,6 +108,9 @@ QString SensorActor::getName() const
|
|||
else if (sloap_ == SLOPE_BOTH) string.append(" passes ");
|
||||
|
||||
string.append(QString::number(threshold_) + " ");
|
||||
|
||||
if(delayMs_ > 0) string.append("(+" + QString::number(delayMs_) + "ms) ");
|
||||
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include "actor.h"
|
||||
#include "sensors/sensor.h"
|
||||
#include <QTimer>
|
||||
|
||||
class SensorActor : public Actor
|
||||
{
|
||||
|
|
@ -15,6 +16,11 @@ private:
|
|||
Sensor sensor_;
|
||||
uint8_t sloap_ = SLOPE_UP;
|
||||
float threshold_ = 0;
|
||||
int delayMs_ = 0;
|
||||
QTimer timer_;
|
||||
|
||||
private slots:
|
||||
void delayTimeout();
|
||||
|
||||
public slots:
|
||||
|
||||
|
|
@ -22,7 +28,9 @@ public slots:
|
|||
|
||||
void setSloap(uint8_t sloap);
|
||||
void setSensor(const Sensor sensor);
|
||||
void setThreshold( float threshold );
|
||||
void setThreshold(float threshold);
|
||||
void setDelayMs(int ms);
|
||||
int getDelayMs();
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
|||
|
|
@ -26,9 +26,12 @@ SensorActorWidget::SensorActorWidget(std::shared_ptr<SensorActor> sensorActor, S
|
|||
|
||||
ui->doubleSpinBox_threshold->setValue(sensorActor_->getThreshold());
|
||||
|
||||
ui->spinBox_delay->setValue(sensorActor_->getDelayMs());
|
||||
|
||||
connect(ui->listView, &SensorListWidget::clicked, this, &SensorActorWidget::setSensor);
|
||||
connect(ui->doubleSpinBox_threshold, SIGNAL(valueChanged(double)), this, SLOT(setThreshold(double)));
|
||||
connect(ui->comboBox_slope, SIGNAL(currentIndexChanged(int)), this, SLOT(setSlope(int)));
|
||||
connect(ui->spinBox_delay, SIGNAL(valueChanged(int)), this, SLOT(setDelay(int)));
|
||||
}
|
||||
|
||||
SensorActorWidget::~SensorActorWidget()
|
||||
|
|
@ -52,3 +55,8 @@ void SensorActorWidget::setSensor(const QModelIndex &index)
|
|||
{
|
||||
sensorActor_->setSensor(ui->listView->getSensorForIndex(index));
|
||||
}
|
||||
|
||||
void SensorActorWidget::setDelay(int ms)
|
||||
{
|
||||
sensorActor_->setDelayMs(ms);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ private slots:
|
|||
void setThreshold(double in);
|
||||
void setSlope(int index);
|
||||
void setSensor(const QModelIndex &index);
|
||||
void setDelay(int ms);
|
||||
|
||||
private:
|
||||
Ui::SensorActorWidget *ui;
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@
|
|||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item row="1" column="0" colspan="4">
|
||||
<widget class="SensorListWidget" name="listView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
|
|
@ -37,16 +37,27 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Threshold</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item row="2" column="1">
|
||||
<spacer name="horizontalSpacer_threshold">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QComboBox" name="comboBox_slope">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
|
|
@ -71,7 +82,7 @@
|
|||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QDoubleSpinBox" name="doubleSpinBox_threshold">
|
||||
<property name="minimum">
|
||||
<double>-9999.989999999999782</double>
|
||||
|
|
@ -81,7 +92,35 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_delay">
|
||||
<property name="text">
|
||||
<string>Delay</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<spacer name="horizontalSpacer_delay">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="3">
|
||||
<widget class="QSpinBox" name="spinBox_delay">
|
||||
<property name="suffix">
|
||||
<string> ms</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>9999999</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
|
@ -89,7 +128,7 @@
|
|||
<customwidget>
|
||||
<class>SensorListWidget</class>
|
||||
<extends>QListView</extends>
|
||||
<header location="local">ui/sensorlistwidget.h</header>
|
||||
<header>ui/sensorlistwidget.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue