0
|
1 %module serport
|
|
2
|
|
3 %{
|
|
4 #include <sys/types.h>
|
|
5 #include <sys/stat.h>
|
|
6 #include <sys/ioctl.h>
|
|
7 #include <fcntl.h>
|
|
8 #include <linux/i2c.h>
|
|
9 #include <linux/i2c-dev.h>
|
|
10 #include <unistd.h>
|
|
11 %}
|
|
12
|
|
13
|
|
14 %typemap(python,in) __u8 {
|
|
15 if( !PyInt_Check($input)) {
|
|
16 PyErr_SetString(PyExc_TypeError,"not an integer");
|
|
17 return NULL;
|
|
18 }
|
|
19 $1 = ($type) PyInt_AsLong($input);
|
|
20 }
|
|
21
|
|
22 %typemap(python,out) __s32 {
|
|
23 $result = Py_BuildValue("i", ($type) $1);
|
|
24 }
|
|
25
|
|
26 %inline %{
|
|
27
|
|
28 __s32 i2c_smbus_write_byte(int file, __u8 value);
|
|
29 __s32 i2c_smbus_read_byte(int file);
|
|
30
|
|
31 PyObject *read_all_adc(int file) {
|
|
32 PyObject *t=PyTuple_New(4);
|
|
33
|
|
34 #define CHAN_TO_TUPLE_POS(chan,idx) i2c_smbus_write_byte(file, chan);\
|
|
35 PyTuple_SetItem(t,idx,PyInt_FromLong(i2c_smbus_read_byte(file)));
|
|
36
|
76
|
37 /*
|
|
38 these are shuffled here to match the way the pots read in. in
|
|
39 the returned tuple, 0=left pot..3=right pot.
|
|
40 */
|
0
|
41 CHAN_TO_TUPLE_POS(1,0)
|
|
42 CHAN_TO_TUPLE_POS(2,1)
|
|
43 CHAN_TO_TUPLE_POS(3,2)
|
|
44 CHAN_TO_TUPLE_POS(0,3)
|
|
45
|
|
46 return t;
|
|
47
|
|
48 }
|
|
49
|
|
50 %}
|