Commit a8d31d64 authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Allow set/get value in points and percents in AIN and AOUT

Fix #45
parent 31b2db39
......@@ -36,6 +36,21 @@ void AbstractAnalogIO::onComponentCompleted (void) {
AbstractIO::onComponentCompleted ();
}
int AbstractAnalogIO::getValueInPoints (void) {
return MathUtils::convert (get_valRaw (), get_minRaw (), get_maxRaw (), 0, get_resolutionInPoints () -1);
}
int AbstractAnalogIO::getValueInPercents (void) {
return MathUtils::convert (get_valRaw (), get_minRaw (), get_maxRaw (), 0, 100);
}
void AbstractAnalogIO::setValueInPoints (const int points) {
set_valRaw (MathUtils::convert (points, 0, get_resolutionInPoints () -1, get_minRaw (), get_maxRaw ()));
}
void AbstractAnalogIO::setValueInPercents (const int percents) {
set_valRaw (MathUtils::convert (percents, 0, 100, get_minRaw (), get_maxRaw ()));
}
AbstractDigitalIO::AbstractDigitalIO (const ObjectDirection::Type direction, QObject * parent)
: AbstractIO (ObjectType::DIGITAL, direction, parent)
, m_value (false)
......@@ -65,14 +80,6 @@ void AnalogInput::onComponentCompleted (void) {
Manager::instance ().intializeObject (this);
}
int AnalogInput::getValueInPoints (void) {
return MathUtils::convert (get_valRaw (), get_minRaw (), get_maxRaw (), 0, get_resolutionInPoints () -1);
}
int AnalogInput::getValueInPercents (void) {
return MathUtils::convert (get_valRaw (), get_minRaw (), get_maxRaw (), 0, 100);
}
AnalogOutput::AnalogOutput (QObject * parent)
: AbstractAnalogIO (ObjectDirection::OUTPUT, parent)
{
......@@ -87,14 +94,6 @@ void AnalogOutput::onComponentCompleted (void) {
Manager::instance ().intializeObject (this);
}
void AnalogOutput::setValueInPoints (const int points) {
set_valRaw (MathUtils::convert (points, 0, get_resolutionInPoints () -1, get_minRaw (), get_maxRaw ()));
}
void AnalogOutput::setValueInPercents (const int percents) {
set_valRaw (MathUtils::convert (percents, 0, 100, get_minRaw (), get_maxRaw ()));
}
DigitalInput::DigitalInput (QObject * parent)
: AbstractDigitalIO (ObjectDirection::INPUT, parent)
{
......
......@@ -36,6 +36,12 @@ public:
QJsonObject exportState (void) const Q_DECL_FINAL;
void onComponentCompleted (void) Q_DECL_OVERRIDE;
Q_INVOKABLE int getValueInPoints (void);
Q_INVOKABLE int getValueInPercents (void);
Q_INVOKABLE void setValueInPoints (const int points);
Q_INVOKABLE void setValueInPercents (const int percents);
};
class AbstractDigitalIO : public AbstractIO {
......@@ -58,9 +64,6 @@ public:
virtual ~AnalogInput (void);
void onComponentCompleted (void) Q_DECL_FINAL;
Q_INVOKABLE int getValueInPoints (void);
Q_INVOKABLE int getValueInPercents (void);
};
class AnalogOutput : public AbstractAnalogIO {
......@@ -71,9 +74,6 @@ public:
virtual ~AnalogOutput (void);
void onComponentCompleted (void) Q_DECL_FINAL;
Q_INVOKABLE void setValueInPoints (const int points);
Q_INVOKABLE void setValueInPercents (const int percents);
};
class DigitalInput : public AbstractDigitalIO {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment