Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make node-i2c compile with Node 4. #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/i2c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,19 @@ void ReadBlock(const FunctionCallbackInfo<Value>& args) {
int32_t len = args[1]->Int32Value();
uint8_t data[len];
Local<Value> err = Local<Value>::New(isolate, Null(isolate));
Local<Object> buffer = node::Buffer::New(len);
MaybeLocal<Object> buffer = node::Buffer::New(isolate, len);

while (fd > 0) {
if (i2c_smbus_read_i2c_block_data(fd, cmd, len, data) != len) {
err = Exception::Error(String::NewFromUtf8(isolate, "Error reading length of bytes"));
}

memcpy(node::Buffer::Data(buffer), data, len);
memcpy(node::Buffer::Data(buffer.ToLocalChecked()), data, len);

if (args[3]->IsFunction()) {
const unsigned argc = 2;
Local<Function> callback = Local<Function>::Cast(args[3]);
Local<Value> argv[argc] = { err, buffer };
Local<Value> argv[argc] = { err, buffer.ToLocalChecked() };
callback->Call(isolate->GetCurrentContext()->Global(), argc, argv);
}

Expand All @@ -183,7 +183,7 @@ void ReadBlock(const FunctionCallbackInfo<Value>& args) {
}
}

args.GetReturnValue().Set(buffer);
args.GetReturnValue().Set(buffer.ToLocalChecked());
}

void Write(const FunctionCallbackInfo<Value>& args) {
Expand Down Expand Up @@ -290,4 +290,4 @@ void Init(Handle<Object> exports) {
NODE_SET_METHOD(exports, "readBlock", ReadBlock);
}

NODE_MODULE(i2c, Init)
NODE_MODULE(i2c, Init)