31 QString operation = Operation.toUpper();
76 m_referenceDeviceId(),
77 m_referenceDevice(nullptr),
78 m_inputDevice(nullptr),
80 m_triggerDevice(nullptr),
82 m_firstRunningValue(
true),
87 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Unrecognised control operation '%1' for device '%2'").arg(Type,
uniqueId));
95 if (Details.contains(QStringLiteral(
"references")))
97 QVariantMap reference = Details.value(QStringLiteral(
"references")).toMap();
98 if (reference.contains(QStringLiteral(
"device")))
100 m_referenceDeviceId = reference.value(QStringLiteral(
"device")).toString().trimmed();
109 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Control '%1' has no reference device for operation").arg(
uniqueId));
117 if (Details.contains(QStringLiteral(
"triggers")))
119 QVariantMap triggers = Details.value(QStringLiteral(
"triggers")).toMap();
120 if (triggers.contains(QStringLiteral(
"device")))
122 m_triggerDeviceId = triggers.value(QStringLiteral(
"device")).toString().trimmed();
130 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Control '%1' has no trigger device for updating").arg(
uniqueId));
136 m_runningValue = std::numeric_limits<double>::max();
140 m_runningValue = std::numeric_limits<double>::min();
157 QString reference(QStringLiteral(
"Unknown"));
162 if (reference.isEmpty())
169 result.append(tr(
"Equal to '%1'").arg(reference));
172 result.append(tr(
"Less than '%1'").arg(reference));
175 result.append(tr(
"Less than or equal to '%1'").arg(reference));
178 result.append(tr(
"Greater than '%1'").arg(reference));
181 result.append(tr(
"Greater than or equal to '%1'").arg(reference));
184 result.append(tr(
"Any"));
187 result.append(tr(
"All"));
190 result.append(tr(
"None"));
193 result.append(tr(
"Average"));
196 result.append(tr(
"Toggle"));
199 result.append(tr(
"Invert"));
202 result.append(tr(
"Passthrough"));
205 result.append(tr(
"Maximum"));
208 result.append(tr(
"Minimum"));
211 result.append(tr(
"Multiply"));
214 result.append(tr(
"Running average"));
217 result.append(tr(
"Running max"));
220 result.append(tr(
"Running min"));
223 result.append(tr(
"Unknown"));
232 QMutexLocker locker(&
lock);
234 bool passthrough =
false;
238 if (qobject_cast<TorcInput*>(
m_inputs.firstKey()))
242 QMap<QObject*,QString>::const_iterator it =
m_outputs.constBegin();
243 for ( ; it !=
m_outputs.constEnd(); ++it)
244 passthrough &= (
bool)qobject_cast<
TorcOutput*>(it.key());
253 QMutexLocker locker(&
lock);
266 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Device '%1' needs at least one output").arg(
uniqueId));
282 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"%1 has %2 inputs for operation '%3' (needs at least 2) - ignoring.")
294 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"%1 has %2 inputs for operation '%3' (must have 1) - ignoring.")
311 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"%1 has %2 inputs for operation '%3' (must have 1 input and 1 reference) - ignoring.")
322 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"%1 has %2 inputs for operation '%3' (must have 1 input, 1 reference and 1 trigger) - ignoring.")
335 m_referenceDevice =
gDeviceList->value(m_referenceDeviceId);
336 if (!m_referenceDevice)
340 m_triggerDevice =
gDeviceList->value(m_triggerDeviceId);
341 if (!m_triggerDevice)
343 QList<QObject*> inputs =
m_inputs.uniqueKeys();
344 foreach(QObject *device, inputs)
346 if (device != m_referenceDevice && device != m_triggerDevice)
348 m_inputDevice = device;
368 void TorcLogicControl::CalculateOutput(
void)
370 QMutexLocker locker(&
lock);
372 double newvalue =
value;
374 double referencevalue = 0.0;
375 double inputvalue = 0.0;
376 double triggervalue = 0.0;
381 if (
IsComplexType(m_operation) && m_inputDevice && m_referenceDevice)
400 newvalue = m_average.
AddValue(inputvalue);
407 if (referencevalue || m_firstRunningValue || (inputvalue > m_runningValue))
409 m_runningValue = newvalue = inputvalue;
410 m_firstRunningValue =
false;
414 if (referencevalue || m_firstRunningValue || (inputvalue < m_runningValue))
416 m_runningValue = newvalue = inputvalue;
417 m_firstRunningValue =
false;
435 newvalue = qFuzzyCompare(inputvalue + 1.0, referencevalue + 1.0) ? 1 : 0;
439 newvalue = inputvalue < referencevalue ? 1 : 0;
444 newvalue = inputvalue <= referencevalue ? 1 : 0;
448 newvalue = inputvalue > referencevalue ? 1 : 0;
452 newvalue = inputvalue >= referencevalue ? 1 : 0;
459 on &= !qFuzzyCompare(next + 1.0, 1.0);
460 newvalue = on ? 1 : 0;
469 on |= !qFuzzyCompare(next + 1.0, 1.0);
471 newvalue = on ? 1 : 0;
473 newvalue = on ? 0 : 1;
490 newvalue =
value >= 1.0 ? 0.0 : 1.0;
495 newvalue =
m_inputValues.constBegin().value() < 1.0 ? 1.0 : 0.0;
bool IsPassthrough(void) override
Only certain logic controls can be passthrough.
QString GetUserName(void)
virtual bool Validate(void)
TorcLogicControl(const QString &Type, const QVariantMap &Details)
QMap< QObject *, QString > m_inputs
QMap< QObject *, double > m_inputValues
QMap< QObject *, double > m_lastInputValues
bool Validate(void) override
static QHash< QString, TorcDevice * > * gDeviceList
void SetValue(double Value) override
static TorcLogicControl::Operation StringToOperation(const QString &Operation)
bool Finish(void)
Finish setup of the control.
#define LOG(_MASK_, _LEVEL_, _STRING_)
QStringList GetDescription(void) override
bool IsComplexType(TorcLogicControl::Operation Type)
QMap< QObject *, QString > m_outputs
TorcControl::Type GetType(void) const override
QString GetUniqueId(void)