Commit 68e10c37 authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Better handling of physical value -> digital input

Create a whole new kind of sensor, HybridSensor

Handle objects init, chains validation and sync

Enhance delegate handling for the 3 types of sensors
parent 250bffc6
......@@ -134,6 +134,8 @@ Project {
"components/ClickableTextLabel.qml",
"components/DelegateAnalogActuator.qml",
"components/DelegateAnalogSensor.qml",
"components/DelegateAnalogSensorMini.qml",
"components/DelegateAnalogSensorWide.qml",
"components/DelegateArgumentDetailsHelp.qml",
"components/DelegateArgumentHelp.qml",
"components/DelegateCanBus.qml",
......@@ -143,7 +145,10 @@ Project {
"components/DelegateControlDout.qml",
"components/DelegateDigitalActuator.qml",
"components/DelegateDigitalSensor.qml",
"components/DelegateDigitalSensorMini.qml",
"components/DelegateEnumHelp.qml",
"components/DelegateHybridSensor.qml",
"components/DelegateHybridSensorMini.qml",
"components/DelegateLinkObjectHelp.qml",
"components/DelegateLinkSource.qml",
"components/DelegateLinkTarget.qml",
......@@ -172,6 +177,7 @@ Project {
"components/DialogImportSnapshot.qml",
"components/DialogOpenNetworkDefinition.qml",
"components/DialogPrintDatasheet.qml",
"components/InstanceCreator.qml",
"components/SymbolPlug.qml",
"components/WindowCodeEditor.qml",
"import/QtCAN/CanTestBench.2/CircleButton.qml",
......
......@@ -48,6 +48,7 @@ QML_ENUM_CLASS (ObjectType,
UNKNOWN_TYPE,
ANALOG,
DIGITAL,
HYBRID,
NB_TYPES)
QML_ENUM_CLASS (ObjectDirection,
......
......@@ -399,19 +399,19 @@ void LinkDigitalOutputToDigitalInput::syncReverse (void) {
m_output->set_value (m_input->get_value ());
}
LinkPhysicalStateToDigitalSensor::LinkPhysicalStateToDigitalSensor (QObject * parent)
LinkPhysicalValueToHybridSensor::LinkPhysicalValueToHybridSensor (QObject * parent)
: AbstractLink (parent)
, m_state (Q_NULLPTR)
, m_value (Q_NULLPTR)
, m_sensor (Q_NULLPTR)
{
Manager::instance ().registerObject (this);
}
LinkPhysicalStateToDigitalSensor::~LinkPhysicalStateToDigitalSensor (void) {
LinkPhysicalValueToHybridSensor::~LinkPhysicalValueToHybridSensor (void) {
Manager::instance ().unregisterObject (this);
}
void LinkPhysicalStateToDigitalSensor::onComponentCompleted (void) {
void LinkPhysicalValueToHybridSensor::onComponentCompleted (void) {
AbstractLink::onComponentCompleted ();
if (get_title ().isEmpty ()) {
set_title ("Watch");
......@@ -419,19 +419,56 @@ void LinkPhysicalStateToDigitalSensor::onComponentCompleted (void) {
Manager::instance ().intializeObject (this);
}
void LinkPhysicalStateToDigitalSensor::initHandler (void) {
update_state (get_source () ? get_source ()->as<PhysicalState> () : Q_NULLPTR);
update_sensor (get_target () ? get_target ()->as<DigitalSensor> () : Q_NULLPTR);
void LinkPhysicalValueToHybridSensor::initHandler (void) {
update_value (get_source () ? get_source ()->as<PhysicalValue> () : Q_NULLPTR);
update_sensor (get_target () ? get_target ()->as<HybridSensor> () : Q_NULLPTR);
}
void LinkPhysicalValueToHybridSensor::ensureValid (void) {
update_valid (m_value && m_sensor);
}
void LinkPhysicalValueToHybridSensor::syncNormal (void) {
m_sensor->set_valPhy (transformNormal (MathUtils::floatToInt (m_value->get_val (), m_sensor->get_decimals ())));
}
void LinkPhysicalValueToHybridSensor::syncReverse (void) {
m_value->set_val (transformReverse (MathUtils::intToFloat (m_sensor->get_valPhy (), m_sensor->get_decimals ())));
}
LinkHybridSensorToDigitalInput::LinkHybridSensorToDigitalInput (QObject * parent)
: AbstractLink (parent)
, m_sensor (Q_NULLPTR)
, m_input (Q_NULLPTR)
{
Manager::instance ().registerObject (this);
}
LinkHybridSensorToDigitalInput::~LinkHybridSensorToDigitalInput (void) {
Manager::instance ().unregisterObject (this);
}
void LinkHybridSensorToDigitalInput::onComponentCompleted (void) {
AbstractLink::onComponentCompleted ();
if (get_title ().isEmpty ()) {
set_title ("Set");
}
Manager::instance ().intializeObject (this);
}
void LinkHybridSensorToDigitalInput::initHandler (void) {
update_sensor (get_source () ? get_source ()->as<HybridSensor> () : Q_NULLPTR);
update_input (get_target () ? get_target ()->as<DigitalInput> () : Q_NULLPTR);
}
void LinkPhysicalStateToDigitalSensor::ensureValid (void) {
update_valid (m_state && m_sensor);
void LinkHybridSensorToDigitalInput::ensureValid (void) {
update_valid (m_sensor && m_input);
}
void LinkPhysicalStateToDigitalSensor::syncNormal (void) {
m_sensor->set_value (m_state->get_state ());
void LinkHybridSensorToDigitalInput::syncNormal (void) {
m_input->set_value (m_sensor->get_valState ());
}
void LinkPhysicalStateToDigitalSensor::syncReverse (void) {
m_state->update_state (m_sensor->get_value ());
void LinkHybridSensorToDigitalInput::syncReverse () {
m_sensor->update_valState (m_input->get_value ());
}
......@@ -16,8 +16,8 @@ class DigitalInput;
class DigitalOutput;
class DigitalSensor;
class DigitalActuator;
class HybridSensor;
class PhysicalValue;
class PhysicalState;
class AbstractLink : public BasicObject {
Q_OBJECT
......@@ -198,14 +198,31 @@ public:
void syncReverse (void) Q_DECL_FINAL;
};
class LinkPhysicalStateToDigitalSensor : public AbstractLink {
class LinkPhysicalValueToHybridSensor : public AbstractLink {
Q_OBJECT
QML_READONLY_PTR_PROPERTY (PhysicalState, state)
QML_READONLY_PTR_PROPERTY (DigitalSensor, sensor)
QML_READONLY_PTR_PROPERTY (PhysicalValue, value)
QML_READONLY_PTR_PROPERTY (HybridSensor, sensor)
public:
explicit LinkPhysicalValueToHybridSensor (QObject * parent = Q_NULLPTR);
virtual ~LinkPhysicalValueToHybridSensor (void);
void onComponentCompleted (void) Q_DECL_FINAL;
void initHandler (void) Q_DECL_FINAL;
void ensureValid (void) Q_DECL_FINAL;
void syncNormal (void) Q_DECL_FINAL;
void syncReverse (void) Q_DECL_FINAL;
};
class LinkHybridSensorToDigitalInput : public AbstractLink {
Q_OBJECT
QML_READONLY_PTR_PROPERTY (HybridSensor, sensor)
QML_READONLY_PTR_PROPERTY (DigitalInput, input)
public:
explicit LinkPhysicalStateToDigitalSensor (QObject * parent = Q_NULLPTR);
virtual ~LinkPhysicalStateToDigitalSensor (void);
explicit LinkHybridSensorToDigitalInput (QObject * parent = Q_NULLPTR);
virtual ~LinkHybridSensorToDigitalInput (void);
void onComponentCompleted (void) Q_DECL_FINAL;
......
......@@ -81,13 +81,15 @@ Manager::Manager (void)
, m_linksPhysicalValueToAnalogSensor (50)
, m_linksAnalogOutputToAnalogInput (50)
, m_linksDigitalOutputToDigitalInput (50)
, m_linksPhysicalStateToDigitalSensor (50)
, m_linksPhysicalValueToHybridSensor (50)
, m_linksHybridSensorToDigitalInput (50)
, m_transformers (100)
, m_affineTransformers (50)
, m_customTransformers (20)
, m_sensors (50)
, m_analogSensors (30)
, m_digitalSensors (30)
, m_hybridSensors (30)
, m_actuators (50)
, m_analogActuators (30)
, m_digitalActuators (30)
......@@ -103,7 +105,6 @@ Manager::Manager (void)
, m_physicalValues (500)
, m_physicalBlocks (10)
, m_physicalMarkers (20)
, m_physicalStates (20)
, m_canOpens (20)
, m_canBuses (5)
, m_serialBuses (5)
......@@ -285,13 +286,13 @@ void Manager::deinit (void) {
m_sensors.clear ();
m_analogSensors.clear ();
m_digitalSensors.clear ();
m_hybridSensors.clear ();
m_actuators.clear ();
m_analogActuators.clear ();
m_digitalActuators.clear ();
m_physicalValues.clear ();
m_physicalBlocks.clear ();
m_physicalMarkers.clear ();
m_physicalStates.clear ();
m_routines.clear ();
m_routinesOnTimer.clear ();
m_routinesOnEvent.clear ();
......@@ -310,7 +311,8 @@ void Manager::deinit (void) {
m_linksPhysicalValueToAnalogSensor.clear ();
m_linksAnalogOutputToAnalogInput.clear ();
m_linksDigitalOutputToDigitalInput.clear ();
m_linksPhysicalStateToDigitalSensor.clear ();
m_linksHybridSensorToDigitalInput.clear ();
m_linksPhysicalValueToHybridSensor.clear ();
m_transformers.clear ();
m_affineTransformers.clear ();
m_customTransformers.clear ();
......@@ -665,7 +667,10 @@ void Manager::onTick (void) {
const int time = int (m_chrono.elapsed ());
m_chrono.restart ();
for (LinkPhysicalValueToAnalogSensor * link : arrayRange (m_linksPhysicalValueToAnalogSensor)) {
link->sync (); // PHYSICAL VALUE -> SENSOR
link->sync (); // PHYSICAL VALUE -> ANALOG SENSOR
}
for (LinkPhysicalValueToHybridSensor * link : arrayRange (m_linksPhysicalValueToHybridSensor)) {
link->sync (); // PHYSICAL VALUE -> HYBRID SENSOR
}
for (LinkAnalogSensorToAnalogInput * link : arrayRange (m_linksAnalogSensorToAnalogInput)) {
link->sync (); // SENSOR -> AIN
......@@ -694,12 +699,6 @@ void Manager::onTick (void) {
for (PhysicalValue * value : arrayRange (m_physicalValues)) {
value->move (time); // move value after running actuators
}
for (PhysicalState * state : arrayRange (m_physicalStates)) {
state->refreshState (); // recompute states after updating physical values
}
for (LinkPhysicalStateToDigitalSensor * link : arrayRange (m_linksPhysicalStateToDigitalSensor)) {
link->sync (); // PHYSICAL STATE -> SENSOR
}
if (m_physicalWorld) {
m_physicalWorld->processPhysics ();
}
......@@ -786,6 +785,9 @@ void Manager::doInitObjects (void) {
else if (DigitalSensor * digitalSensor = sensor->as<DigitalSensor> ()) {
m_digitalSensors.add (digitalSensor);
}
else if (HybridSensor * hybridSensor = sensor->as<HybridSensor> ()) {
m_hybridSensors.add (hybridSensor);
}
else { }
usePath = true;
}
......@@ -865,8 +867,11 @@ void Manager::doInitObjects (void) {
else if (LinkDigitalOutputToDigitalInput * sublink = link->as<LinkDigitalOutputToDigitalInput> ()) {
m_linksDigitalOutputToDigitalInput.add (sublink);
}
else if (LinkPhysicalStateToDigitalSensor * sublink = link->as<LinkPhysicalStateToDigitalSensor> ()) {
m_linksPhysicalStateToDigitalSensor.add (sublink);
else if (LinkPhysicalValueToHybridSensor * sublink = link->as<LinkPhysicalValueToHybridSensor> ()) {
m_linksPhysicalValueToHybridSensor.add (sublink);
}
else if (LinkHybridSensorToDigitalInput * sublink = link->as<LinkHybridSensorToDigitalInput> ()) {
m_linksHybridSensorToDigitalInput.add (sublink);
}
else { }
}
......@@ -909,11 +914,6 @@ void Manager::doInitObjects (void) {
block->refreshVertexList ();
usePath = true;
}
else if (PhysicalState * state = basicObject->as<PhysicalState> ()) {
dump ("STATE", state);
m_physicalStates.add (state);
usePath = true;
}
else if (PhysicalMarker * marker = basicObject->as<PhysicalMarker> ()) {
dump ("MARKER", marker);
m_physicalMarkers.add (marker);
......@@ -979,11 +979,13 @@ void Manager::doBuildChains (void) {
/// prepare sets for mode/conflict detection
QList<AnalogSensorChain *> analogSensorChains;
QList<DigitalSensorChain *> digitalSensorChains;
QList<HybridSensorChain *> hybridSensorChains;
QList<AnalogActuatorChain *> analogActuatorChains;
QList<DigitalActuatorChain *> digitalActuatorChains;
QSet<Node *> activeNodes, passiveNodes, inactiveNodes;
QSet<AnalogSensor *> invertedAnalogSensors;
QSet<DigitalSensor *> invertedDigitalSensors;
QSet<HybridSensor *> disabledHybridSensors;
QSet<PhysicalValue *> forcedPhysicalValues;
QSet<LinkAnalogSensorToAnalogInput *> invertedLinkSensorToAins;
QSet<LinkDigitalSensorToDigitalInput *> invertedLinkSensorToDins;
......@@ -1025,6 +1027,31 @@ void Manager::doBuildChains (void) {
digitalSensorChains.append (chain);
}
}
for (HybridSensor * sensor : arrayRange (m_hybridSensors)) {
LinkPhysicalValueToHybridSensor * linkValueToSensor = sensor->get_sourceLink ();
PhysicalValue * value = (linkValueToSensor ? linkValueToSensor->get_value () : Q_NULLPTR);
bool fullChain = false;
for (LinkHybridSensorToDigitalInput * linkSensorToDin : arrayRange (sensor->get_targetLinks ().items ())) {
DigitalInput * din = (linkSensorToDin ? linkSensorToDin->get_input () : Q_NULLPTR);
HybridSensorChain * chain = new HybridSensorChain;
chain->sensor = sensor;
chain->linkValueToSensor = linkValueToSensor;
chain->value = value;
chain->linkSensorToDin = linkSensorToDin;
chain->din = din;
hybridSensorChains.append (chain);
if (din) {
fullChain = true;
}
}
if (!fullChain) {
HybridSensorChain * chain = new HybridSensorChain;
chain->sensor = sensor;
chain->linkValueToSensor = linkValueToSensor;
chain->value = value;
hybridSensorChains.append (chain);
}
}
for (AnalogActuator * actuator : arrayRange (m_analogActuators)) {
LinkAnalogOutputToAnalogActuator * linkAoutToActuator = actuator->get_sourceLink ();
AnalogOutput * aout = (linkAoutToActuator ? linkAoutToActuator->get_output () : Q_NULLPTR);
......@@ -1171,6 +1198,26 @@ void Manager::doBuildChains (void) {
invertedLinkSensorToDins.insert (chain->linkSensorToDin);
}
}
/// disable links between passive node inputs and hybrid sensors because they are not reversable
for (HybridSensorChain * chain : arrayRange (hybridSensorChains)) {
bool enabled = true;
if (chain->din) {
if (Node * node = nodeForIO.value (chain->din)) {
enabled = (!inactiveNodes.contains (node) &&
!passiveNodes.contains (node));
}
}
if (chain->linkSensorToDin) {
chain->linkSensorToDin->update_enabled (enabled);
}
if (chain->linkValueToSensor) {
chain->linkValueToSensor->update_enabled (enabled);
}
if (chain->sensor) {
chain->sensor->update_disabled (!enabled);
disabledHybridSensors.insert (chain->sensor);
}
}
/// disable links between forced physical values and actuators to avoid conflicts between relative speed and forced absolute value
for (AnalogActuatorChain * chain : arrayRange (analogActuatorChains)) {
bool conflict = false;
......@@ -1234,12 +1281,10 @@ void Manager::doBuildChains (void) {
link->update_enabled (enabled);
link->update_reversed (reversed);
}
for (LinkPhysicalStateToDigitalSensor * link : arrayRange (m_linksPhysicalStateToDigitalSensor)) {
link->update_enabled (true);
}
/// clear old chains
qDeleteAll (analogSensorChains);
qDeleteAll (digitalSensorChains);
qDeleteAll (hybridSensorChains);
qDeleteAll (analogActuatorChains);
qDeleteAll (digitalActuatorChains);
}
......
......@@ -52,6 +52,7 @@ class DigitalOutput;
class AbstractSensor;
class AnalogSensor;
class DigitalSensor;
class HybridSensor;
class AbstractActuator;
class AnalogActuator;
......@@ -66,13 +67,13 @@ class LinkDigitalSensorToDigitalInput;
class LinkPhysicalValueToAnalogSensor;
class LinkAnalogOutputToAnalogInput;
class LinkDigitalOutputToDigitalInput;
class LinkPhysicalStateToDigitalSensor;
class LinkPhysicalValueToHybridSensor;
class LinkHybridSensorToDigitalInput;
class PhysicalWorld;
class PhysicalValue;
class PhysicalBlock;
class PhysicalMarker;
class PhysicalState;
class AbstractTransformer;
class AffineTransformer;
......@@ -97,6 +98,14 @@ struct DigitalSensorChain : public AbstractSensorChain {
DigitalInput * din = Q_NULLPTR;
};
struct HybridSensorChain : public AbstractSensorChain {
PhysicalValue * value = Q_NULLPTR;
LinkPhysicalValueToHybridSensor * linkValueToSensor = Q_NULLPTR;
HybridSensor * sensor = Q_NULLPTR;
LinkHybridSensorToDigitalInput * linkSensorToDin = Q_NULLPTR;
DigitalInput * din = Q_NULLPTR;
};
struct AnalogActuatorChain : public AbstractActuatorChain {
AnalogOutput * aout = Q_NULLPTR;
LinkAnalogOutputToAnalogActuator * linkAoutToActuator = Q_NULLPTR;
......@@ -198,7 +207,8 @@ protected:
Collection<LinkPhysicalValueToAnalogSensor> m_linksPhysicalValueToAnalogSensor;
Collection<LinkAnalogOutputToAnalogInput> m_linksAnalogOutputToAnalogInput;
Collection<LinkDigitalOutputToDigitalInput> m_linksDigitalOutputToDigitalInput;
Collection<LinkPhysicalStateToDigitalSensor> m_linksPhysicalStateToDigitalSensor;
Collection<LinkPhysicalValueToHybridSensor> m_linksPhysicalValueToHybridSensor;
Collection<LinkHybridSensorToDigitalInput> m_linksHybridSensorToDigitalInput;
Collection<AbstractTransformer> m_transformers;
Collection<AffineTransformer> m_affineTransformers;
......@@ -207,6 +217,7 @@ protected:
Collection<AbstractSensor> m_sensors;
Collection<AnalogSensor> m_analogSensors;
Collection<DigitalSensor> m_digitalSensors;
Collection<HybridSensor> m_hybridSensors;
Collection<AbstractActuator> m_actuators;
Collection<AnalogActuator> m_analogActuators;
......@@ -225,7 +236,6 @@ protected:
Collection<PhysicalValue> m_physicalValues;
Collection<PhysicalBlock> m_physicalBlocks;
Collection<PhysicalMarker> m_physicalMarkers;
Collection<PhysicalState> m_physicalStates;
Collection<CanOpen> m_canOpens;
Collection<CanBus> m_canBuses;
......
......@@ -466,37 +466,6 @@ QJsonObject PhysicalBlock::exportState (void) const {
};
}
PhysicalState::PhysicalState (QObject * parent)
: BasicObject (ObjectFamily::STATE, parent)
, m_lowThreshold (0.0f)
, m_highThreshold (1.0f)
, m_inverted (false)
, m_state (false)
{
Manager::instance ().registerObject (this);
}
PhysicalState::~PhysicalState (void) {
Manager::instance ().unregisterObject (this);
}
void PhysicalState::onComponentCompleted (void) {
BasicObject::onComponentCompleted ();
Manager::instance ().intializeObject (this);
}
void PhysicalState::refreshState (void) {
if (m_referenceValue) {
if (m_referenceValue->get_val () >= m_highThreshold) {
update_state (m_inverted ? false : true);
}
else if (m_referenceValue->get_val () <= m_lowThreshold) {
update_state (m_inverted ? true : false);
}
else { }
}
}
PhysicalWorld::PhysicalWorld (QObject * parent)
: BasicObject (ObjectFamily::WORLD, parent)
, m_subObjects (this)
......
......@@ -230,23 +230,6 @@ public:
void refreshAncestors (void);
};
class PhysicalState : public BasicObject {
Q_OBJECT
QML_WRITABLE_PTR_PROPERTY (PhysicalValue, referenceValue)
QML_WRITABLE_VAR_PROPERTY (float, lowThreshold)
QML_WRITABLE_VAR_PROPERTY (float, highThreshold)
QML_WRITABLE_VAR_PROPERTY (bool, inverted)
QML_READONLY_VAR_PROPERTY (bool, state)
public:
explicit PhysicalState (QObject * parent = Q_NULLPTR);
virtual ~PhysicalState (void);
void onComponentCompleted (void) Q_DECL_FINAL;
void refreshState (void);
};
class PhysicalWorld : public BasicObject {
Q_OBJECT
Q_INTERFACES (QQmlParserStatus)
......
......@@ -12,6 +12,7 @@ AbstractSensor::AbstractSensor (const ObjectType::Type type, QObject * parent)
, m_type (type)
, m_isAnalog (type == ObjectType::ANALOG)
, m_isDigital (type == ObjectType::DIGITAL)
, m_isHybrid (type == ObjectType::HYBRID)
{ }
AbstractSensor::~AbstractSensor (void) { }
......@@ -115,7 +116,6 @@ DigitalSensor::DigitalSensor (QObject * parent)
, m_value (false)
, m_trueLabel ("ON")
, m_falseLabel ("OFF")
, m_sourceLink (Q_NULLPTR)
, m_targetLinks (this)
{
Manager::instance ().registerObject (this);
......@@ -132,16 +132,58 @@ QJsonObject DigitalSensor::exportState (void) const {
}
void DigitalSensor::onComponentCompleted (void) {
AbstractSensor::onComponentCompleted ();
for (LinkDigitalSensorToDigitalInput * link : m_targetLinks) {
link->set_source (this);
}
Manager::instance ().intializeObject (this);
}
HybridSensor::HybridSensor (QObject * parent)
: AbstractSensor (ObjectType::HYBRID, parent)
, m_disabled (false)
, m_valPhy (0)
, m_lowThresholdPhy (0)
, m_highThresholdPhy (1)
, m_invertState (false)
, m_valState (false)
, m_decimals (0)
, m_unit ("")
, m_sourceLink (Q_NULLPTR)
, m_targetLinks (this)
{
connect (this, &HybridSensor::valPhyChanged, this, &HybridSensor::refreshValState);
connect (this, &HybridSensor::lowThresholdPhyChanged, this, &HybridSensor::refreshValState);
connect (this, &HybridSensor::highThresholdPhyChanged, this, &HybridSensor::refreshValState);
connect (this, &HybridSensor::invertStateChanged, this, &HybridSensor::refreshValState);
Manager::instance ().registerObject (this);
}
HybridSensor::~HybridSensor (void) {
Manager::instance ().unregisterObject (this);
}
void HybridSensor::onComponentCompleted (void) {
AbstractSensor::onComponentCompleted ();
if (m_sourceLink) {
m_sourceLink->set_target (this);
}
for (LinkDigitalSensorToDigitalInput * link : m_targetLinks) {
for (LinkHybridSensorToDigitalInput * link : m_targetLinks) {
link->set_source (this);
}
Manager::instance ().intializeObject (this);
}
void HybridSensor::refreshValState (void) {
if (m_valPhy >= m_highThresholdPhy) {
update_valState (m_invertState ? false : true);
}
else if (m_valPhy <= m_lowThresholdPhy) {
update_valState (m_invertState ? true : false);
}
else { }
}
SensorsList::SensorsList (QObject * parent)
: QObject (parent)
, m_subObjects (this)
......
......@@ -11,13 +11,15 @@ class PhysicalValue;
class LinkAnalogSensorToAnalogInput;
class LinkDigitalSensorToDigitalInput;
class LinkPhysicalValueToAnalogSensor;
class LinkPhysicalStateToDigitalSensor;
class LinkPhysicalValueToHybridSensor;
class LinkHybridSensorToDigitalInput;
class AbstractSensor : public BasicObject {
Q_OBJECT
QML_CONSTANT_VAR_PROPERTY (ObjectType::Type, type)
QML_CONSTANT_VAR_PROPERTY (bool, isAnalog)
QML_CONSTANT_VAR_PROPERTY (bool, isDigital)
QML_CONSTANT_VAR_PROPERTY (bool, isHybrid)
QML_WRITABLE_CSTREF_PROPERTY (QString, description)
public:
......@@ -73,8 +75,6 @@ class DigitalSensor : public AbstractSensor {
QML_WRITABLE_VAR_PROPERTY (bool, value)
QML_WRITABLE_CSTREF_PROPERTY (QString, trueLabel)
QML_WRITABLE_CSTREF_PROPERTY (QString, falseLabel)
// source link
QML_WRITABLE_PTR_PROPERTY (LinkPhysicalStateToDigitalSensor, sourceLink)
// target links
QML_LIST_PROPERTY (LinkDigitalSensorToDigitalInput, targetLinks)
......@@ -87,6 +87,34 @@ public:
QJsonObject exportState (void) const Q_DECL_FINAL;
};
class HybridSensor : public AbstractSensor {
Q_OBJECT
// mode
QML_READONLY_VAR_PROPERTY (bool, disabled)
// physical values
QML_WRITABLE_VAR_PROPERTY (int, valPhy)
QML_WRITABLE_VAR_PROPERTY (int, lowThresholdPhy)
QML_WRITABLE_VAR_PROPERTY (int, highThresholdPhy)
// digital state
QML_WRITABLE_VAR_PROPERTY (bool, invertState)
QML_READONLY_VAR_PROPERTY (bool, valState)
// display format
QML_WRITABLE_VAR_PROPERTY (int, decimals)
QML_WRITABLE_CSTREF_PROPERTY (QString, unit)
// source link
QML_WRITABLE_PTR_PROPERTY (LinkPhysicalValueToHybridSensor, sourceLink)
// target links
QML_LIST_PROPERTY (LinkHybridSensorToDigitalInput, targetLinks)
public:
explicit HybridSensor (QObject * parent = Q_NULLPTR);
virtual ~HybridSensor (void);
void onComponentCompleted (void) Q_DECL_FINAL;
void refreshValState (void);
};
class SensorsList : public QObject, public QQmlParserStatus {
Q_OBJECT
Q_INTERFACES (QQmlParserStatus)
......
......@@ -161,6 +161,7 @@ void SharedObject::registerQmlTypes (QQmlEngine * qmlEngine) {
qmlRegisterType<DigitalInput> (uri, maj, min, "DigitalInput");
qmlRegisterType<DigitalOutput> (uri, maj, min, "DigitalOutput");
qmlRegisterType<DigitalSensor> (uri, maj, min, "DigitalSensor");
qmlRegisterType<HybridSensor> (uri, maj, min, "HybridSensor");
qmlRegisterType<LinkAnalogActuatorToPhysicalValue> (uri, maj, min, "LinkAnalogActuatorToPhysicalValue");
qmlRegisterType<LinkAnalogOutputToAnalogActuator> (uri, maj, min, "LinkAnalogOutputToAnalogActuator");
qmlRegisterType<LinkAnalogSensorToAnalogInput> (uri, maj, min, "LinkAnalogSensorToAnalogInput");
......@@ -169,7 +170,8 @@ void SharedObject::registerQmlTypes (QQmlEngine * qmlEngine) {
qmlRegisterType<LinkPhysicalValueToAnalogSensor> (uri, maj, min, "LinkPhysicalValueToAnalogSensor");
qmlRegisterType<LinkAnalogOutputToAnalogInput> (uri, maj, min, "LinkAnalogOutputToAnalogInput");
qmlRegisterType<LinkDigitalOutputToDigitalInput> (uri, maj, min, "LinkDigitalOutputToDigitalInput");
qmlRegisterType<LinkPhysicalStateToDigitalSensor> (uri, maj, min, "LinkPhysicalStateToDigitalSensor");
qmlRegisterType<LinkPhysicalValueToHybridSensor> (uri, maj, min, "LinkPhysicalValueToHybridSensor");
qmlRegisterType<LinkHybridSensorToDigitalInput> (uri, maj, min, "LinkHybridSensorToDigitalInput");
qmlRegisterType<CanBus> (uri, maj, min, "CanBus");
qmlRegisterType<CanOpen> (uri, maj, min, "CanOpen");
qmlRegisterType<NetworkDefinition> (uri, maj, min, "NetworkDefinition");
......@@ -181,7 +183,6 @@ void SharedObject::registerQmlTypes (QQmlEngine * qmlEngine) {
qmlRegisterType<PhysicalBlock> (uri, maj, min, "PhysicalBlock");
qmlRegisterType<PhysicalValue> (uri, maj, min, "PhysicalValue");
qmlRegisterType<PhysicalMarker> (uri, maj, min, "PhysicalMarker");
qmlRegisterType<PhysicalState> (uri, maj, min, "PhysicalState");
qmlRegisterType<PhysicalWorld> (uri, maj, min, "PhysicalWorld");
qmlRegisterType<RoutineOnCanFrame> (uri, maj, min, "RoutineOnCanFrame");
qmlRegisterType<RoutineOnSerialFrame> (uri, maj, min, "RoutineOnSerialFrame");
......
......@@ -7,4 +7,11 @@ StretchColumnContainer {
enabled: (sensor !== null);
property var sensor;
function intToFloat (value, decimals) {
return (value / Math.pow (10, decimals));
}
function floatToInt (value, decimals) {
return (value * Math.pow (10, decimals));
}
}
......@@ -9,13 +9,6 @@ AbstractDelegateSensor {
property alias sensor : base.analogSensor;
function intToFloat (value, decimals) {
return (value / Math.pow (10, decimals));
}
function floatToInt (value, decimals) {
return (value * Math.pow (10, decimals));
}
StretchRowContainer {
spacing: Style.spacingNormal;
ExtraAnchors.horizontalFill: parent;
......
import QtQuick 2.1;
import QtQmlTricks.UiElements 2.0;
import QtCAN.CanTestBench 2.0;