Compare commits
No commits in common. "8e33897d29c39fb0ba60f17c663df418fe02d77c" and "58ba22b26780d99417e24e73589570bb81eed430" have entirely different histories.
8e33897d29
...
58ba22b267
5 changed files with 48 additions and 131 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,25 +17,14 @@ 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_ )
|
&& sensor.field >= threshold_ ) performAction();
|
||||||
{
|
|
||||||
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_)
|
&& sensor.field <= threshold_) performAction();
|
||||||
{
|
|
||||||
timer_.start(delayMs_);
|
|
||||||
}
|
|
||||||
sensor_ = sensor;
|
sensor_ = sensor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -50,33 +39,21 @@ 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;
|
||||||
|
|
@ -88,7 +65,6 @@ 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);
|
||||||
|
|
@ -108,9 +84,6 @@ QString SensorActor::getName() const
|
||||||
else if (sloap_ == SLOPE_BOTH) string.append(" passes ");
|
else if (sloap_ == SLOPE_BOTH) string.append(" passes ");
|
||||||
|
|
||||||
string.append(QString::number(threshold_) + " ");
|
string.append(QString::number(threshold_) + " ");
|
||||||
|
|
||||||
if(delayMs_ > 0) string.append("(+" + QString::number(delayMs_) + "ms) ");
|
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
#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
|
||||||
{
|
{
|
||||||
|
|
@ -16,11 +15,6 @@ 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:
|
||||||
|
|
||||||
|
|
@ -29,8 +23,6 @@ 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:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,9 @@ SensorActorWidget::SensorActorWidget(std::shared_ptr<SensorActor> sensorActor, S
|
||||||
|
|
||||||
ui->doubleSpinBox_threshold->setValue(sensorActor_->getThreshold());
|
ui->doubleSpinBox_threshold->setValue(sensorActor_->getThreshold());
|
||||||
|
|
||||||
ui->spinBox_delay->setValue(sensorActor_->getDelayMs());
|
|
||||||
|
|
||||||
connect(ui->listView, &SensorListWidget::clicked, this, &SensorActorWidget::setSensor);
|
connect(ui->listView, &SensorListWidget::clicked, this, &SensorActorWidget::setSensor);
|
||||||
connect(ui->doubleSpinBox_threshold, SIGNAL(valueChanged(double)), this, SLOT(setThreshold(double)));
|
connect(ui->doubleSpinBox_threshold, SIGNAL(valueChanged(double)), this, SLOT(setThreshold(double)));
|
||||||
connect(ui->comboBox_slope, SIGNAL(currentIndexChanged(int)), this, SLOT(setSlope(int)));
|
connect(ui->comboBox_slope, SIGNAL(currentIndexChanged(int)), this, SLOT(setSlope(int)));
|
||||||
connect(ui->spinBox_delay, SIGNAL(valueChanged(int)), this, SLOT(setDelay(int)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SensorActorWidget::~SensorActorWidget()
|
SensorActorWidget::~SensorActorWidget()
|
||||||
|
|
@ -55,8 +52,3 @@ void SensorActorWidget::setSensor(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
sensorActor_->setSensor(ui->listView->getSensorForIndex(index));
|
sensorActor_->setSensor(ui->listView->getSensorForIndex(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SensorActorWidget::setDelay(int ms)
|
|
||||||
{
|
|
||||||
sensorActor_->setDelayMs(ms);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ private slots:
|
||||||
void setThreshold(double in);
|
void setThreshold(double in);
|
||||||
void setSlope(int index);
|
void setSlope(int index);
|
||||||
void setSensor(const QModelIndex &index);
|
void setSensor(const QModelIndex &index);
|
||||||
void setDelay(int ms);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::SensorActorWidget *ui;
|
Ui::SensorActorWidget *ui;
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item row="0" column="0" colspan="2">
|
<item>
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0" colspan="4">
|
<item>
|
||||||
<widget class="SensorListWidget" name="listView">
|
<widget class="SensorListWidget" name="listView">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
|
@ -37,27 +37,16 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="label_3">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Threshold</string>
|
<string>Threshold</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item>
|
||||||
<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">
|
<widget class="QComboBox" name="comboBox_slope">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
|
@ -82,7 +71,7 @@
|
||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="3">
|
<item>
|
||||||
<widget class="QDoubleSpinBox" name="doubleSpinBox_threshold">
|
<widget class="QDoubleSpinBox" name="doubleSpinBox_threshold">
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<double>-9999.989999999999782</double>
|
<double>-9999.989999999999782</double>
|
||||||
|
|
@ -92,35 +81,7 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
</layout>
|
||||||
<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>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
@ -128,7 +89,7 @@
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>SensorListWidget</class>
|
<class>SensorListWidget</class>
|
||||||
<extends>QListView</extends>
|
<extends>QListView</extends>
|
||||||
<header>ui/sensorlistwidget.h</header>
|
<header location="local">ui/sensorlistwidget.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue