-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathwrapper.c
106 lines (80 loc) · 2.47 KB
/
wrapper.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <Python.h>
#include "wrapper.h"
/* Docstrings */
static char module_docstring[] =
"Esta biblioteca é um wrapper ";
/* Available functions */
static PyObject *adc_read_channel(PyObject *self, PyObject *args);
static PyObject *adc_read_all_channels(PyObject *self, PyObject *args);
static PyObject *adc_start(PyObject *self, PyObject *args);
static PyObject *adc_stop(PyObject *self, PyObject *args);
/* Module specification */
static PyMethodDef module_methods[] = {
// {"chi2", chi2_chi2, METH_VARARGS, chi2_docstring},
{"read_channel", adc_read_channel, METH_VARARGS, {"lê o canal especificado do ads1256"}},
{"read_all_channels", adc_read_all_channels, METH_VARARGS, {"lê todos os 8 canais do ads1256"}},
{"start", adc_start, METH_VARARGS, {"inicia e configura o ads1256"}},
{"stop", adc_stop, 0, {"termina e fecha o ads1256"}},
{NULL, NULL, 0, NULL}
};
/* Initialize the module */
PyMODINIT_FUNC initads1256(void)
{
PyObject *m = Py_InitModule3("ads1256", module_methods, module_docstring);
if (m == NULL)
return;
}
static PyObject *adc_start(PyObject *self, PyObject *args)
{
char * ganho, *sps;
PyObject *yerr_obj;
double v[8];
int value ;
/* Parse the input tuple */
if (!PyArg_ParseTuple(args, "ss", &ganho, &sps,&yerr_obj))
return NULL;
/* execute the code */
value = adcStart(4,"0",ganho,sps);
/* Build the output tuple */
PyObject *ret = Py_BuildValue("i",value);
return ret;
}
static PyObject *adc_read_channel(PyObject *self, PyObject *args)
{
int ch;
long int retorno;
PyObject *yerr_obj;
/* Parse the input tuple */
if (!PyArg_ParseTuple(args, "i", &ch,&yerr_obj))
return NULL;
/* execute the code */
retorno = readChannel(ch);
return Py_BuildValue("l",retorno);
}
static PyObject *adc_read_all_channels(PyObject *self, PyObject *args)
{
PyObject *yerr_obj;
long int v[8];
/* execute the code */
readChannels(v);
/* Build the output tuple */
PyObject *ret = Py_BuildValue("[l,l,l,l,l,l,l,l]",
v[0],
v[1],
v[2],
v[3],
v[4],
v[5],
v[6],
v[7]
);
return ret;
}
static PyObject *adc_stop(PyObject *self, PyObject *args)
{
/* execute the code */
int value = adcStop();
/* Build the output tuple */
PyObject *ret = Py_BuildValue("i",value);
return ret;
}