forked from fabiovix/py-ads1256
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrapper.c
105 lines (80 loc) · 2.59 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
#include <Python.h>
#include "wrapper.h"
/* Docstrings */
static char module_docstring[] =
"ads1256 library 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, {"reads the specified channel from the ads1256"}},
{"read_all_channels", adc_read_all_channels, METH_VARARGS, {"reads all 8 channels of the ads1256"}},
{"start", adc_start, METH_VARARGS, {"starts and sets the ads1256"}},
{"stop", adc_stop, METH_VARARGS, {"ends and closes ads1256"}},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef ads1256 = {
PyModuleDef_HEAD_INIT,
"ads1256", /* name of module */
NULL, /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */
module_methods
};
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;
}