Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2105 - 1
#include "main.h"
2
#include "flowcam.h"
3
 
4
pthread_t piCamThread;                                
5
char* indata = NULL;
6
PyObject *pName, *pModule, *pDict, *pFunc, *pFunc2;
7
 
8
//>> Get Motion Vector Data from mmap
9
//------------------------------------------------------------------------------------------------------
10
void get_flowcam_values(){
11
        PiCamMoVector = atoi(indata);                  //PiCam Motion Vectors
12
        printf("MAIN: %d\n", PiCamMoVector);
13
}
14
 
15
//>> Call Function in Python Program
16
//------------------------------------------------------------------------------------------------------
17
void *ThreadProc()
18
{
19
    if(PyCallable_Check(pFunc))
20
    {
21
        PyObject_CallObject(pFunc, NULL);
22
    }else{
23
        PyErr_Print();
24
    }
25
 
26
    //Clean up (Programm will never reach this Part)
27
    Py_DECREF(pModule);
28
    Py_DECREF(pName);
29
 
30
    Py_Finalize();
31
    printf("piCamThread is finishing...\n");
32
}
33
 
34
//>> Create MMAP, Python Object and start Thread
35
//------------------------------------------------------------------------------------------------------
36
void flowcam_init(){
37
    //////////////////////////////////////////////////////////////////////////
38
    // Create a MMAP
39
    int fd;
40
    if((fd = open("/home/pi/ExPlat/input.dat", O_RDWR)) == -1)
41
    {
42
        printf("Couldn't open 'input.data'\n");
43
    }
44
    indata = mmap(  NULL, 1024, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
45
    if(indata != NULL)
46
    {  
47
        printf("Wrapper has created a MMAP for file 'input.data'\n");
48
    }
49
    //////////////////////////////////////////////////////////////////////////
50
 
51
    char *script = "motionVector";
52
    char *functionUse = "get_values";
53
    Py_Initialize();
54
    pName = PyString_FromString(script);
55
    PyRun_SimpleString("import sys");
56
    PyRun_SimpleString("sys.path.append(\"/home/pi/ExPlat\")");
57
    pModule = PyImport_Import(pName);
58
    pDict = PyModule_GetDict(pModule);
59
    pFunc = PyDict_GetItemString(pDict, functionUse);
60
 
61
    // POSIX code
62
    pthread_create( &piCamThread, NULL, ThreadProc, NULL);
63
}