mraajs: update for node.js 0.12 API differences
This requires setting #define SWIG_V8_VERSION 0x032873 in the mraajsJAVASCRIPT_wrap.cxx file. Note most v8 APIs now require v8::Isolate and v8::Persistent is no longer a v8::Handle so the gpio.hpp for ISR support is also modified by this change Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
@@ -27,6 +27,12 @@
|
|||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#if defined(SWIGJAVASCRIPT)
|
||||||
|
#if NODE_MODULE_VERSION >= 0x000D
|
||||||
|
#include <uv.h>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace mraa {
|
namespace mraa {
|
||||||
|
|
||||||
// These enums must match the enums in gpio.h
|
// These enums must match the enums in gpio.h
|
||||||
@@ -122,8 +128,13 @@ class Gpio {
|
|||||||
static void v8isr(uv_work_t* req, int status) {
|
static void v8isr(uv_work_t* req, int status) {
|
||||||
mraa::Gpio *This = (mraa::Gpio *)req->data;
|
mraa::Gpio *This = (mraa::Gpio *)req->data;
|
||||||
int argc = 1;
|
int argc = 1;
|
||||||
v8::Local<v8::Value> argv[] = { v8::Integer::New(-1) };
|
v8::Local<v8::Value> argv[] = { SWIGV8_INTEGER_NEW(-1) };
|
||||||
This->m_v8isr->Call(v8::Context::GetCurrent()->Global(), argc, argv);
|
#if NODE_MODULE_VERSION >= 0x000D
|
||||||
|
v8::Local<v8::Function> f = v8::Local<v8::Function>::New(v8::Isolate::GetCurrent(), This->m_v8isr);
|
||||||
|
f->Call(SWIGV8_CURRENT_CONTEXT()->Global(), argc, argv);
|
||||||
|
#else
|
||||||
|
This->m_v8isr->Call(SWIGV8_CURRENT_CONTEXT()->Global(), argc, argv);
|
||||||
|
#endif
|
||||||
delete req;
|
delete req;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +150,11 @@ class Gpio {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mraa_result_t isr(Edge mode, v8::Handle<v8::Function> func) {
|
mraa_result_t isr(Edge mode, v8::Handle<v8::Function> func) {
|
||||||
|
#if NODE_MODULE_VERSION >= 0x000D
|
||||||
|
m_v8isr.Reset(v8::Isolate::GetCurrent(), func);
|
||||||
|
#else
|
||||||
m_v8isr = v8::Persistent<v8::Function>::New(func);
|
m_v8isr = v8::Persistent<v8::Function>::New(func);
|
||||||
|
#endif
|
||||||
return mraa_gpio_isr(m_gpio, (gpio_edge_t) mode, &uvwork, this);
|
return mraa_gpio_isr(m_gpio, (gpio_edge_t) mode, &uvwork, this);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -164,7 +179,12 @@ class Gpio {
|
|||||||
*/
|
*/
|
||||||
mraa_result_t isrExit() {
|
mraa_result_t isrExit() {
|
||||||
#if defined(SWIGJAVASCRIPT)
|
#if defined(SWIGJAVASCRIPT)
|
||||||
|
#if NODE_MODULE_VERSION >= 0x000D
|
||||||
|
m_v8isr.Reset();
|
||||||
|
#else
|
||||||
m_v8isr.Dispose();
|
m_v8isr.Dispose();
|
||||||
|
m_v8isr.Clear();
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return mraa_gpio_isr_exit(m_gpio);
|
return mraa_gpio_isr_exit(m_gpio);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
%module (docstring="Javascript interface to libmraa") mraa
|
%module (docstring="Javascript interface to libmraa") mraa
|
||||||
|
|
||||||
%feature("autodoc", "3");
|
%feature("autodoc", "3");
|
||||||
|
#define NODE012
|
||||||
|
|
||||||
%include carrays.i
|
%include carrays.i
|
||||||
%include cpointer.i
|
%include cpointer.i
|
||||||
@@ -28,7 +29,11 @@ namespace mraa {
|
|||||||
class Spi;
|
class Spi;
|
||||||
%typemap(out) uint8_t*
|
%typemap(out) uint8_t*
|
||||||
{
|
{
|
||||||
|
#ifdef NODE012
|
||||||
|
$result = node::Buffer::New((char*) $1, arg3);
|
||||||
|
#else
|
||||||
$result = node::Buffer::New((char*) $1, arg3)->handle_;
|
$result = node::Buffer::New((char*) $1, arg3)->handle_;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +49,7 @@ class Spi;
|
|||||||
$2 = x;
|
$2 = x;
|
||||||
if ($2 < 0) {
|
if ($2 < 0) {
|
||||||
SWIG_exception_fail(SWIG_ERROR, "Positive integer expected");
|
SWIG_exception_fail(SWIG_ERROR, "Positive integer expected");
|
||||||
SWIGV8_RETURN(v8::Undefined());
|
SWIGV8_RETURN(SWIGV8_UNDEFINED());
|
||||||
}
|
}
|
||||||
$1 = (uint8_t*) malloc($2 * sizeof(uint8_t));
|
$1 = (uint8_t*) malloc($2 * sizeof(uint8_t));
|
||||||
}
|
}
|
||||||
@@ -53,9 +58,13 @@ class Spi;
|
|||||||
if (result < 0) { /* Check for I/O error */
|
if (result < 0) { /* Check for I/O error */
|
||||||
free($1);
|
free($1);
|
||||||
SWIG_exception_fail(SWIG_ERROR, "I2c write failed");
|
SWIG_exception_fail(SWIG_ERROR, "I2c write failed");
|
||||||
SWIGV8_RETURN(v8::Undefined());
|
SWIGV8_RETURN(SWIGV8_UNDEFINED());
|
||||||
}
|
}
|
||||||
|
#ifdef NODE012
|
||||||
|
$result = node::Buffer::New((char*) $1, result);
|
||||||
|
#else
|
||||||
$result = node::Buffer::New((char*) $1, result)->handle_;
|
$result = node::Buffer::New((char*) $1, result)->handle_;
|
||||||
|
#endif
|
||||||
free($1);
|
free($1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user