Blame |
Last modification |
View Log
| RSS feed
#include "main.h"
#include "flowcam.h"
pthread_t piCamThread
;
char* indata
= NULL
;
PyObject
*pName
, *pModule
, *pDict
, *pFunc
, *pFunc2
;
//>> Get Motion Vector Data from mmap
//------------------------------------------------------------------------------------------------------
void get_flowcam_values
(){
PiCamMoVector
= atoi(indata
); //PiCam Motion Vectors
printf("MAIN: %d\n", PiCamMoVector
);
}
//>> Call Function in Python Program
//------------------------------------------------------------------------------------------------------
void *ThreadProc
()
{
if(PyCallable_Check
(pFunc
))
{
PyObject_CallObject
(pFunc
, NULL
);
}else{
PyErr_Print
();
}
//Clean up (Programm will never reach this Part)
Py_DECREF
(pModule
);
Py_DECREF
(pName
);
Py_Finalize
();
printf("piCamThread is finishing...\n");
}
//>> Create MMAP, Python Object and start Thread
//------------------------------------------------------------------------------------------------------
void flowcam_init
(){
//////////////////////////////////////////////////////////////////////////
// Create a MMAP
int fd
;
if((fd
= open
("/home/pi/ExPlat/input.dat", O_RDWR
)) == -1)
{
printf("Couldn't open 'input.data'\n");
}
indata
= mmap
( NULL
, 1024, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
if(indata
!= NULL
)
{
printf("Wrapper has created a MMAP for file 'input.data'\n");
}
//////////////////////////////////////////////////////////////////////////
char *script
= "motionVector";
char *functionUse
= "get_values";
Py_Initialize
();
pName
= PyString_FromString
(script
);
PyRun_SimpleString
("import sys");
PyRun_SimpleString
("sys.path.append(\"/home/pi/ExPlat\")");
pModule
= PyImport_Import
(pName
);
pDict
= PyModule_GetDict
(pModule
);
pFunc
= PyDict_GetItemString
(pDict
, functionUse
);
// POSIX code
pthread_create
( &piCamThread
, NULL
, ThreadProc
, NULL
);
}