diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d7da835..10f5f39d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Updated dependency rpi_ws281x to latest upstream +- Fix High CPU load (RPI3B+) (#1013) ### Fixed - LED-Hue: Proper black in Entertainement mode if min brightness is set diff --git a/include/effectengine/Effect.h b/include/effectengine/Effect.h index a1ecc990..ca4c3a43 100644 --- a/include/effectengine/Effect.h +++ b/include/effectengine/Effect.h @@ -44,10 +44,22 @@ public: void requestInterruption() { _interupt = true; } /// - /// @brief Check if the interruption flag has been set + /// @brief Check an interruption was requested. + /// This can come from requestInterruption() + /// or the effect's timeout expiring. + /// /// @return The flag state /// - bool isInterruptionRequested() { return _interupt; } + bool isInterruptionRequested(); + + /// + /// @brief Get the remaining timeout, or 0 if there + /// is no timeout for this effect. + /// + /// @return The flag state + /// + int getRemaining(); + QString getScript() const { return _script; } QString getName() const { return _name; } diff --git a/libsrc/effectengine/Effect.cpp b/libsrc/effectengine/Effect.cpp index 3f241f2f..22c985fa 100644 --- a/libsrc/effectengine/Effect.cpp +++ b/libsrc/effectengine/Effect.cpp @@ -47,6 +47,25 @@ Effect::~Effect() _imageStack.clear(); } +bool Effect::isInterruptionRequested() +{ + return _interupt || getRemaining() < 0; +} + +int Effect::getRemaining() +{ + // determine the timeout + int timeout = _timeout; + + if (timeout > 0) + { + timeout = _endTime - QDateTime::currentMSecsSinceEpoch(); + return timeout; + } + + return timeout; +} + void Effect::setModuleParameters() { // import the buildtin Hyperion module diff --git a/libsrc/effectengine/EffectModule.cpp b/libsrc/effectengine/EffectModule.cpp index 78d6be5d..59a6bf73 100644 --- a/libsrc/effectengine/EffectModule.cpp +++ b/libsrc/effectengine/EffectModule.cpp @@ -124,16 +124,6 @@ PyObject* EffectModule::wrapSetColor(PyObject *self, PyObject *args) // check if we have aborted already if (getEffect()->isInterruptionRequested()) Py_RETURN_NONE; - // determine the timeout - int timeout = getEffect()->_timeout; - if (timeout > 0) - { - timeout = getEffect()->_endTime - QDateTime::currentMSecsSinceEpoch(); - - // we are done if the time has passed - if (timeout <= 0) Py_RETURN_NONE; - } - // check the number of arguments int argCount = PyTuple_Size(args); if (argCount == 3) @@ -144,7 +134,7 @@ PyObject* EffectModule::wrapSetColor(PyObject *self, PyObject *args) { getEffect()->_colors.fill(color); QVector _cQV = getEffect()->_colors; - emit getEffect()->setInput(getEffect()->_priority, std::vector( _cQV.begin(), _cQV.end() ), timeout, false); + emit getEffect()->setInput(getEffect()->_priority, std::vector( _cQV.begin(), _cQV.end() ), getEffect()->getRemaining(), false); Py_RETURN_NONE; } return nullptr; @@ -163,7 +153,7 @@ PyObject* EffectModule::wrapSetColor(PyObject *self, PyObject *args) char * data = PyByteArray_AS_STRING(bytearray); memcpy(getEffect()->_colors.data(), data, length); QVector _cQV = getEffect()->_colors; - emit getEffect()->setInput(getEffect()->_priority, std::vector( _cQV.begin(), _cQV.end() ), timeout, false); + emit getEffect()->setInput(getEffect()->_priority, std::vector( _cQV.begin(), _cQV.end() ), getEffect()->getRemaining(), false); Py_RETURN_NONE; } else @@ -195,16 +185,6 @@ PyObject* EffectModule::wrapSetImage(PyObject *self, PyObject *args) // check if we have aborted already if (getEffect()->isInterruptionRequested()) Py_RETURN_NONE; - // determine the timeout - int timeout = getEffect()->_timeout; - if (timeout > 0) - { - timeout = getEffect()->_endTime - QDateTime::currentMSecsSinceEpoch(); - - // we are done if the time has passed - if (timeout <= 0) Py_RETURN_NONE; - } - // bytearray of values int width, height; PyObject * bytearray = nullptr; @@ -218,7 +198,7 @@ PyObject* EffectModule::wrapSetImage(PyObject *self, PyObject *args) Image image(width, height); char * data = PyByteArray_AS_STRING(bytearray); memcpy(image.memptr(), data, length); - emit getEffect()->setInputImage(getEffect()->_priority, image, timeout, false); + emit getEffect()->setInputImage(getEffect()->_priority, image, getEffect()->getRemaining(), false); Py_RETURN_NONE; } else @@ -332,16 +312,6 @@ PyObject* EffectModule::wrapImageShow(PyObject *self, PyObject *args) // check if we have aborted already if (getEffect()->isInterruptionRequested()) Py_RETURN_NONE; - // determine the timeout - int timeout = getEffect()->_timeout; - if (timeout > 0) - { - timeout = getEffect()->_endTime - QDateTime::currentMSecsSinceEpoch(); - - // we are done if the time has passed - if (timeout <= 0) Py_RETURN_NONE; - } - int argCount = PyTuple_Size(args); int imgId = -1; bool argsOk = (argCount == 0); @@ -375,7 +345,7 @@ PyObject* EffectModule::wrapImageShow(PyObject *self, PyObject *args) } memcpy(image.memptr(), binaryImage.data(), binaryImage.size()); - emit getEffect()->setInputImage(getEffect()->_priority, image, timeout, false); + emit getEffect()->setInputImage(getEffect()->_priority, image, getEffect()->getRemaining(), false); return Py_BuildValue(""); }