2013-11-24 16:10:48 +01:00
|
|
|
#pragma once
|
|
|
|
|
2013-11-26 21:38:24 +01:00
|
|
|
// Python includes
|
|
|
|
#include <Python.h>
|
|
|
|
|
2013-11-30 17:41:38 +01:00
|
|
|
// Qt includes
|
|
|
|
#include <QThread>
|
2016-09-21 22:01:50 +02:00
|
|
|
#include <QSize>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QPainter>
|
2013-11-30 17:41:38 +01:00
|
|
|
|
2013-11-28 14:38:07 +01:00
|
|
|
// Hyperion includes
|
|
|
|
#include <hyperion/ImageProcessor.h>
|
|
|
|
|
2013-11-26 21:38:24 +01:00
|
|
|
class Effect : public QThread
|
2013-11-24 16:10:48 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2016-09-13 11:51:16 +02:00
|
|
|
Effect(PyThreadState * mainThreadState, int priority, int timeout, const QString & script, const QString & name, const Json::Value & args = Json::Value());
|
2013-11-24 16:10:48 +01:00
|
|
|
virtual ~Effect();
|
2013-11-26 21:38:24 +01:00
|
|
|
|
|
|
|
virtual void run();
|
|
|
|
|
|
|
|
int getPriority() const;
|
2016-04-24 17:07:31 +02:00
|
|
|
|
2016-09-13 11:51:16 +02:00
|
|
|
QString getScript() const { return _script; }
|
|
|
|
QString getName() const { return _name; }
|
2016-04-24 17:07:31 +02:00
|
|
|
|
|
|
|
int getTimeout() const {return _timeout; }
|
|
|
|
|
|
|
|
Json::Value getArgs() const { return _args; }
|
2013-11-26 21:38:24 +01:00
|
|
|
|
2013-11-30 15:54:47 +01:00
|
|
|
bool isAbortRequested() const;
|
|
|
|
|
2014-02-26 18:10:17 +01:00
|
|
|
/// This function registers the extension module in Python
|
|
|
|
static void registerHyperionExtensionModule();
|
|
|
|
|
2013-11-26 21:38:24 +01:00
|
|
|
public slots:
|
|
|
|
void abort();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void effectFinished(Effect * effect);
|
|
|
|
|
2013-12-08 17:45:26 +01:00
|
|
|
void setColors(int priority, const std::vector<ColorRgb> &ledColors, const int timeout_ms, bool clearEffects);
|
2013-11-29 23:22:49 +01:00
|
|
|
|
2013-11-26 21:38:24 +01:00
|
|
|
private slots:
|
|
|
|
void effectFinished();
|
|
|
|
|
2013-11-28 14:15:52 +01:00
|
|
|
private:
|
2013-11-30 17:41:38 +01:00
|
|
|
PyObject * json2python(const Json::Value & json) const;
|
|
|
|
|
2013-11-28 14:15:52 +01:00
|
|
|
// Wrapper methods for Python interpreter extra buildin methods
|
2016-09-21 22:01:50 +02:00
|
|
|
static PyMethodDef effectMethods[];
|
|
|
|
static PyObject* wrapSetColor(PyObject *self, PyObject *args);
|
2013-11-28 14:15:52 +01:00
|
|
|
static PyObject* wrapSetImage(PyObject *self, PyObject *args);
|
|
|
|
static PyObject* wrapAbort(PyObject *self, PyObject *args);
|
2016-09-21 22:01:50 +02:00
|
|
|
static PyObject* wrapImageShow(PyObject *self, PyObject *args);
|
|
|
|
static PyObject* wrapImageCanonicalGradient(PyObject *self, PyObject *args);
|
|
|
|
static PyObject* wrapImageRadialGradient(PyObject *self, PyObject *args);
|
|
|
|
|
|
|
|
static Effect * getEffect();
|
2014-02-26 18:10:17 +01:00
|
|
|
|
|
|
|
#if PY_MAJOR_VERSION >= 3
|
2016-09-21 22:01:50 +02:00
|
|
|
static struct PyModuleDef moduleDef;
|
|
|
|
static PyObject* PyInit_hyperion();
|
2014-02-26 18:10:17 +01:00
|
|
|
#else
|
2016-09-21 22:01:50 +02:00
|
|
|
static void PyInit_hyperion();
|
2014-02-26 18:10:17 +01:00
|
|
|
#endif
|
2013-11-28 14:15:52 +01:00
|
|
|
|
2013-11-26 21:38:24 +01:00
|
|
|
private:
|
2016-09-21 22:01:50 +02:00
|
|
|
PyThreadState * _mainThreadState;
|
2014-02-26 18:10:17 +01:00
|
|
|
|
2013-11-26 21:38:24 +01:00
|
|
|
const int _priority;
|
|
|
|
|
|
|
|
const int _timeout;
|
2013-11-29 23:22:49 +01:00
|
|
|
|
2016-09-13 11:51:16 +02:00
|
|
|
const QString _script;
|
|
|
|
const QString _name;
|
2013-11-30 00:28:04 +01:00
|
|
|
|
2013-12-01 14:09:01 +01:00
|
|
|
const Json::Value _args;
|
2013-11-30 00:28:04 +01:00
|
|
|
|
2013-11-28 14:29:31 +01:00
|
|
|
int64_t _endTime;
|
2013-11-26 21:38:24 +01:00
|
|
|
|
|
|
|
PyThreadState * _interpreterThreadState;
|
|
|
|
|
|
|
|
bool _abortRequested;
|
2013-11-28 14:38:07 +01:00
|
|
|
|
|
|
|
/// The processor for translating images to led-values
|
|
|
|
ImageProcessor * _imageProcessor;
|
2013-12-08 12:46:33 +01:00
|
|
|
|
|
|
|
/// Buffer for colorData
|
|
|
|
std::vector<ColorRgb> _colors;
|
2016-09-21 22:01:50 +02:00
|
|
|
|
|
|
|
QSize _imageSize;
|
|
|
|
|
|
|
|
QImage * _image;
|
|
|
|
QPainter * _painter;
|
2013-11-24 16:10:48 +01:00
|
|
|
};
|
2016-06-23 13:48:49 +02:00
|
|
|
|