Skip to content

Commit

Permalink
Interrupt effect on timeout (#1181)
Browse files Browse the repository at this point in the history
Fixes #1013
  • Loading branch information
vtavernier authored Feb 23, 2021
1 parent 45bd23c commit 9475b93
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions include/effectengine/Effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,22 @@ class Effect : public QThread
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; }
Expand Down
19 changes: 19 additions & 0 deletions libsrc/effectengine/Effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 4 additions & 34 deletions libsrc/effectengine/EffectModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -144,7 +134,7 @@ PyObject* EffectModule::wrapSetColor(PyObject *self, PyObject *args)
{
getEffect()->_colors.fill(color);
QVector<ColorRgb> _cQV = getEffect()->_colors;
emit getEffect()->setInput(getEffect()->_priority, std::vector<ColorRgb>( _cQV.begin(), _cQV.end() ), timeout, false);
emit getEffect()->setInput(getEffect()->_priority, std::vector<ColorRgb>( _cQV.begin(), _cQV.end() ), getEffect()->getRemaining(), false);
Py_RETURN_NONE;
}
return nullptr;
Expand All @@ -163,7 +153,7 @@ PyObject* EffectModule::wrapSetColor(PyObject *self, PyObject *args)
char * data = PyByteArray_AS_STRING(bytearray);
memcpy(getEffect()->_colors.data(), data, length);
QVector<ColorRgb> _cQV = getEffect()->_colors;
emit getEffect()->setInput(getEffect()->_priority, std::vector<ColorRgb>( _cQV.begin(), _cQV.end() ), timeout, false);
emit getEffect()->setInput(getEffect()->_priority, std::vector<ColorRgb>( _cQV.begin(), _cQV.end() ), getEffect()->getRemaining(), false);
Py_RETURN_NONE;
}
else
Expand Down Expand Up @@ -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;
Expand All @@ -218,7 +198,7 @@ PyObject* EffectModule::wrapSetImage(PyObject *self, PyObject *args)
Image<ColorRgb> 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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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("");
}
Expand Down

1 comment on commit 9475b93

@DonaldTrump-2020
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi friend, this commit makes selecting effect from tray menu not working, after I revert it, everything is fine. You can check and see

Please sign in to comment.