mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
implement origin for effects (#408)
* implement rigin for efx * implement origin for effects and other components add experimental adalight firmware for arduino with upto 5 pwm channels * cleanup * origin ip now with dns lookup * fix compile * move some code
This commit is contained in:
@@ -66,7 +66,7 @@ void Effect::registerHyperionExtensionModule()
|
||||
PyImport_AppendInittab("hyperion", &PyInit_hyperion);
|
||||
}
|
||||
|
||||
Effect::Effect(PyThreadState * mainThreadState, int priority, int timeout, const QString & script, const QString & name, const QJsonObject & args)
|
||||
Effect::Effect(PyThreadState * mainThreadState, int priority, int timeout, const QString & script, const QString & name, const QJsonObject & args, const QString & origin)
|
||||
: QThread()
|
||||
, _mainThreadState(mainThreadState)
|
||||
, _priority(priority)
|
||||
@@ -79,6 +79,7 @@ Effect::Effect(PyThreadState * mainThreadState, int priority, int timeout, const
|
||||
, _abortRequested(false)
|
||||
, _imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor())
|
||||
, _colors()
|
||||
, _origin(origin)
|
||||
{
|
||||
_colors.resize(_imageProcessor->getLedCount(), ColorRgb::BLACK);
|
||||
|
||||
@@ -146,7 +147,7 @@ void Effect::run()
|
||||
}
|
||||
else
|
||||
{
|
||||
Error(Logger::getInstance("EFFECTENGINE"), "Unable to open script file %s", _script.toUtf8().constData());
|
||||
Error(Logger::getInstance("EFFECTENGINE"), "Unable to open script file %s.", QSTRING_CSTR(_script));
|
||||
}
|
||||
file.close();
|
||||
|
||||
@@ -265,7 +266,7 @@ PyObject* Effect::wrapSetColor(PyObject *self, PyObject *args)
|
||||
if (PyArg_ParseTuple(args, "bbb", &color.red, &color.green, &color.blue))
|
||||
{
|
||||
std::fill(effect->_colors.begin(), effect->_colors.end(), color);
|
||||
effect->setColors(effect->_priority, effect->_colors, timeout, false, hyperion::COMP_EFFECT);
|
||||
effect->setColors(effect->_priority, effect->_colors, timeout, false, hyperion::COMP_EFFECT, effect->_origin);
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
else
|
||||
@@ -286,7 +287,7 @@ PyObject* Effect::wrapSetColor(PyObject *self, PyObject *args)
|
||||
{
|
||||
char * data = PyByteArray_AS_STRING(bytearray);
|
||||
memcpy(effect->_colors.data(), data, length);
|
||||
effect->setColors(effect->_priority, effect->_colors, timeout, false, hyperion::COMP_EFFECT);
|
||||
effect->setColors(effect->_priority, effect->_colors, timeout, false, hyperion::COMP_EFFECT, effect->_origin);
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
else
|
||||
@@ -356,7 +357,7 @@ PyObject* Effect::wrapSetImage(PyObject *self, PyObject *args)
|
||||
memcpy(image.memptr(), data, length);
|
||||
|
||||
effect->_imageProcessor->process(image, effect->_colors);
|
||||
effect->setColors(effect->_priority, effect->_colors, timeout, false, hyperion::COMP_EFFECT);
|
||||
effect->setColors(effect->_priority, effect->_colors, timeout, false, hyperion::COMP_EFFECT, effect->_origin);
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
else
|
||||
@@ -432,7 +433,7 @@ PyObject* Effect::wrapImageShow(PyObject *self, PyObject *args)
|
||||
|
||||
memcpy(image.memptr(), binaryImage.data(), binaryImage.size());
|
||||
effect->_imageProcessor->process(image, effect->_colors);
|
||||
effect->setColors(effect->_priority, effect->_colors, timeout, false, hyperion::COMP_EFFECT);
|
||||
effect->setColors(effect->_priority, effect->_colors, timeout, false, hyperion::COMP_EFFECT, effect->_origin);
|
||||
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ class Effect : public QThread
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Effect(PyThreadState * mainThreadState, int priority, int timeout, const QString & script, const QString & name, const QJsonObject & args = QJsonObject());
|
||||
Effect(PyThreadState * mainThreadState, int priority, int timeout, const QString & script, const QString & name, const QJsonObject & args = QJsonObject(), const QString & origin="System");
|
||||
virtual ~Effect();
|
||||
|
||||
virtual void run();
|
||||
@@ -43,7 +43,7 @@ public slots:
|
||||
signals:
|
||||
void effectFinished(Effect * effect);
|
||||
|
||||
void setColors(int priority, const std::vector<ColorRgb> &ledColors, const int timeout_ms, bool clearEffects, hyperion::Components component);
|
||||
void setColors(int priority, const std::vector<ColorRgb> &ledColors, const int timeout_ms, bool clearEffects, hyperion::Components componentconst, QString origin);
|
||||
|
||||
private slots:
|
||||
void effectFinished();
|
||||
@@ -102,5 +102,6 @@ private:
|
||||
|
||||
QImage * _image;
|
||||
QPainter * _painter;
|
||||
QString _origin;
|
||||
};
|
||||
|
||||
|
@@ -342,11 +342,16 @@ void EffectEngine::readEffects()
|
||||
}
|
||||
}
|
||||
|
||||
int EffectEngine::runEffect(const QString &effectName, const QJsonObject &args, int priority, int timeout, QString pythonScript)
|
||||
int EffectEngine::runEffect(const QString &effectName, int priority, int timeout, const QString &origin)
|
||||
{
|
||||
return runEffect(effectName, QJsonObject(), priority, timeout, "", origin);
|
||||
}
|
||||
|
||||
int EffectEngine::runEffect(const QString &effectName, const QJsonObject &args, int priority, int timeout, const QString &pythonScript, const QString &origin)
|
||||
{
|
||||
Info( _log, "run effect %s on channel %d", effectName.toUtf8().constData(), priority);
|
||||
|
||||
if (pythonScript == "")
|
||||
if (pythonScript.isEmpty())
|
||||
{
|
||||
const EffectDefinition * effectDefinition = nullptr;
|
||||
for (const EffectDefinition & e : _availableEffects)
|
||||
@@ -364,24 +369,24 @@ int EffectEngine::runEffect(const QString &effectName, const QJsonObject &args,
|
||||
return -1;
|
||||
}
|
||||
|
||||
return runEffectScript(effectDefinition->script, effectName, args.isEmpty() ? effectDefinition->args : args, priority, timeout);
|
||||
} else
|
||||
return runEffectScript(pythonScript, effectName, args, priority, timeout);
|
||||
return runEffectScript(effectDefinition->script, effectName, (args.isEmpty() ? effectDefinition->args : args), priority, timeout, origin);
|
||||
}
|
||||
return runEffectScript(pythonScript, effectName, args, priority, timeout, origin);
|
||||
}
|
||||
|
||||
int EffectEngine::runEffectScript(const QString &script, const QString &name, const QJsonObject &args, int priority, int timeout)
|
||||
int EffectEngine::runEffectScript(const QString &script, const QString &name, const QJsonObject &args, int priority, int timeout, const QString & origin)
|
||||
{
|
||||
// clear current effect on the channel
|
||||
channelCleared(priority);
|
||||
|
||||
// create the effect
|
||||
Effect * effect = new Effect(_mainThreadState, priority, timeout, script, name, args);
|
||||
connect(effect, SIGNAL(setColors(int,std::vector<ColorRgb>,int,bool,hyperion::Components)), _hyperion, SLOT(setColors(int,std::vector<ColorRgb>,int,bool,hyperion::Components)), Qt::QueuedConnection);
|
||||
Effect * effect = new Effect(_mainThreadState, priority, timeout, script, name, args, origin);
|
||||
connect(effect, SIGNAL(setColors(int,std::vector<ColorRgb>,int,bool,hyperion::Components,const QString)), _hyperion, SLOT(setColors(int,std::vector<ColorRgb>,int,bool,hyperion::Components,const QString)), Qt::QueuedConnection);
|
||||
connect(effect, SIGNAL(effectFinished(Effect*)), this, SLOT(effectFinished(Effect*)));
|
||||
_activeEffects.push_back(effect);
|
||||
|
||||
// start the effect
|
||||
_hyperion->registerPriority(name.toStdString(), priority);
|
||||
_hyperion->registerPriority(name, priority);
|
||||
effect->start();
|
||||
|
||||
return 0;
|
||||
@@ -426,5 +431,5 @@ void EffectEngine::effectFinished(Effect *effect)
|
||||
|
||||
// cleanup the effect
|
||||
effect->deleteLater();
|
||||
_hyperion->unRegisterPriority(effect->getName().toStdString());
|
||||
_hyperion->unRegisterPriority(effect->getName());
|
||||
}
|
||||
|
Reference in New Issue
Block a user