mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Effect pointer feedback added from Python
Former-commit-id: a1175d2d3b4eb0e368a2cbf6a9ac3a0a386ef5bb
This commit is contained in:
parent
d24fddaf21
commit
80cdac2055
@ -1,35 +1,38 @@
|
|||||||
// stl includes
|
// stl includes
|
||||||
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
// effect engin eincludes
|
// effect engin eincludes
|
||||||
#include "Effect.h"
|
#include "Effect.h"
|
||||||
|
|
||||||
// Effect wrapper methods for Python interpreter extra build in methods
|
// Effect wrapper methods for Python interpreter extra build in methods
|
||||||
static PyObject* Effect_SetColor(PyObject *self, PyObject *args)
|
static PyObject* Effect_setColor(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
return Py_BuildValue("i", 42);
|
return Py_BuildValue("i", 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject* Effect_SetImage(PyObject *self, PyObject *args)
|
static PyObject* Effect_setImage(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
return Py_BuildValue("i", 42);
|
return Py_BuildValue("i", 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject* Effect_GetLedCount(PyObject *self, PyObject *args)
|
static PyObject* Effect_getLedCount(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
return Py_BuildValue("i", 42);
|
return Py_BuildValue("i", 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject* Effect_IsAbortRequested(PyObject *self, PyObject *args)
|
static PyObject* Effect_abort(PyObject *self, PyObject *)
|
||||||
{
|
{
|
||||||
return Py_BuildValue("i", 42);
|
Effect * effect = reinterpret_cast<Effect *>(PyCapsule_GetPointer(self, nullptr));
|
||||||
|
bool abort = effect->isAbortedRequested();
|
||||||
|
return Py_BuildValue("i", abort ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyMethodDef effectMethods[] = {
|
static PyMethodDef effectMethods[] = {
|
||||||
{"setColor", Effect_SetColor, METH_VARARGS, "Set a new color for the leds."},
|
{"setColor", Effect_setColor, METH_VARARGS, "Set a new color for the leds."},
|
||||||
{"setImage", Effect_SetImage, METH_VARARGS, "Set a new image to process and determine new led colors."},
|
{"setImage", Effect_setImage, METH_VARARGS, "Set a new image to process and determine new led colors."},
|
||||||
{"getLedCount", Effect_GetLedCount, METH_VARARGS, "Get the number of avaliable led channels."},
|
{"getLedCount", Effect_getLedCount, METH_VARARGS, "Get the number of avaliable led channels."},
|
||||||
{"isAbortRequested", Effect_IsAbortRequested, METH_VARARGS, "Check if the effect should abort execution."},
|
{"abort", Effect_abort, METH_NOARGS , "Check if the effect should abort execution."},
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -54,22 +57,11 @@ void Effect::run()
|
|||||||
// Initialize a new thread state
|
// Initialize a new thread state
|
||||||
PyEval_AcquireLock(); // Get the GIL
|
PyEval_AcquireLock(); // Get the GIL
|
||||||
_interpreterThreadState = Py_NewInterpreter();
|
_interpreterThreadState = Py_NewInterpreter();
|
||||||
Py_InitModule("hyperiond", effectMethods);
|
|
||||||
|
|
||||||
// Create hyperion instance in the new interpreter
|
// add methods extra builtin methods to the interpreter
|
||||||
std::ostringstream oss;
|
PyObject * thisCapsule = PyCapsule_New(this, nullptr, nullptr);
|
||||||
oss << "import hyperiond" << std::endl;
|
Py_InitModule4("hyperion", effectMethods, nullptr, thisCapsule, PYTHON_API_VERSION);
|
||||||
oss << "class Hyperion:" << std::endl;
|
std::cout << this << std::endl;
|
||||||
oss << " def setColor(self):" << std::endl;
|
|
||||||
oss << " return hyperiond.setColor()" << std::endl;
|
|
||||||
oss << " def setImage(self):" << std::endl;
|
|
||||||
oss << " return hyperiond.setImage()" << std::endl;
|
|
||||||
oss << " def getLedCount(self):" << std::endl;
|
|
||||||
oss << " return hyperiond.getLedCount()" << std::endl;
|
|
||||||
oss << " def isAbortRequested(self):" << std::endl;
|
|
||||||
oss << " return hyperiond.isAbortRequested()" << std::endl;
|
|
||||||
oss << "hyperion = Hyperion()" << std::endl;
|
|
||||||
PyRun_SimpleString(oss.str().c_str());
|
|
||||||
|
|
||||||
// Run the effect script
|
// Run the effect script
|
||||||
std::string script = "test.py";
|
std::string script = "test.py";
|
||||||
@ -82,6 +74,11 @@ void Effect::run()
|
|||||||
PyEval_ReleaseLock();
|
PyEval_ReleaseLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Effect::isAbortedRequested() const
|
||||||
|
{
|
||||||
|
return _abortRequested;
|
||||||
|
}
|
||||||
|
|
||||||
int Effect::getPriority() const
|
int Effect::getPriority() const
|
||||||
{
|
{
|
||||||
return _priority;
|
return _priority;
|
||||||
|
@ -16,6 +16,8 @@ public:
|
|||||||
|
|
||||||
virtual void run();
|
virtual void run();
|
||||||
|
|
||||||
|
bool isAbortedRequested() const;
|
||||||
|
|
||||||
int getPriority() const;
|
int getPriority() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
Loading…
Reference in New Issue
Block a user