forked from eclipse/mraa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mraajs.i
57 lines (47 loc) · 1.34 KB
/
mraajs.i
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
%module (docstring="Javascript interface to libmraa") mraa
%feature("autodoc", "3");
%include carrays.i
%array_class(uint8_t, uint8Array);
%inline %{
#include <node_buffer.h>
%}
%typemap(in) (const uint8_t *data, int length) {
$1 = (uint8_t*) node::Buffer::Data($input);
$2 = node::Buffer::Length($input);
}
%typemap(in) (uint8_t *txBuf, int length) {
$1 = (uint8_t*) node::Buffer::Data($input);
$2 = node::Buffer::Length($input);
}
namespace mraa {
class Spi;
%typemap(out) uint8_t*
{
$result = node::Buffer::New((char*) $1, arg3)->handle_;
}
}
%newobject I2c::read(uint8_t *data, int length);
%newobject Spi::write(uint8_t *data, int length);
%typemap(in) (uint8_t *data, int length) {
int x;
int ecode = SWIG_AsVal_int($input, &x);
if (!SWIG_IsOK(ecode)) {
SWIG_exception_fail(SWIG_ArgError(ecode), "Expected an int");
}
$2 = x;
if ($2 < 0) {
SWIG_exception_fail(SWIG_ERROR, "Positive integer expected");
SWIGV8_RETURN(v8::Undefined());
}
$1 = (uint8_t*) malloc($2 * sizeof(uint8_t));
}
%typemap(argout) (uint8_t *data, int length) {
if (result < 0) { /* Check for I/O error */
free($1);
SWIG_exception_fail(SWIG_ERROR, "I2c write failed");
SWIGV8_RETURN(v8::Undefined());
}
$result = node::Buffer::New((char*) $1, result)->handle_;
free($1);
}
%include ../mraa.i