Skip to content

Commit

Permalink
Fix 1181 - Effects were not started from tray (#1199)
Browse files Browse the repository at this point in the history
* Fix 1181, add constants and defaults

* Include #1195 changes
  • Loading branch information
Lord-Grey authored Mar 19, 2021
1 parent 41af5c1 commit 94d9b02
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 98 deletions.
10 changes: 6 additions & 4 deletions include/effectengine/Effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class Effect : public QThread
Q_OBJECT

public:

static const int ENDLESS;

friend class EffectModule;

Effect(Hyperion *hyperion
Expand Down Expand Up @@ -53,12 +56,11 @@ class Effect : public QThread
bool isInterruptionRequested();

///
/// @brief Get the remaining timeout, or 0 if there
/// is no timeout for this effect.
/// @brief Get the remaining timeout, or indication it is endless
///
/// @return The flag state
///
int getRemaining();
int getRemaining() const;


QString getScript() const { return _script; }
Expand Down Expand Up @@ -88,7 +90,7 @@ class Effect : public QThread
const QJsonObject _args;
const QString _imageData;

int64_t _endTime;
qint64 _endTime;

/// Buffer for colorData
QVector<ColorRgb> _colors;
Expand Down
7 changes: 4 additions & 3 deletions include/effectengine/EffectEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

// Effect engine includes
#include <effectengine/EffectDefinition.h>
#include <effectengine/Effect.h>
#include <effectengine/ActiveEffectDefinition.h>
#include <effectengine/EffectSchema.h>
#include <utils/Logger.h>
Expand Down Expand Up @@ -69,13 +70,13 @@ class EffectEngine : public QObject

public slots:
/// Run the specified effect on the given priority channel and optionally specify a timeout
int runEffect(const QString &effectName, int priority, int timeout = -1, const QString &origin="System");
int runEffect(const QString &effectName, int priority, int timeout = Effect::ENDLESS, const QString &origin="System");

/// Run the specified effect on the given priority channel and optionally specify a timeout
int runEffect(const QString &effectName
, const QJsonObject &args
, int priority
, int timeout = -1
, int timeout = Effect::ENDLESS
, const QString &pythonScript = ""
, const QString &origin = "System"
, unsigned smoothCfg=0
Expand All @@ -102,7 +103,7 @@ private slots:
,const QString &name
, const QJsonObject &args
, int priority
, int timeout = -1
, int timeout = Effect::ENDLESS
, const QString &origin="System"
, unsigned smoothCfg=0
, const QString &imageData = ""
Expand Down
7 changes: 4 additions & 3 deletions include/hyperion/BGEffectHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <utils/Logger.h>
#include <hyperion/Hyperion.h>
#include <utils/settings.h>
#include <effectengine/Effect.h>

///
/// @brief Handle the background Effect settings, reacts on runtime to settings changes
Expand Down Expand Up @@ -37,7 +38,7 @@ private slots:

#define BGCONFIG_ARRAY bgColorConfig.toArray()
// clear background priority
_hyperion->clear(254);
_hyperion->clear(PriorityMuxer::BG_PRIORITY);
// initial background effect/color
if (BGEffectConfig["enable"].toBool(true))
{
Expand All @@ -53,12 +54,12 @@ private slots:
static_cast<uint8_t>(BGCONFIG_ARRAY.at(2).toInt(0))
}
};
_hyperion->setColor(254, bg_color);
_hyperion->setColor(PriorityMuxer::BG_PRIORITY, bg_color);
Info(Logger::getInstance("HYPERION"),"Initial background color set (%d %d %d)",bg_color.at(0).red, bg_color.at(0).green, bg_color.at(0).blue);
}
else
{
int result = _hyperion->setEffect(bgEffectConfig, 254);
int result = _hyperion->setEffect(bgEffectConfig, PriorityMuxer::BG_PRIORITY, Effect::ENDLESS);
Info(Logger::getInstance("HYPERION"),"Initial background effect '%s' %s", QSTRING_CSTR(bgEffectConfig), ((result == 0) ? "started" : "failed"));
}
}
Expand Down
5 changes: 3 additions & 2 deletions include/hyperion/Hyperion.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

// Effect engine includes
#include <effectengine/EffectDefinition.h>
#include <effectengine/Effect.h>
#include <effectengine/ActiveEffectDefinition.h>
#include <effectengine/EffectSchema.h>

Expand Down Expand Up @@ -217,7 +218,7 @@ public slots:
/// @param effectName Name of the effec to run
/// @param priority The priority channel of the effect
/// @param timeout The timeout of the effect (after the timout, the effect will be cleared)
int setEffect(const QString & effectName, int priority, int timeout = -1, const QString & origin="System");
int setEffect(const QString & effectName, int priority, int timeout = Effect::ENDLESS, const QString & origin="System");

/// Run the specified effect on the given priority channel and optionally specify a timeout
/// @param effectName Name of the effec to run
Expand All @@ -227,7 +228,7 @@ public slots:
int setEffect(const QString &effectName
, const QJsonObject &args
, int priority
, int timeout = -1
, int timeout = Effect::ENDLESS
, const QString &pythonScript = ""
, const QString &origin="System"
, const QString &imageData = ""
Expand Down
3 changes: 3 additions & 0 deletions include/hyperion/PriorityMuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class PriorityMuxer : public QObject
QString owner;
};

//Foreground and Background priorities
const static int FG_PRIORITY;
const static int BG_PRIORITY;
/// The lowest possible priority, which is used when no priority channels are active
const static int LOWEST_PRIORITY;

Expand Down
6 changes: 3 additions & 3 deletions include/utils/hyperion.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <hyperion/LedString.h>
// fg effect
#include <hyperion/Hyperion.h>
#include <hyperion/PriorityMuxer.h>

///
/// @brief Provide utility methods for Hyperion class
Expand All @@ -16,7 +17,6 @@ namespace hyperion {
void handleInitialEffect(Hyperion* hyperion, const QJsonObject& FGEffectConfig)
{
#define FGCONFIG_ARRAY fgColorConfig.toArray()
const int FG_PRIORITY = 0;
const int DURATION_INFINITY = 0;

// initial foreground effect/color
Expand All @@ -41,12 +41,12 @@ namespace hyperion {
static_cast<uint8_t>(FGCONFIG_ARRAY.at(2).toInt(0))
}
};
hyperion->setColor(FG_PRIORITY, fg_color, fg_duration_ms);
hyperion->setColor(PriorityMuxer::FG_PRIORITY, fg_color, fg_duration_ms);
Info(Logger::getInstance("HYPERION"),"Initial foreground color set (%d %d %d)",fg_color.at(0).red,fg_color.at(0).green,fg_color.at(0).blue);
}
else
{
int result = hyperion->setEffect(fgEffectConfig, FG_PRIORITY, fg_duration_ms);
int result = hyperion->setEffect(fgEffectConfig, PriorityMuxer::FG_PRIORITY, fg_duration_ms);
Info(Logger::getInstance("HYPERION"),"Initial foreground effect '%s' %s", QSTRING_CSTR(fgEffectConfig), ((result == 0) ? "started" : "failed"));
}
}
Expand Down
13 changes: 7 additions & 6 deletions libsrc/effectengine/Effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// python utils
#include <python/PythonProgram.h>

const int Effect::ENDLESS = -1;

Effect::Effect(Hyperion *hyperion, int priority, int timeout, const QString &script, const QString &name, const QJsonObject &args, const QString &imageData)
: QThread()
, _hyperion(hyperion)
Expand All @@ -22,7 +24,7 @@ Effect::Effect(Hyperion *hyperion, int priority, int timeout, const QString &scr
, _args(args)
, _imageData(imageData)
, _endTime(-1)
, _colors()
, _interupt(false)
, _imageSize(hyperion->getLedGridSize())
, _image(_imageSize,QImage::Format_ARGB32_Premultiplied)
{
Expand All @@ -49,21 +51,20 @@ Effect::~Effect()

bool Effect::isInterruptionRequested()
{
return _interupt || getRemaining() < 0;
return _interupt || getRemaining() < ENDLESS;
}

int Effect::getRemaining()
int Effect::getRemaining() const
{
// determine the timeout
int timeout = _timeout;

if (timeout > 0)
{
timeout = _endTime - QDateTime::currentMSecsSinceEpoch();
timeout = static_cast<int>( _endTime - QDateTime::currentMSecsSinceEpoch());
return timeout;
}

return timeout;
return ENDLESS;
}

void Effect::setModuleParameters()
Expand Down
4 changes: 1 addition & 3 deletions libsrc/effectengine/EffectEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

EffectEngine::EffectEngine(Hyperion * hyperion)
: _hyperion(hyperion)
, _availableEffects()
, _activeEffects()
, _log(Logger::getInstance("EFFECTENGINE"))
, _effectFileHandler(EffectFileHandler::getInstance())
{
Expand Down Expand Up @@ -202,7 +200,7 @@ void EffectEngine::allChannelsCleared()
{
for (Effect * effect : _activeEffects)
{
if (effect->getPriority() != 254 && !effect->isInterruptionRequested())
if (effect->getPriority() != PriorityMuxer::BG_PRIORITY && !effect->isInterruptionRequested())
{
effect->requestInterruption();
}
Expand Down
Loading

0 comments on commit 94d9b02

Please sign in to comment.